Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //========= Copyright Valve Corporation, All rights reserved. ============//
- //
- // Purpose:
- //
- //=============================================================================//
- #include "cbase.h"
- #include "basehlcombatweapon.h"
- #include "npcevent.h"
- #include "basecombatcharacter.h"
- #include "ai_basenpc.h"
- #include "player.h"
- #include "game.h"
- #include "in_buttons.h"
- #include "grenade_ar2.h"
- #include "ai_memory.h"
- #include "soundent.h"
- #include "rumble_shared.h"
- #include "gamestats.h"
- // memdbgon must be the last include file in a .cpp file!!!
- #include "tier0/memdbgon.h"
- class CWeaponAR2 : public CHLMachineGun
- {
- DECLARE_DATADESC();
- public:
- DECLARE_CLASS(CWeaponAR2, CHLMachineGun);
- CWeaponAR2();
- DECLARE_SERVERCLASS();
- void Precache(void);
- void AddViewKick(void);
- int GetMinBurst() { return 2; }
- int GetMaxBurst() { return 5; }
- virtual void Equip(CBaseCombatCharacter* pOwner);
- bool Reload(void);
- float GetFireRate(void) { return 0.1f; } // 13.3hz
- int CapabilitiesGet(void) { return bits_CAP_WEAPON_RANGE_ATTACK1; }
- Activity GetPrimaryAttackActivity(void);
- virtual const Vector& GetBulletSpread(void)
- {
- static const Vector cone = VECTOR_CONE_5DEGREES;
- return cone;
- }
- const WeaponProficiencyInfo_t* GetProficiencyValues();
- void FireNPCPrimaryAttack(CBaseCombatCharacter* pOperator, Vector& vecShootOrigin, Vector& vecShootDir);
- void Operator_ForceNPCFire(CBaseCombatCharacter* pOperator, bool bSecondary);
- void Operator_HandleAnimEvent(animevent_t* pEvent, CBaseCombatCharacter* pOperator);
- DECLARE_ACTTABLE();
- protected:
- bool m_bInZoom;
- /**
- * Check for weapon being holstered so we can disable scope zoom
- */
- bool CWeaponAR2::Holster(CBaseCombatWeapon* pSwitchingTo /* = NULL */)
- {
- if (m_bInZoom)
- {
- ToggleZoom();
- }
- return BaseClass::Holster(pSwitchingTo);
- }
- /**
- * Check the status of the zoom key every frame to see if player is still zoomed in
- */
- void CWeaponAR2::ItemPostFrame()
- {
- // Allow zoom toggling
- CheckZoomToggle();
- BaseClass::ItemPostFrame();
- }
- /**
- * Check the status of the zoom key every frame to see if player is still zoomed in
- */
- void CWeaponAR2::ItemBusyFrame(void)
- {
- // Allow zoom toggling even when we're reloading
- CheckZoomToggle();
- BaseClass::ItemBusyFrame();
- }
- /**
- * Check if the zoom key was pressed in the last input tick
- */
- void CWeaponAR2::CheckZoomToggle(void)
- {
- CBasePlayer* pPlayer = ToBasePlayer(GetOwner());
- if (pPlayer && (pPlayer->m_afButtonPressed & IN_ATTACK2)) //We need to include "in_buttons.h" for IN_ATTACK2
- {
- ToggleZoom();
- }
- }
- /**
- * If we're zooming, stop. If we're not, start.
- */
- void CWeaponAR2::ToggleZoom(void)
- {
- CBasePlayer* pPlayer = ToBasePlayer(GetOwner());
- if (pPlayer == NULL)
- return;
- #ifndef CLIENT_DLL
- if (m_bInZoom)
- {
- // Narrowing the Field Of View here is what gives us the zoomed effect
- if (pPlayer->SetFOV(this, 0, 0.2f))
- {
- m_bInZoom = false;
- // Send a message to hide the scope
- CSingleUserRecipientFilter filter(pPlayer);
- UserMessageBegin(filter, "ShowScope");
- WRITE_BYTE(0);
- MessageEnd();
- }
- }
- else
- {
- if (pPlayer->SetFOV(this, 20, 0.1f))
- {
- m_bInZoom = true;
- // Send a message to Show the scope
- CSingleUserRecipientFilter filter(pPlayer);
- UserMessageBegin(filter, "ShowScope");
- WRITE_BYTE(1);
- MessageEnd();
- }
- }
- #endif
- }
- protected:
- Vector m_vecTossVelocity;
- float m_flNextGrenadeCheck;
- };
- IMPLEMENT_SERVERCLASS_ST(CWeaponAR2, DT_WeaponAR2)
- END_SEND_TABLE()
- LINK_ENTITY_TO_CLASS(weapon_ar2, CWeaponAR2);
- PRECACHE_WEAPON_REGISTER(weapon_ar2);
- BEGIN_DATADESC(CWeaponAR2)
- DEFINE_FIELD(m_vecTossVelocity, FIELD_VECTOR),
- DEFINE_FIELD(m_flNextGrenadeCheck, FIELD_TIME),
- END_DATADESC()
- acttable_t CWeaponAR2::m_acttable[] =
- {
- { ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_SMG1, true },
- { ACT_RELOAD, ACT_RELOAD_SMG1, true },
- { ACT_IDLE, ACT_IDLE_SMG1, true },
- { ACT_IDLE_ANGRY, ACT_IDLE_ANGRY_SMG1, true },
- { ACT_WALK, ACT_WALK_RIFLE, true },
- { ACT_WALK_AIM, ACT_WALK_AIM_RIFLE, true },
- // Readiness activities (not aiming)
- { ACT_IDLE_RELAXED, ACT_IDLE_SMG1_RELAXED, false },//never aims
- { ACT_IDLE_STIMULATED, ACT_IDLE_SMG1_STIMULATED, false },
- { ACT_IDLE_AGITATED, ACT_IDLE_ANGRY_SMG1, false },//always aims
- { ACT_WALK_RELAXED, ACT_WALK_RIFLE_RELAXED, false },//never aims
- { ACT_WALK_STIMULATED, ACT_WALK_RIFLE_STIMULATED, false },
- { ACT_WALK_AGITATED, ACT_WALK_AIM_RIFLE, false },//always aims
- { ACT_RUN_RELAXED, ACT_RUN_RIFLE_RELAXED, false },//never aims
- { ACT_RUN_STIMULATED, ACT_RUN_RIFLE_STIMULATED, false },
- { ACT_RUN_AGITATED, ACT_RUN_AIM_RIFLE, false },//always aims
- // Readiness activities (aiming)
- { ACT_IDLE_AIM_RELAXED, ACT_IDLE_SMG1_RELAXED, false },//never aims
- { ACT_IDLE_AIM_STIMULATED, ACT_IDLE_AIM_RIFLE_STIMULATED, false },
- { ACT_IDLE_AIM_AGITATED, ACT_IDLE_ANGRY_SMG1, false },//always aims
- { ACT_WALK_AIM_RELAXED, ACT_WALK_RIFLE_RELAXED, false },//never aims
- { ACT_WALK_AIM_STIMULATED, ACT_WALK_AIM_RIFLE_STIMULATED, false },
- { ACT_WALK_AIM_AGITATED, ACT_WALK_AIM_RIFLE, false },//always aims
- { ACT_RUN_AIM_RELAXED, ACT_RUN_RIFLE_RELAXED, false },//never aims
- { ACT_RUN_AIM_STIMULATED, ACT_RUN_AIM_RIFLE_STIMULATED, false },
- { ACT_RUN_AIM_AGITATED, ACT_RUN_AIM_RIFLE, false },//always aims
- //End readiness activities
- { ACT_WALK_AIM, ACT_WALK_AIM_RIFLE, true },
- { ACT_WALK_CROUCH, ACT_WALK_CROUCH_RIFLE, true },
- { ACT_WALK_CROUCH_AIM, ACT_WALK_CROUCH_AIM_RIFLE, true },
- { ACT_RUN, ACT_RUN_RIFLE, true },
- { ACT_RUN_AIM, ACT_RUN_AIM_RIFLE, true },
- { ACT_RUN_CROUCH, ACT_RUN_CROUCH_RIFLE, true },
- { ACT_RUN_CROUCH_AIM, ACT_RUN_CROUCH_AIM_RIFLE, true },
- { ACT_GESTURE_RANGE_ATTACK1, ACT_GESTURE_RANGE_ATTACK_SMG1, true },
- { ACT_RANGE_ATTACK1_LOW, ACT_RANGE_ATTACK_SMG1_LOW, true },
- { ACT_COVER_LOW, ACT_COVER_SMG1_LOW, false },
- { ACT_RANGE_AIM_LOW, ACT_RANGE_AIM_SMG1_LOW, false },
- { ACT_RELOAD_LOW, ACT_RELOAD_SMG1_LOW, false },
- { ACT_GESTURE_RELOAD, ACT_GESTURE_RELOAD_SMG1, true },
- };
- IMPLEMENT_ACTTABLE(CWeaponAR2);
- //=========================================================
- CWeaponAR2::CWeaponAR2()
- {
- m_fMinRange1 = 0;// No minimum range.
- m_fMaxRange1 = 1400;
- m_bAltFiresUnderwater = false;
- }
- //-----------------------------------------------------------------------------
- // Purpose:
- //-----------------------------------------------------------------------------
- void CWeaponAR2::Precache(void)
- {
- UTIL_PrecacheOther("grenade_ar2");
- BaseClass::Precache();
- }
- //-----------------------------------------------------------------------------
- // Purpose: Give this weapon longer range when wielded by an ally NPC.
- //-----------------------------------------------------------------------------
- void CWeaponAR2::Equip(CBaseCombatCharacter* pOwner)
- {
- if (pOwner->Classify() == CLASS_PLAYER_ALLY)
- {
- m_fMaxRange1 = 3000;
- }
- else
- {
- m_fMaxRange1 = 1400;
- }
- BaseClass::Equip(pOwner);
- }
- //-----------------------------------------------------------------------------
- // Purpose:
- //-----------------------------------------------------------------------------
- void CWeaponAR2::FireNPCPrimaryAttack(CBaseCombatCharacter* pOperator, Vector& vecShootOrigin, Vector& vecShootDir)
- {
- // FIXME: use the returned number of bullets to account for >10hz firerate
- WeaponSoundRealtime(SINGLE_NPC);
- CSoundEnt::InsertSound(SOUND_COMBAT | SOUND_CONTEXT_GUNFIRE, pOperator->GetAbsOrigin(), SOUNDENT_VOLUME_MACHINEGUN, 0.2, pOperator, SOUNDENT_CHANNEL_WEAPON, pOperator->GetEnemy());
- pOperator->FireBullets(1, vecShootOrigin, vecShootDir, VECTOR_CONE_PRECALCULATED,
- MAX_TRACE_LENGTH, m_iPrimaryAmmoType, 2, entindex(), 0);
- pOperator->DoMuzzleFlash();
- m_iClip1 = m_iClip1 - 1;
- }
- //-----------------------------------------------------------------------------
- // Purpose:
- //-----------------------------------------------------------------------------
- void CWeaponAR2::Operator_ForceNPCFire(CBaseCombatCharacter* pOperator, bool bSecondary)
- {
- // Ensure we have enough rounds in the clip
- m_iClip1++;
- Vector vecShootOrigin, vecShootDir;
- QAngle angShootDir;
- GetAttachment(LookupAttachment("muzzle"), vecShootOrigin, angShootDir);
- AngleVectors(angShootDir, &vecShootDir);
- FireNPCPrimaryAttack(pOperator, vecShootOrigin, vecShootDir);
- }
- //-----------------------------------------------------------------------------
- // Purpose:
- //-----------------------------------------------------------------------------
- void CWeaponAR2::Operator_HandleAnimEvent(animevent_t* pEvent, CBaseCombatCharacter* pOperator)
- {
- switch (pEvent->event)
- {
- case EVENT_WEAPON_SMG1:
- {
- Vector vecShootOrigin, vecShootDir;
- QAngle angDiscard;
- // Support old style attachment point firing
- if ((pEvent->options == NULL) || (pEvent->options[0] == '\0') || (!pOperator->GetAttachment(pEvent->options, vecShootOrigin, angDiscard)))
- {
- vecShootOrigin = pOperator->Weapon_ShootPosition();
- }
- CAI_BaseNPC* npc = pOperator->MyNPCPointer();
- ASSERT(npc != NULL);
- vecShootDir = npc->GetActualShootTrajectory(vecShootOrigin);
- FireNPCPrimaryAttack(pOperator, vecShootOrigin, vecShootDir);
- }
- break;
- /*//FIXME: Re-enable
- case EVENT_WEAPON_AR2_GRENADE:
- {
- CAI_BaseNPC *npc = pOperator->MyNPCPointer();
- Vector vecShootOrigin, vecShootDir;
- vecShootOrigin = pOperator->Weapon_ShootPosition();
- vecShootDir = npc->GetShootEnemyDir( vecShootOrigin );
- Vector vecThrow = m_vecTossVelocity;
- CGrenadeAR2 *pGrenade = (CGrenadeAR2*)Create( "grenade_ar2", vecShootOrigin, vec3_angle, npc );
- pGrenade->SetAbsVelocity( vecThrow );
- pGrenade->SetLocalAngularVelocity( QAngle( 0, 400, 0 ) );
- pGrenade->SetMoveType( MOVETYPE_FLYGRAVITY );
- pGrenade->m_hOwner = npc;
- pGrenade->m_pMyWeaponAR2 = this;
- pGrenade->SetDamage(sk_npc_dmg_ar2_grenade.GetFloat());
- // FIXME: arrgg ,this is hard coded into the weapon???
- m_flNextGrenadeCheck = gpGlobals->curtime + 6;// wait six seconds before even looking again to see if a grenade can be thrown.
- m_iClip2--;
- }
- break;
- */
- default:
- BaseClass::Operator_HandleAnimEvent(pEvent, pOperator);
- break;
- }
- }
- //-----------------------------------------------------------------------------
- // Purpose:
- // Output : Activity
- //-----------------------------------------------------------------------------
- Activity CWeaponAR2::GetPrimaryAttackActivity(void)
- {
- if (m_nShotsFired < 2)
- return ACT_VM_PRIMARYATTACK;
- return ACT_VM_PRIMARYATTACK;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- bool CWeaponAR2::Reload(void)
- {
- bool fRet;
- float fCacheTime = m_flNextSecondaryAttack;
- fRet = DefaultReload(GetMaxClip1(), GetMaxClip2(), ACT_VM_RELOAD);
- if (fRet)
- {
- // Undo whatever the reload process has done to our secondary
- // attack timer. We allow you to interrupt reloading to fire
- // a grenade.
- m_flNextSecondaryAttack = GetOwner()->m_flNextAttack = fCacheTime;
- WeaponSound(RELOAD);
- }
- return fRet;
- }
- //-----------------------------------------------------------------------------
- // Purpose:
- //-----------------------------------------------------------------------------
- void CWeaponAR2::AddViewKick(void)
- {
- #define EASY_DAMPEN 0.5f
- #define MAX_VERTICAL_KICK 1.0f //Degrees
- #define SLIDE_LIMIT 2.0f //Seconds
- //Get the view kick
- CBasePlayer* pPlayer = ToBasePlayer(GetOwner());
- if (pPlayer == NULL)
- return;
- DoMachineGunKick(pPlayer, EASY_DAMPEN, MAX_VERTICAL_KICK, m_fFireDuration, SLIDE_LIMIT);
- }
- //-----------------------------------------------------------------------------
- const WeaponProficiencyInfo_t* CWeaponAR2::GetProficiencyValues()
- {
- static WeaponProficiencyInfo_t proficiencyTable[] =
- {
- { 7.0, 0.75 },
- { 5.00, 0.75 },
- { 10.0 / 3.0, 0.75 },
- { 5.0 / 3.0, 0.75 },
- { 1.00, 1.0 },
- };
- COMPILE_TIME_ASSERT(ARRAYSIZE(proficiencyTable) == WEAPON_PROFICIENCY_PERFECT + 1);
- return proficiencyTable;
- }
Advertisement
Add Comment
Please, Sign In to add comment