void CSDKPlayer::MakeTracer( const Vector &vecTracerSrc, const trace_t &tr, int iTracerType ) { #ifdef CLIENT_DLL CWeaponSDKBase *pWeapon = GetActiveSDKWeapon(); if (pWeapon) pWeapon->MakeTracer( vecTracerSrc, tr, iTracerType ); #endif }
const char* CSDKPlayerAnimState::GetWeaponSuffix() { // Figure out the weapon suffix. CWeaponSDKBase *pWeapon = m_pHelpers->SDKAnim_GetActiveWeapon(); if ( !pWeapon ) return "Pistol"; const char *pSuffix = pWeapon->GetSDKWpnData().m_szAnimExtension; return pSuffix; }
void C_SDKPlayer::PlayReloadEffect() { // Only play the effect for other players. if ( this == C_SDKPlayer::GetLocalSDKPlayer() ) { Assert( false ); // We shouldn't have been sent this message. return; } // Get the view model for our current gun. CWeaponSDKBase *pWeapon = GetActiveSDKWeapon(); if ( !pWeapon ) return; // The weapon needs two models, world and view, but can only cache one. Synthesize the other. const CSDKWeaponInfo &info = pWeapon->GetSDKWpnData(); const model_t *pModel = modelinfo->GetModel( modelinfo->GetModelIndex( info.szViewModel ) ); if ( !pModel ) return; CStudioHdr studioHdr( modelinfo->GetStudiomodel( pModel ), mdlcache ); if ( !studioHdr.IsValid() ) return; // Find the reload animation. for ( int iSeq=0; iSeq < studioHdr.GetNumSeq(); iSeq++ ) { mstudioseqdesc_t *pSeq = &studioHdr.pSeqdesc( iSeq ); if ( pSeq->activity == ACT_VM_RELOAD ) { float poseParameters[MAXSTUDIOPOSEPARAM]; memset( poseParameters, 0, sizeof( poseParameters ) ); float cyclesPerSecond = Studio_CPS( &studioHdr, *pSeq, iSeq, poseParameters ); // Now read out all the sound events with their timing for ( int iEvent=0; iEvent < pSeq->numevents; iEvent++ ) { //mstudioevent_t *pevent = (mstudioevent_for_client_server_t*)pSeq.pEvent(iEvent ); mstudioevent_t *pEvent = (mstudioevent_for_client_server_t*)pSeq->pEvent( iEvent ); if ( pEvent->Event() == CL_EVENT_SOUND ) { CSDKSoundEvent event; event.m_SoundName = pEvent->options; event.m_flEventTime = gpGlobals->curtime + pEvent->cycle / cyclesPerSecond; m_SoundEvents.AddToTail( event ); } } break; } } }
CWeaponSDKBase* CSDKPlayer::FindWeapon (SDKWeaponID id) { int i; for (i = 0; i < WeaponCount(); i++) { CWeaponSDKBase *wpn = (CWeaponSDKBase *)GetWeapon (i); if (wpn) { if (wpn->GetWeaponID () == id) return wpn; } } return NULL; }
void CSDKPlayerShared::SetAimIn(bool bAimIn) { // If we're aimed in and aimin is being turned off and we're aimed in enough to have noticed a change, train the aimin lesson. if (m_bAimedIn && !bAimIn && m_flAimIn > 0.5f) { CWeaponSDKBase* pWeapon = m_pOuter->GetActiveSDKWeapon(); // Also must be holding an aimin weapon. if (pWeapon && (pWeapon->HasAimInFireRateBonus() || pWeapon->HasAimInRecoilBonus() || pWeapon->HasAimInSpeedPenalty())) m_pOuter->Instructor_LessonLearned("aimin"); } m_bAimedIn = bAimIn; }
bool PlayerOutOfAmmoAndMultipleWeaponsConditions( C_SDKPlayer *pPlayer, class CLesson *pLesson ) { if (!PlayerHasMultipleWeaponsConditions(pPlayer, pLesson)) return false; CWeaponSDKBase* pWeapon = pPlayer->GetActiveSDKWeapon(); if (!pWeapon) return false; if (pWeapon->GetWeaponID() == SDK_WEAPON_BRAWL) return false; return !pWeapon->HasPrimaryAmmo(); }
bool PlayerActiveWeaponHasAimInConditions( C_SDKPlayer *pPlayer, class CLesson *pLesson ) { if (!PlayerAliveConditions(pPlayer, pLesson)) return false; CWeaponSDKBase* pWeapon = pPlayer->GetActiveSDKWeapon(); if (!pWeapon) return false; if (pWeapon->HasAimInSpeedPenalty() || pWeapon->HasAimInFireRateBonus() || pWeapon->HasAimInRecoilBonus()) return true; return false; }
CBaseCombatWeapon* CSDKPlayer::GetLastWeapon() { // This is pretty silly, but I'd rather mess around with stock Valve code as little as possible. #ifdef CLIENT_DLL CBaseCombatWeapon* pLastWeapon = BaseClass::GetLastWeapon(); #else CBaseCombatWeapon* pLastWeapon = BaseClass::Weapon_GetLast(); #endif if (pLastWeapon && pLastWeapon != GetActiveWeapon()) return pLastWeapon; CWeaponSDKBase* pHeaviest = NULL; CWeaponSDKBase* pBrawl = NULL; for (int i = 0; i < WeaponCount(); i++) { if (!GetWeapon(i)) continue; if (GetWeapon(i) == GetActiveWeapon()) continue; CWeaponSDKBase* pSDKWeapon = dynamic_cast<CWeaponSDKBase*>(GetWeapon(i)); if (!pSDKWeapon) continue; if (pSDKWeapon->GetWeaponID() == SDK_WEAPON_BRAWL) { pBrawl = pSDKWeapon; continue; } if (!pHeaviest) { pHeaviest = pSDKWeapon; continue; } if (pHeaviest->GetWeight() < pSDKWeapon->GetWeight()) pHeaviest = pSDKWeapon; } if (!pHeaviest) pHeaviest = pBrawl; return pHeaviest; }
bool PlayerCanReloadConditions( C_SDKPlayer *pPlayer, class CLesson *pLesson ) { if (!PlayerAliveConditions(pPlayer, pLesson)) return false; CWeaponSDKBase* pWeapon = pPlayer->GetActiveSDKWeapon(); if (!pWeapon) return false; if (!pWeapon->UsesClipsForAmmo1()) return false; if (pWeapon->Clip1() == pWeapon->GetMaxClip1()) return false; return pWeapon->HasPrimaryAmmo(); }
void CSDKPlayer::ThrowActiveWeapon( void ) { CWeaponSDKBase *pWeapon = (CWeaponSDKBase *)GetActiveWeapon(); if( pWeapon && pWeapon->CanWeaponBeDropped() ) { QAngle gunAngles; VectorAngles( BodyDirection2D(), gunAngles ); Vector vecForward; AngleVectors( gunAngles, &vecForward, NULL, NULL ); float flDiameter = sqrt( CollisionProp()->OBBSize().x * CollisionProp()->OBBSize().x + CollisionProp()->OBBSize().y * CollisionProp()->OBBSize().y ); pWeapon->Holster(NULL); SwitchToNextBestWeapon( pWeapon ); SDKThrowWeapon( pWeapon, vecForward, gunAngles, flDiameter ); } }
bool PlayerHasMultipleWeaponsConditions( C_SDKPlayer *pPlayer, class CLesson *pLesson ) { if (!PlayerAliveConditions(pPlayer, pLesson)) return false; int iWeapons = 0; for (int i = 0; i < pPlayer->WeaponCount(); i++) { if (!pPlayer->GetWeapon(i)) continue; CWeaponSDKBase* pWeapon = dynamic_cast<CWeaponSDKBase*>(pPlayer->GetWeapon(i)); if (!pWeapon) continue; if (pWeapon->GetWeaponID() == SDK_WEAPON_BRAWL) continue; iWeapons++; } return iWeapons > 1; }
void CDAHudCrosshair::CalculateCrosshair( void ) { C_SDKPlayer *pPlayer = C_SDKPlayer::GetLocalSDKPlayer(); if ( !pPlayer ) return; CWeaponSDKBase *pWeapon = pPlayer->GetActiveSDKWeapon(); if (!pWeapon) { ResetCrosshair(); return; } if ( !pWeapon->ShouldDrawCrosshair() ) { ResetCrosshair(); return; } Color clrHUD = Color( 200, 200, 200, 255 ); clrHUD[3] = 255; Color white( 255, 255, 255, 255 ); if ( pPlayer->m_Shared.GetAimIn() <= 0.5f || !pWeapon->HasAimInRecoilBonus() ) { if ( pWeapon->GetWpnData().iconCrosshair ) SetCrosshair( pWeapon->GetWpnData().iconCrosshair, clrHUD ); else ResetCrosshair(); } else { // zoomed crosshairs if ( pWeapon->GetWpnData().iconZoomedCrosshair ) SetCrosshair( pWeapon->GetWpnData().iconZoomedCrosshair, white ); else if ( pWeapon->GetWpnData().iconCrosshair ) SetCrosshair( pWeapon->GetWpnData().iconCrosshair, clrHUD ); else ResetCrosshair(); } }
int CDAViewModel::DrawModel(int flags) { int iReturn = BaseClass::DrawModel(flags); C_SDKPlayer* pLocalPlayer = C_SDKPlayer::GetLocalOrSpectatedPlayer(); if (pLocalPlayer && pLocalPlayer->UseVRHUD()) { Vector vecAmmo1, vecAmmo2; int iAmmo1 = LookupAttachment("ammo_1"); int iAmmo2 = LookupAttachment("ammo_2"); int iAmmoL1 = LookupAttachment("ammo_1_l"); int iAmmoL2 = LookupAttachment("ammo_2_l"); int iAmmoR1 = LookupAttachment("ammo_1_r"); int iAmmoR2 = LookupAttachment("ammo_2_r"); if (GetAttachment(iAmmo1, vecAmmo1) && GetAttachment(iAmmo2, vecAmmo2)) CWeaponSDKBase::DrawVRBullets(vecAmmo1, vecAmmo2, GetActiveWeapon()->Clip1(), GetActiveWeapon()->GetMaxClip1(), true); if (GetAttachment(iAmmoR1, vecAmmo1) && GetAttachment(iAmmoR2, vecAmmo2)) { CWeaponSDKBase* pWeapon = dynamic_cast<CWeaponSDKBase*>(GetActiveWeapon()); if (pWeapon) CWeaponSDKBase::DrawVRBullets(vecAmmo1, vecAmmo2, pWeapon->m_iRightClip, pWeapon->GetMaxClip1()/2, true); } if (GetAttachment(iAmmoL1, vecAmmo1) && GetAttachment(iAmmoL2, vecAmmo2)) { CWeaponSDKBase* pWeapon = dynamic_cast<CWeaponSDKBase*>(GetActiveWeapon()); if (pWeapon) CWeaponSDKBase::DrawVRBullets(vecAmmo1, vecAmmo2, pWeapon->m_iLeftClip, pWeapon->GetMaxClip1()/2, false); } } return iReturn; }
void CSDKGameRules::PlayerSpawn( CBasePlayer *p ) { CSDKPlayer *pPlayer = ToSDKPlayer( p ); int team = pPlayer->GetTeamNumber(); if( team != TEAM_SPECTATOR ) { #if defined ( SDK_USE_PLAYERCLASSES ) if( pPlayer->m_Shared.DesiredPlayerClass() == PLAYERCLASS_RANDOM ) { ChooseRandomClass( pPlayer ); ClientPrint( pPlayer, HUD_PRINTTALK, "#game_now_as", GetPlayerClassName( pPlayer->m_Shared.PlayerClass(), team ) ); } else { pPlayer->m_Shared.SetPlayerClass( pPlayer->m_Shared.DesiredPlayerClass() ); } int playerclass = pPlayer->m_Shared.PlayerClass(); if( playerclass != PLAYERCLASS_UNDEFINED ) { //Assert( PLAYERCLASS_UNDEFINED < playerclass && playerclass < NUM_PLAYERCLASSES ); CSDKTeam *pTeam = GetGlobalSDKTeam( team ); const CSDKPlayerClassInfo &pClassInfo = pTeam->GetPlayerClassInfo( playerclass ); Assert( pClassInfo.m_iTeam == team ); pPlayer->SetModel( pClassInfo.m_szPlayerModel ); pPlayer->SetHitboxSet( 0 ); char buf[64]; int bufsize = sizeof(buf); //Give weapons // Primary weapon Q_snprintf( buf, bufsize, "weapon_%s", WeaponIDToAlias(pClassInfo.m_iPrimaryWeapon) ); CBaseEntity *pPrimaryWpn = pPlayer->GiveNamedItem( buf ); Assert( pPrimaryWpn ); // Secondary weapon CBaseEntity *pSecondaryWpn = NULL; if ( pClassInfo.m_iSecondaryWeapon != WEAPON_NONE ) { Q_snprintf( buf, bufsize, "weapon_%s", WeaponIDToAlias(pClassInfo.m_iSecondaryWeapon) ); pSecondaryWpn = pPlayer->GiveNamedItem( buf ); } // Melee weapon if ( pClassInfo.m_iMeleeWeapon ) { Q_snprintf( buf, bufsize, "weapon_%s", WeaponIDToAlias(pClassInfo.m_iMeleeWeapon) ); pPlayer->GiveNamedItem( buf ); } CWeaponSDKBase *pWpn = NULL; // Primary Ammo pWpn = dynamic_cast<CWeaponSDKBase *>(pPrimaryWpn); if( pWpn ) { int iNumClip = pWpn->GetSDKWpnData().m_iDefaultAmmoClips - 1; //account for one clip in the gun int iClipSize = pWpn->GetSDKWpnData().iMaxClip1; pPlayer->GiveAmmo( iNumClip * iClipSize, pWpn->GetSDKWpnData().szAmmo1 ); } // Secondary Ammo if ( pSecondaryWpn ) { pWpn = dynamic_cast<CWeaponSDKBase *>(pSecondaryWpn); if( pWpn ) { int iNumClip = pWpn->GetSDKWpnData().m_iDefaultAmmoClips - 1; //account for one clip in the gun int iClipSize = pWpn->GetSDKWpnData().iMaxClip1; pPlayer->GiveAmmo( iNumClip * iClipSize, pWpn->GetSDKWpnData().szAmmo1 ); } } // Grenade Type 1 if ( pClassInfo.m_iGrenType1 != WEAPON_NONE ) { Q_snprintf( buf, bufsize, "weapon_%s", WeaponIDToAlias(pClassInfo.m_iGrenType1) ); CBaseEntity *pGrenade = pPlayer->GiveNamedItem( buf ); Assert( pGrenade ); pWpn = dynamic_cast<CWeaponSDKBase *>(pGrenade); if( pWpn ) { pPlayer->GiveAmmo( pClassInfo.m_iNumGrensType1 - 1, pWpn->GetSDKWpnData().szAmmo1 ); } } // Grenade Type 2 if ( pClassInfo.m_iGrenType2 != WEAPON_NONE ) { Q_snprintf( buf, bufsize, "weapon_%s", WeaponIDToAlias(pClassInfo.m_iGrenType2) ); CBaseEntity *pGrenade2 = pPlayer->GiveNamedItem( buf ); Assert( pGrenade2 ); pWpn = dynamic_cast<CWeaponSDKBase *>(pGrenade2); if( pWpn ) { pPlayer->GiveAmmo( pClassInfo.m_iNumGrensType2 - 1, pWpn->GetSDKWpnData().szAmmo1 ); } } pPlayer->Weapon_Switch( (CBaseCombatWeapon *)pPrimaryWpn ); // DevMsg("setting spawn armor to: %d\n", pClassInfo.m_iArmor ); pPlayer->SetSpawnArmorValue( pClassInfo.m_iArmor ); } else { // Assert( !"Player spawning with PLAYERCLASS_UNDEFINED" ); pPlayer->SetModel( SDK_PLAYER_MODEL ); } #else pPlayer->GiveDefaultItems(); #endif // SDK_USE_PLAYERCLASSES pPlayer->SetMaxSpeed( 600 ); } }
//----------------------------------------------------------------------------- // Purpose: determine the class name of the weapon that got a kill //----------------------------------------------------------------------------- const char *CSDKGameRules::GetKillingWeaponName( const CTakeDamageInfo &info, CSDKPlayer *pVictim, int *iWeaponID ) { CBaseEntity *pInflictor = info.GetInflictor(); CBaseEntity *pKiller = info.GetAttacker(); CBasePlayer *pScorer = SDKGameRules()->GetDeathScorer( pKiller, pInflictor, pVictim ); const char *killer_weapon_name = "world"; *iWeaponID = SDK_WEAPON_NONE; if ( pScorer && pInflictor && ( pInflictor == pScorer ) ) { // If the inflictor is the killer, then it must be their current weapon doing the damage if ( pScorer->GetActiveWeapon() ) { killer_weapon_name = pScorer->GetActiveWeapon()->GetClassname(); if ( pScorer->IsPlayer() ) { *iWeaponID = ToSDKPlayer(pScorer)->GetActiveSDKWeapon()->GetWeaponID(); } } } else if ( pInflictor ) { killer_weapon_name = STRING( pInflictor->m_iClassname ); CWeaponSDKBase *pWeapon = dynamic_cast< CWeaponSDKBase * >( pInflictor ); if ( pWeapon ) { *iWeaponID = pWeapon->GetWeaponID(); } else { CBaseGrenadeProjectile *pBaseGrenade = dynamic_cast<CBaseGrenadeProjectile*>( pInflictor ); if ( pBaseGrenade ) { *iWeaponID = pBaseGrenade->GetWeaponID(); } } } // strip certain prefixes from inflictor's classname const char *prefix[] = { "weapon_", "NPC_", "func_" }; for ( int i = 0; i< ARRAYSIZE( prefix ); i++ ) { // if prefix matches, advance the string pointer past the prefix int len = Q_strlen( prefix[i] ); if ( strncmp( killer_weapon_name, prefix[i], len ) == 0 ) { killer_weapon_name += len; break; } } // grenade projectiles need to be translated to 'grenade' if ( 0 == Q_strcmp( killer_weapon_name, "grenade_projectile" ) ) { killer_weapon_name = "grenade"; } return killer_weapon_name; }
void CHudAmmo::Paint() { C_SDKPlayer *pPlayer = C_SDKPlayer::GetLocalSDKPlayer(); if ( !pPlayer ) return; if (!pPlayer->IsAlive()) return; if (!pPlayer->GetActiveSDKWeapon()) return; int iWidth, iHeight; GetSize(iWidth, iHeight); float flScale = 480.0f/(float)iHeight * hud_ammoscale.GetFloat(); int iGrenades = 0; int iTotalGrenades = GetAmmoDef()->MaxCarry(GetAmmoDef()->Index("grenades")); if (pPlayer->m_Shared.m_iStyleSkill != SKILL_TROLL) iTotalGrenades = ConVarRef("da_max_grenades").GetInt(); CWeaponSDKBase* pGrenade = pPlayer->FindWeapon(SDK_WEAPON_GRENADE); if (pGrenade) iGrenades = pPlayer->GetAmmoCount(pGrenade->GetPrimaryAmmoType()); if (m_pGrenadeIcon) { for (int i = 0; i < iGrenades; i++) { Vector4D vecGrenade = GetGrenadePosition(i); m_pGrenadeIcon->DrawSelf(vecGrenade.x, vecGrenade.y, vecGrenade.z, vecGrenade.w, Color(255, 255, 255, 255)); } } if (m_pGrenadeEmptyIcon) { for (int i = iGrenades; i < iTotalGrenades; i++) { Vector4D vecGrenade = GetGrenadePosition(i); m_pGrenadeEmptyIcon->DrawSelf(vecGrenade.x, vecGrenade.y, vecGrenade.z, vecGrenade.w, Color(255, 255, 255, 255)); } } if (pPlayer->UseVRHUD()) return; CHudTexture* pTexture = GetTexture(); if (!pTexture) return; for (int i = 0; i < m_iAmmo; i++) { Vector2D vecRound = GetRoundPosition(i); pTexture->DrawSelf( vecRound.x, vecRound.y, GetTextureDrawWidth(pTexture, flScale), GetTextureDrawHeight(pTexture, flScale), Color(255, 255, 255, 255) ); } float flFrameTime = gpGlobals->frametime * pPlayer->GetSlowMoMultiplier(); for (int i = 0; i < m_aRounds.Count(); i++) { CFlyingRound& oRound = m_aRounds[i]; if (!oRound.bActive) continue; if (oRound.vecPosition.y > iHeight+1000) { oRound.bActive = false; continue; } if (!oRound.pTexture) { oRound.bActive = false; continue; } oRound.vecPosition += flFrameTime * oRound.vecVelocity; oRound.vecVelocity.y += flFrameTime * 2000; oRound.flAngle += flFrameTime * oRound.flAngularVelocity; SDKViewport::DrawPolygon(oRound.pTexture, oRound.vecPosition.x, oRound.vecPosition.y, GetTextureDrawWidth(oRound.pTexture, flScale), GetTextureDrawHeight(oRound.pTexture, flScale), oRound.flAngle); } wchar_t* pszActivate = g_pVGuiLocalize->Find("#DA_HUD_Ammo_Reload"); if (pszActivate && m_iAmmo == 0 && !pPlayer->GetActiveSDKWeapon()->m_bInReload) { #define WSTRLEN 512 // replace any key references with bound keys wchar_t wszHintLabel[WSTRLEN]; UTIL_ReplaceKeyBindings( pszActivate, 0, wszHintLabel, sizeof( wszHintLabel ) ); int iTextWide, iTextTall; surface()->GetTextSize( m_hHintFont, wszHintLabel, iTextWide, iTextTall ); int iWidth, iHeight; GetSize(iWidth, iHeight); float flRightPadding = scheme()->GetProportionalScaledValueEx(GetScheme(), 40); float flBottomPadding = scheme()->GetProportionalScaledValueEx(GetScheme(), 40); surface()->DrawSetTextPos( iWidth - iTextWide - flRightPadding, iHeight - flBottomPadding - iTextTall ); surface()->DrawSetTextColor( Color(255, 0, 0, Oscillate(gpGlobals->curtime, 1)*255) ); surface()->DrawSetTextFont( m_hHintFont ); surface()->DrawUnicodeString( wszHintLabel, vgui::FONT_DRAW_NONADDITIVE ); }}
void CSDKPlayer::UpdateThirdCamera(const Vector& vecEye, const QAngle& angEye) { if (!IsInThirdPerson()) return; CWeaponSDKBase * pWeapon = NULL; if (GetActiveWeapon() != NULL){ pWeapon = GetActiveSDKWeapon(); } Assert(pWeapon); #ifdef CLIENT_DLL if (m_vecThirdCamera.DistTo(vecEye) < da_cam_fade_distance.GetFloat()){ m_flCurrentAlphaVal = Approach(da_cam_fade_alpha_val.GetFloat(), m_flCurrentAlphaVal, 500.0f * gpGlobals->frametime); if (GetRenderMode() != kRenderTransTexture){ SetRenderMode(kRenderTransTexture); } SetRenderColorA(m_flCurrentAlphaVal); if (pWeapon){ if (pWeapon->GetRenderMode() != kRenderTransTexture){ pWeapon->SetRenderMode(kRenderTransTexture); } pWeapon->SetRenderColorA(m_flCurrentAlphaVal); } }else{ m_flCurrentAlphaVal = Approach(255.0f, m_flCurrentAlphaVal, 500.0f * gpGlobals->frametime); if (GetRenderMode() != kRenderNormal){ SetRenderMode(kRenderNormal); } SetRenderColorA(m_flCurrentAlphaVal); if (pWeapon){ if (pWeapon->GetRenderMode() != kRenderNormal){ pWeapon->SetRenderMode(kRenderNormal); } pWeapon->SetRenderColorA(m_flCurrentAlphaVal); } } #endif m_vecThirdCamera = CalculateThirdPersonCameraPosition(vecEye, angEye); Vector vecShoot; AngleVectors(angEye, &vecShoot); // Trace to see where the camera is pointing trace_t tr; UTIL_TraceLine( m_vecThirdCamera, m_vecThirdCamera + vecShoot * 99999, MASK_VISIBLE|CONTENTS_DEBRIS|CONTENTS_HITBOX, this, COLLISION_GROUP_NONE, &tr ); m_vecThirdTarget = tr.endpos; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CBaseSDKGrenade::ItemPostFrame() { CSDKPlayer *pPlayer = GetPlayerOwner(); if ( !pPlayer ) return; CBaseViewModel *vm = pPlayer->GetViewModel( m_nViewModelIndex ); if ( !vm ) return; // If they let go of the fire button, they want to throw the grenade. if ( m_bPinPulled && !(pPlayer->m_nButtons & IN_ATTACK) ) { pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY ); // if (m_bSecondary) // DropGrenade(); // else ThrowGrenade(); if (!pPlayer->IsStyleSkillActive(SKILL_TROLL)) DecrementAmmo( pPlayer ); m_bPinPulled = false; SendWeaponAnim( ACT_VM_THROW ); SetWeaponIdleTime( GetCurrentTime() + SequenceDuration() ); m_bPinPulled = false; // m_bSecondary = false; } else if( m_bRedraw ) { // Has the throw animation finished playing if( m_flTimeWeaponIdle < GetCurrentTime() ) { // if we're officially out of grenades, ditch this weapon if( pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0 ) { #ifdef GAME_DLL pPlayer->Weapon_Drop( this, NULL, NULL ); UTIL_Remove(this); #endif pPlayer->SwitchToNextBestWeapon( NULL ); //Tony; now switch! cuz we rans outs! } else if (pPlayer->IsStyleSkillActive(SKILL_TROLL)) { m_bRedraw = false; m_flNextPrimaryAttack = GetCurrentTime() + 1.2; m_flNextSecondaryAttack = GetCurrentTime() + 1.2; SendWeaponAnim( GetDeployActivity() ); } else { m_bRedraw = false; // Only switch to the next best weapon if the next best weapon is not brawl. CBaseCombatWeapon *pNewWeapon = g_pGameRules->GetNextBestWeapon(pPlayer, this); CWeaponSDKBase* pSDKNewWeapon = dynamic_cast<CWeaponSDKBase*>(pNewWeapon); bool bSwitch = true; if (!pSDKNewWeapon) bSwitch = false; // If I'm going to switch to brawl but I have more grenades, don't switch. else if (pSDKNewWeapon && pSDKNewWeapon->GetWeaponID() == SDK_WEAPON_BRAWL && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) > 0) bSwitch = false; if (bSwitch) pPlayer->SwitchToNextBestWeapon( this ); } return; //don't animate this grenade any more! } } else if( !m_bRedraw ) { BaseClass::ItemPostFrame(); } }
void CDAViewModel::AddViewModelBob( CBasePlayer *owner, Vector& eyePosition, QAngle& eyeAngles ) { CSDKPlayer* pOwner = ToSDKPlayer(owner); if (!pOwner) return; CWeaponSDKBase* pWeapon = GetDAWeapon(); if (pWeapon && pWeapon->IsThrowingGrenade()) { float flThrowStart = GetDAWeapon()->GetGrenadeThrowStart(); float flHolsterTime = GetDAWeapon()->GetGrenadeThrowWeaponHolsterTime(); float flDeployTime = GetDAWeapon()->GetGrenadeThrowWeaponDeployTime(); float flThrowEnd = GetDAWeapon()->GetGrenadeThrowEnd(); float flGain = 0.7f; if (pOwner->GetCurrentTime() < flHolsterTime) { eyePosition -= Vector(0, 0, 1) * RemapGainedValClamped( pOwner->GetCurrentTime(), flGain, flThrowStart, flHolsterTime, 0, da_weapon_grenadethrow_drop.GetFloat()); eyeAngles.x += RemapGainedValClamped( pOwner->GetCurrentTime(), flGain, flThrowStart, flHolsterTime, 0, da_weapon_grenadethrow_tilt.GetFloat()); } else if (pOwner->GetCurrentTime() > flDeployTime) { eyePosition -= Vector(0, 0, 1) * RemapGainedValClamped( pOwner->GetCurrentTime(), flGain, flDeployTime, flThrowEnd, da_weapon_grenadethrow_drop.GetFloat(), 0); eyeAngles.x += RemapGainedValClamped( pOwner->GetCurrentTime(), flGain, flDeployTime, flThrowEnd, da_weapon_grenadethrow_tilt.GetFloat(), 0); } } // Offset it a tad so that it moves while looking around. eyePosition.x += da_weaponoffset.GetFloat(); // For mysterious reasons that I don't care to investigate, the eye angles // are sometimes slammed to (0, 0, 0) for a frame or two. If this should // happen, use the previous eye angles instead. QAngle angEye = EyeAngles(); if (angEye.x == 0 && angEye.y == 0 && angEye.z == 0) angEye = m_angLastPlayerEyeAngles; else m_angLastPlayerEyeAngles = angEye; Vector vecViewForward, vecViewRight, vecViewUp; AngleVectors(angEye, &vecViewForward, &vecViewRight, &vecViewUp); Vector vecViewDirection(vecViewForward.x, vecViewForward.y, 0); vecViewDirection.NormalizeInPlace(); float flMaxVelocity = 100; Vector vecOwnerVelocity = pOwner->GetAbsVelocity(); if (vecOwnerVelocity.LengthSqr() > flMaxVelocity*flMaxVelocity) vecOwnerVelocity = (vecOwnerVelocity / vecOwnerVelocity.Length()) * flMaxVelocity; m_vecPlayerVelocityLerp.x = Approach(vecOwnerVelocity.x, m_vecPlayerVelocityLerp.x, 1000*gpGlobals->frametime); m_vecPlayerVelocityLerp.y = Approach(vecOwnerVelocity.y, m_vecPlayerVelocityLerp.y, 1000*gpGlobals->frametime); m_vecPlayerVelocityLerp.z = Approach(vecOwnerVelocity.z, m_vecPlayerVelocityLerp.z, 1000*gpGlobals->frametime); Vector vecPlayerVelocityLerp = m_vecPlayerVelocityLerp; vecPlayerVelocityLerp.NormalizeInPlace(); float flViewVelocityDot = fabs(vecPlayerVelocityLerp.Dot(vecViewRight)); eyePosition += m_vecPlayerVelocityLerp * da_weaponlag.GetFloat() * flViewVelocityDot; if (pOwner->m_Shared.GetViewBobRamp() && pOwner->m_Shared.GetRunSpeed()) { float flViewBobMagnitude = pOwner->m_Shared.GetViewBobRamp() * da_weaponbob.GetFloat(); float flRunPeriod = M_PI * 3; float flRunUpBob = sin(pOwner->GetCurrentTime() * flRunPeriod * 2) * (flViewBobMagnitude / 2); float flRunRightBob = sin(pOwner->GetCurrentTime() * flRunPeriod) * flViewBobMagnitude; float flWalkPeriod = M_PI * 1.5f; float flWalkUpBob = sin(pOwner->GetCurrentTime() * flWalkPeriod * 2) * (flViewBobMagnitude / 2); float flWalkRightBob = sin(pOwner->GetCurrentTime() * flWalkPeriod) * flViewBobMagnitude; // 0 is walk, 1 is run. float flRunRamp = RemapValClamped(pOwner->m_Shared.GetViewBobRamp(), pOwner->m_Shared.GetAimInSpeed()/pOwner->m_Shared.GetRunSpeed(), 1.0f, 0.0f, 1.0f); float flRightBob = RemapValClamped(flRunRamp, 0, 1, flWalkRightBob, flRunRightBob); float flUpBob = RemapValClamped(flRunRamp, 0, 1, flWalkUpBob, flRunUpBob); eyePosition += vecViewRight * flRightBob + vecViewUp * (flUpBob - pOwner->m_Shared.GetViewBobRamp() * da_weapondrop.GetFloat()); } if (pOwner->m_Shared.GetViewTilt()) { Vector vecDiveRight = Vector(0, 0, 1).Cross(pOwner->m_Shared.GetDiveDirection()); float flRightDot = vecViewDirection.Dot(vecDiveRight); float flUpDot = vecViewDirection.Dot(pOwner->m_Shared.GetDiveDirection()); eyeAngles.z += flRightDot * pOwner->m_Shared.GetViewTilt() * da_weapontilt.GetFloat();; eyePosition += (vecViewUp * (flUpDot * 0.5f) + vecViewDirection * (flUpDot * 0.5f)) * pOwner->m_Shared.GetViewTilt(); float flDiveBobMagnitude = 0.5f * pOwner->m_Shared.GetViewTilt(); float flDiveBobPeriod = M_PI * 0.5f; float flDiveUpBob = sin(pOwner->GetCurrentTime() * flDiveBobPeriod * 2) * (flDiveBobMagnitude / 2); float flDiveRightBob = cos(pOwner->GetCurrentTime() * flDiveBobPeriod * 2) * (flDiveBobMagnitude / 2); eyePosition += vecViewRight * flDiveRightBob + vecViewUp * flDiveUpBob; } }
bool CSDKPlayer::PlayerUse() { #ifdef GAME_DLL // Was use pressed or released? if ( ((m_nButtons | m_afButtonPressed | m_afButtonReleased) & IN_USE) && !IsObserver() ) { Vector forward, up; EyeVectors( &forward, NULL, &up ); Vector vecSearchCenter = EyePosition(); CBaseEntity *pObject = nullptr; CBaseEntity *pNearest = nullptr; float flNearest = FLT_MAX; // Look for grenades so we can prioritize picking them up first. for ( CEntitySphereQuery sphere( vecSearchCenter, PLAYER_USE_RADIUS ); ( pObject = sphere.GetCurrentEntity() ) != NULL; sphere.NextEntity() ) { if ( !pObject ) continue; if ( !IsUseableEntity( pObject, FCAP_USE_IN_RADIUS ) ) continue; CWeaponSDKBase* pWeapon = dynamic_cast<CWeaponSDKBase*>(pObject); if (!pWeapon) continue; if (pWeapon->GetWeaponID() != SDK_WEAPON_GRENADE) continue; // If we're full up on grenades, pass over to whatever other weapons are lying around. if (!g_pGameRules->CanHavePlayerItem(this, pWeapon)) continue; // see if it's more roughly in front of the player than previous guess Vector point; pObject->CollisionProp()->CalcNearestPoint( vecSearchCenter, &point ); Vector dir = point - vecSearchCenter; VectorNormalize(dir); float dot = DotProduct( dir, forward ); // Need to be looking at the object more or less if ( dot < 0.8 ) continue; float dist = CalcDistanceToLine( point, vecSearchCenter, forward ); ConVarRef sv_debug_player_use("sv_debug_player_use"); if ( sv_debug_player_use.GetBool() ) { Msg("Radius found %s, dist %.2f\n", pObject->GetClassname(), dist ); } // Not worried about shit being behind a wall at this point. // Just greedily gobble up all nearby grenades since there's // no penalty to the player for doing so. if ( dist < flNearest ) { pNearest = pObject; flNearest = dist; } } if (pNearest) { // This is a grenade. Use it to pick it up. variant_t emptyVariant; pNearest->AcceptInput( "Use", this, this, emptyVariant, USE_TOGGLE ); return true; } } #endif bool bUsed = BaseClass::PlayerUse(); if (bUsed) return bUsed; if (!(m_afButtonPressed & IN_USE)) return false; if (!IsAlive()) return false; return false; }