//----------------------------------------------------------------------------- // Purpose: TF2 Specific Client Commands // Input : // Output : //----------------------------------------------------------------------------- bool CSDKGameRules::ClientCommand( CBaseEntity *pEdict, const CCommand &args ) { CSDKPlayer *pPlayer = ToSDKPlayer( pEdict ); #if 0 const char *pcmd = args[0]; if ( FStrEq( pcmd, "somecommand" ) ) { if ( args.ArgC() < 2 ) return true; // Do something here! return true; } else #endif // Handle some player commands here as they relate more directly to gamerules state if ( pPlayer->ClientCommand( args ) ) { return true; } else if ( BaseClass::ClientCommand( pEdict, args ) ) { return true; } return false; }
//----------------------------------------------------------------------------- // Purpose: // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool CBaseHL2MPCombatWeapon::Deploy( void ) { // If we should be lowered, deploy in the lowered position // We have to ask the player if the last time it checked, the weapon was lowered if ( GetOwner() && GetOwner()->IsPlayer() ) { CSDKPlayer *pPlayer = assert_cast<CSDKPlayer*>( GetOwner() ); if ( pPlayer->IsWeaponLowered() ) { if ( SelectWeightedSequence( ACT_VM_IDLE_LOWERED ) != ACTIVITY_NOT_AVAILABLE ) { if ( DefaultDeploy( (char*)GetViewModel(), (char*)GetWorldModel(), ACT_VM_IDLE_LOWERED, (char*)GetAnimPrefix() ) ) { m_bLowered = true; // Stomp the next attack time to fix the fact that the lower idles are long pPlayer->SetNextAttack( gpGlobals->curtime + 1.0 ); m_flNextPrimaryAttack = gpGlobals->curtime + 1.0; m_flNextSecondaryAttack = gpGlobals->curtime + 1.0; return true; } } } } m_bLowered = false; return BaseClass::Deploy(); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CBaseSDKGrenade::SecondaryAttack() { if ( m_bRedraw ) return; CSDKPlayer *pPlayer = GetPlayerOwner(); if ( pPlayer == NULL ) return; //See if we're ducking if ( pPlayer->GetFlags() & FL_DUCKING ) { //Send the weapon animation SendWeaponAnim( ACT_VM_SECONDARYATTACK ); } else { //Send the weapon animation SendWeaponAnim( ACT_VM_HAULBACK ); } // Don't let weapon idle interfere in the middle of a throw! SetWeaponIdleTime( gpGlobals->curtime + SequenceDuration() ); m_flNextSecondaryAttack = gpGlobals->curtime + SequenceDuration(); }
void CDataManager::SavePositions() { if (IsSendingData()) return; d->m_flNextPositionsUpdate = gpGlobals->curtime + da_data_positions_interval.GetFloat(); for (int i = 1; i <= gpGlobals->maxClients; i++) { CSDKPlayer *pPlayer = ToSDKPlayer(UTIL_PlayerByIndex( i )); if (!pPlayer) continue; if (pPlayer->IsBot()) continue; if (!pPlayer->IsAlive()) continue; d->m_avecPlayerPositions.AddToTail(pPlayer->GetAbsOrigin()); if (pPlayer->IsInThirdPerson()) d->m_iThirdPersonActive++; else d->m_iThirdPersonInactive++; } ConVarRef sv_cheats("sv_cheats"); d->m_bCheated |= sv_cheats.GetBool(); }
CBall *GetNearestPlayerBall(const Vector &pos) { CBall *pNearestBall = GetMatchBall(); Vector ballPos = pNearestBall->GetPos(); float shortestDist = (ballPos - pos).Length2DSqr(); for (int i = 1; i <= gpGlobals->maxClients; i++) { CSDKPlayer *pPl = ToSDKPlayer(UTIL_PlayerByIndex(i)); if (!pPl || !CSDKPlayer::IsOnField(pPl)) continue; CBall *pBall = pPl->GetPlayerBall(); if (!pBall) continue; Vector ballPos = pBall->GetPos(); float dist = (ballPos - pos).Length2DSqr(); if (dist < shortestDist) { shortestDist = dist; pNearestBall = pBall; } } return pNearestBall; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CSDKPlayerAnimState::Update( float eyeYaw, float eyePitch ) { // Profile the animation update. VPROF( "CMultiPlayerAnimState::Update" ); // Clear animation overlays because we're about to completely reconstruct them. ClearAnimationLayers(); // Some mods don't want to update the player's animation state if they're dead and ragdolled. if ( !ShouldUpdateAnimState() ) { ClearAnimationState(); return; } // Get the SDK player. CSDKPlayer *pSDKPlayer = GetSDKPlayer(); if ( !pSDKPlayer ) return; // Get the studio header for the player. CStudioHdr *pStudioHdr = pSDKPlayer->GetModelPtr(); if ( !pStudioHdr ) return; // Check to see if we should be updating the animation state - dead, ragdolled? if ( !ShouldUpdateAnimState() ) { ClearAnimationState(); return; } // Store the eye angles. m_flEyeYaw = AngleNormalize( eyeYaw ); m_flEyePitch = AngleNormalize( eyePitch ); // Compute the player sequences. ComputeSequences( pStudioHdr ); if ( SetupPoseParameters( pStudioHdr ) ) { // Pose parameter - what direction are the player's legs running in. ComputePoseParam_MoveYaw( pStudioHdr ); // Pose parameter - Torso aiming (up/down). ComputePoseParam_AimPitch( pStudioHdr ); // Pose parameter - Torso aiming (rotation). ComputePoseParam_AimYaw( pStudioHdr ); } #ifdef CLIENT_DLL if ( C_BasePlayer::ShouldDrawLocalPlayer() ) { m_pSDKPlayer->SetPlaybackRate( 1.0f ); } #endif }
void CSDKGameRules::CalculateSlowMoForPlayer(CSDKPlayer* pPlayer) { if (!pPlayer) return; if (!pPlayer->IsAlive()) { pPlayer->SetSlowMoType(SLOWMO_NONE); return; } // If I activated slow then I get to keep my slow level. if (pPlayer->GetSlowMoType() == SLOWMO_ACTIVATED) return; if (pPlayer->GetSlowMoType() == SLOWMO_STYLESKILL) return; // Players who haven't activated anything are at the whims of those who have. bool bOtherInSlow = false; CUtlVector<CSDKPlayer*> apOthersInPVS; CBaseEntity* pOther = NULL; while ((pOther = UTIL_EntitiesInPVS(pPlayer, pOther)) != NULL) { CSDKPlayer* pOtherPlayer = ToSDKPlayer(pOther); if (!pOtherPlayer) continue; if (pOtherPlayer == pPlayer) continue; apOthersInPVS.AddToTail(pOtherPlayer); } for (int i = 0; i < apOthersInPVS.Size(); i++) { CSDKPlayer* pOtherPlayer = apOthersInPVS[i]; if (!pOtherPlayer->IsAlive()) continue; if (pOtherPlayer->GetSlowMoType() != SLOWMO_NONE) { bOtherInSlow = true; break; } } // If any of these players are in slow then I'm in slow too. if (bOtherInSlow) pPlayer->SetSlowMoType(SLOWMO_PASSIVE); else pPlayer->SetSlowMoType(SLOWMO_NONE); }
void CWeaponMP5::PrimaryAttack( void ) { const CSDKWeaponInfo &pWeaponInfo = GetSDKWpnData(); CSDKPlayer *pPlayer = GetPlayerOwner(); float flCycleTime = pWeaponInfo.m_flCycleTime; bool bPrimaryMode = true; float flSpread = 0.01f; // more spread when jumping if ( !FBitSet( pPlayer->GetFlags(), FL_ONGROUND ) ) flSpread = 0.05f; pPlayer->m_iShotsFired++; // Out of ammo? if ( m_iClip1 <= 0 ) { if (m_bFireOnEmpty) { PlayEmptySound(); m_flNextPrimaryAttack = gpGlobals->curtime + 0.2; } } SendWeaponAnim( ACT_VM_PRIMARYATTACK ); m_iClip1--; // player "shoot" animation pPlayer->SetAnimation( PLAYER_ATTACK1 ); FX_FireBullets( pPlayer->entindex(), pPlayer->Weapon_ShootPosition(), pPlayer->EyeAngles() + pPlayer->GetPunchAngle(), GetWeaponID(), bPrimaryMode?Primary_Mode:Secondary_Mode, CBaseEntity::GetPredictionRandomSeed() & 255, flSpread ); pPlayer->DoMuzzleFlash(); m_flNextPrimaryAttack = m_flNextSecondaryAttack = gpGlobals->curtime + flCycleTime; if (!m_iClip1 && pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) <= 0) { // HEV suit - indicate out of ammo condition pPlayer->SetSuitUpdate("!HEV_AMO0", false, 0); } // start idle animation in 5 seconds SetWeaponIdleTime( gpGlobals->curtime + 5.0 ); }
void CC_ShootPlayerBall(const CCommand &args) { CSDKPlayer *pPl = ToSDKPlayer(UTIL_GetCommandClient()); if (!CSDKPlayer::IsOnField(pPl) || !pPl->GetPlayerBall()) return; pPl->GetPlayerBall()->SetBallCannonMode(true); pPl->GetPlayerBall()->RestoreBallCannonSettings(); pPl->m_Shared.SetStamina(100); }
float CDAViewModel::GetSequenceCycleRate( CStudioHdr *pStudioHdr, int iSequence ) { float flSlow = 1; CSDKPlayer* pOwner = ToSDKPlayer(GetOwner()); if (pOwner) flSlow *= pOwner->GetSlowMoMultiplier(); return BaseClass::GetSequenceCycleRate(pStudioHdr, iSequence) * flSlow; }
void CWeaponSDKMelee::PrimaryAttack() { #ifndef CLIENT_DLL CSDKPlayer *pPlayer = ToSDKPlayer( GetPlayerOwner() ); pPlayer->NoteWeaponFired(); #endif StartSwing( false ); }
// checks if the spot is clear of players bool CSDKGameRules::IsSpawnPointValid( CBaseEntity *pSpot, CBasePlayer *pPlayer ) { if ( !pSpot->IsTriggered( pPlayer ) ) { return false; } // Check if it is disabled by Enable/Disable CSpawnPoint *pSpawnPoint = dynamic_cast< CSpawnPoint * >( pSpot ); if ( pSpawnPoint ) { if ( pSpawnPoint->IsDisabled() ) { return false; } } for (int i = 0; i < gpGlobals->maxClients; i++) { CBasePlayer *pOtherPlayer = UTIL_PlayerByIndex( i ); if (!pOtherPlayer) continue; if (PlayerRelationship(pPlayer, pOtherPlayer) == GR_TEAMMATE) continue; if ((pSpot->GetAbsOrigin() - pOtherPlayer->GetAbsOrigin()).LengthSqr() > 512*512) continue; CSDKPlayer* pOtherSDKPlayer = ToSDKPlayer(pOtherPlayer); trace_t tr; UTIL_TraceLine( pSpot->WorldSpaceCenter(), pOtherSDKPlayer->WorldSpaceCenter(), MASK_VISIBLE_AND_NPCS, pPlayer, COLLISION_GROUP_NONE, &tr ); if (tr.m_pEnt == pOtherPlayer) return false; } CBaseEntity* pGrenade = gEntList.FindEntityByClassname( NULL, "weapon_grenade" ); while (pGrenade) { if ((pSpot->GetAbsOrigin() - pGrenade->GetAbsOrigin()).LengthSqr() < 500*500) return false; pGrenade = gEntList.FindEntityByClassname( pGrenade, "weapon_grenade" ); } Vector mins = GetViewVectors()->m_vHullMin; Vector maxs = GetViewVectors()->m_vHullMax; Vector vTestMins = pSpot->GetAbsOrigin() + mins; Vector vTestMaxs = pSpot->GetAbsOrigin() + maxs; // First test the starting origin. return UTIL_IsSpaceEmpty( pPlayer, vTestMins, vTestMaxs ); }
//----------------------------------------------------------------------------- // Purpose: Recover stamina //----------------------------------------------------------------------------- void CSDKGameMovement::ReduceTimers( void ) { Vector vecPlayerVelocity = m_pSDKPlayer->GetAbsVelocity(); #if defined ( SDK_USE_STAMINA ) || defined ( SDK_USE_SPRINTING ) float flStamina = m_pSDKPlayer->m_Shared.GetStamina(); #endif #if defined ( SDK_USE_SPRINTING ) float fl2DVelocitySquared = vecPlayerVelocity.x * vecPlayerVelocity.x + vecPlayerVelocity.y * vecPlayerVelocity.y; if ( !( mv->m_nButtons & IN_SPEED ) ) { m_pSDKPlayer->m_Shared.ResetSprintPenalty(); } // Can only sprint in forward direction. bool bSprinting = ( (mv->m_nButtons & IN_SPEED) && ( mv->m_nButtons & IN_FORWARD ) ); // If we're holding the sprint key and also actually moving, remove some stamina Vector vel = m_pSDKPlayer->GetAbsVelocity(); if ( bSprinting && fl2DVelocitySquared > 10000 ) //speed > 100 { flStamina -= 20 * gpGlobals->frametime; m_pSDKPlayer->m_Shared.SetStamina( flStamina ); } else #endif // SDK_USE_SPRINTING #if defined ( SDK_USE_STAMINA ) || defined ( SDK_USE_SPRINTING ) { //gain some back if ( fl2DVelocitySquared <= 0 ) { flStamina += 60 * gpGlobals->frametime; } else if ( ( m_pSDKPlayer->GetFlags() & FL_ONGROUND ) && ( mv->m_nButtons & IN_DUCK ) && ( m_pSDKPlayer->GetFlags() & FL_DUCKING ) ) { flStamina += 50 * gpGlobals->frametime; } else { flStamina += 10 * gpGlobals->frametime; } m_pSDKPlayer->m_Shared.SetStamina( flStamina ); } #endif BaseClass::ReduceTimers(); }
bool CWeaponShotgun::Reload() { CSDKPlayer *pPlayer = GetPlayerOwner(); if (pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) <= 0 || m_iClip1 == GetMaxClip1()) return true; // don't reload until recoil is done if (m_flNextPrimaryAttack > gpGlobals->curtime) return true; // check to see if we're ready to reload if (m_fInSpecialReload == 0) { pPlayer->SetAnimation( PLAYER_RELOAD ); SendWeaponAnim( ACT_SHOTGUN_RELOAD_START ); m_fInSpecialReload = 1; pPlayer->m_flNextAttack = gpGlobals->curtime + 0.5; m_flNextPrimaryAttack = gpGlobals->curtime + 0.5; m_flNextSecondaryAttack = gpGlobals->curtime + 0.5; SetWeaponIdleTime( gpGlobals->curtime + 0.5 ); return true; } else if (m_fInSpecialReload == 1) { if (m_flTimeWeaponIdle > gpGlobals->curtime) return true; // was waiting for gun to move to side m_fInSpecialReload = 2; SendWeaponAnim( ACT_VM_RELOAD ); SetWeaponIdleTime( gpGlobals->curtime + 0.45 ); } else { // Add them to the clip m_iClip1 += 1; #ifdef GAME_DLL SendReloadEvents(); #endif CSDKPlayer *pPlayer = GetPlayerOwner(); if ( pPlayer ) pPlayer->RemoveAmmo( 1, m_iPrimaryAmmoType ); m_fInSpecialReload = 1; } return true; }
//----------------------------------------------------------------------------- // Purpose: Run through all the Bots in the game and let them think. //----------------------------------------------------------------------------- void Bot_RunAll(void) { /*if (g_iWaitingAmount && g_bServerReady) //Kind of a shitty hack. But this will allow people to spawn a certain amount of bots in { //the server.cfg. Anyway, the server is ready, so do it. BotPutInServer(g_iWaitingAmount, false); g_iWaitingAmount = 0; //Make sure we've reset the waiting count. }*/ //bot manager handles bot population via the svars CBotManager::Think(); //let the vcomm managers do their thing g_BotAmerComms.Think(); g_BotBritComms.Think(); if (bot_pause.GetBool()) //If we're true, just don't run the thinking cycle. Effectively "pausing" the bots. return; BotDebugThink(); //we're testing something, don't let the AI interfere! extern ConVar bot_mimic; if (bot_mimic.GetBool()) return; #ifdef PROFILE_BOT_PERFORMANCE auto preThinkTime = std::chrono::system_clock::now(); #endif for (int i = 1; i <= gpGlobals->maxClients; i++) { CSDKPlayer *pPlayer = UTIL_PlayerByIndex(i);// ); if (pPlayer && (pPlayer->GetFlags() & FL_FAKECLIENT)) { CSDKBot *pBot = CSDKBot::ToBot(pPlayer); if (pBot) {//Do most of the "filtering" here. pBot->Think(); } } } #ifdef PROFILE_BOT_PERFORMANCE auto postThinkTime = std::chrono::system_clock::now(); int deltaTime = std::chrono::duration_cast<std::chrono::milliseconds>(postThinkTime - preThinkTime).count(); static int counter = 0; counter++; if (counter == 500) { counter = 0; Msg("%i\n", deltaTime); } #endif }
Activity CSDKPlayerAnimState::CalcMainActivity() { float flOuterSpeed = GetOuterXYSpeed(); CSDKPlayer *pPlayer = dynamic_cast<CSDKPlayer*>(GetBasePlayer()); Activity idealActivity = ACT_IDLE; if (pPlayer->m_Shared.m_bIsShotCharging && mp_charging_animation_enabled.GetBool()) return ACT_IOS_RUNCELEB; if ( HandleJumping(idealActivity) ) { if (pPlayer->GetFlags() & FL_CELEB) return ACT_IOS_JUMPCELEB; //cartwheel celeb //else if (pPlayer->m_nBody > 0) else if (pPlayer->m_Shared.GetAnimEvent() == PLAYERANIMEVENT_KEEPER_JUMP) return ACT_IDLE;//FIXME: Buggy jump animation: ACT_LEAP; //keepers jump else return ACT_IDLE;//FIXME: Buggy jump animation: ACT_HOP; //normal jump } else { if ( flOuterSpeed > MOVING_MINIMUM_SPEED ) { if ( flOuterSpeed > (mp_runspeed.GetInt() + mp_sprintspeed.GetInt()) / 2.0f ) { idealActivity = ACT_SPRINT; } else if ( flOuterSpeed > (mp_walkspeed.GetInt() + mp_runspeed.GetInt()) / 2.0f ) { if (pPlayer->GetFlags() & FL_CELEB) //now on layer idealActivity = ACT_IOS_RUNCELEB; else idealActivity = ACT_RUN; } else { idealActivity = ACT_WALK; } } else { idealActivity = ACT_IDLE; } return idealActivity; } }
//------------------------------------------------------------------------------ // Purpose : // Input : // Output : //------------------------------------------------------------------------------ void CWeaponSDKMelee::PrimaryAttack() { #ifndef CLIENT_DLL CSDKPlayer *pPlayer = ToSDKPlayer( GetPlayerOwner() ); pPlayer->NoteWeaponFired(); // Move other players back to history positions based on local player's lag lagcompensation->StartLagCompensation( pPlayer, pPlayer->GetCurrentCommand() ); #endif Swing( false ); #ifndef CLIENT_DLL // Move other players back to history positions based on local player's lag lagcompensation->FinishLagCompensation( pPlayer ); #endif }
void CWeaponSDKBase::SendReloadEvents() { CSDKPlayer *pPlayer = dynamic_cast< CSDKPlayer* >( GetOwner() ); if ( !pPlayer ) return; // Send a message to any clients that have this entity to play the reload. CPASFilter filter( pPlayer->GetAbsOrigin() ); filter.RemoveRecipient( pPlayer ); UserMessageBegin( filter, "ReloadEffect" ); WRITE_SHORT( pPlayer->entindex() ); MessageEnd(); // Make the player play his reload animation. pPlayer->DoAnimationEvent( PLAYERANIMEVENT_RELOAD ); }
void CArmorRechargerClassic::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) { // if it's not a player, ignore if ( !pActivator || !pActivator->IsPlayer()) { return; } else if (GameRules()->GetGameMode() == GAMEMODE_CLASSIC) { if (ClassicGameRules()->GetCurrentPhaseID() == PHASE_BUILD) { if (m_flSoundTime <= gpGlobals->curtime) { m_flSoundTime = gpGlobals->curtime + 0.62; EmitSound( "SuitRecharge.Deny" ); } return; } else if (GetTeamNumber() != pActivator->GetTeamNumber() && GetTeamNumber() != TEAM_SPECTATOR) { if (m_flSoundTime <= gpGlobals->curtime) { CBasePlayer *pPlayer = ToBasePlayer( pActivator ); Assert( pPlayer ); ClientPrint( pPlayer, HUD_PRINTTALK, "#lf_armor_charger_deny" ); m_flSoundTime = gpGlobals->curtime + 0.62; EmitSound( "SuitRecharge.Deny" ); } return; } } CSDKPlayer *pPlayer = ToSDKPlayer( pCaller ); AssertMsg( pPlayer, "Failure SDKPlayer Armor charger\n" ); CSDKTeam *pTeam = GetGlobalSDKTeam( pPlayer->GetTeamNumber() ); const CSDKPlayerClassInfo &pClassInfo = pTeam->GetPlayerClassInfo( pPlayer->m_Shared.PlayerClass() ); SetMaxArmor( pClassInfo.m_iArmor ); BaseClass::Use( pActivator, pCaller, useType, value ); }
float CWeaponSDKMelee::GetMeleeDamage( bool bIsSecondary ) const { CSDKPlayer *pPlayer = ToSDKPlayer( GetOwner() ); float flDamage = GetSDKWpnData().m_iDamage; if (bIsSecondary) flDamage = GetSDKWpnData().m_iSecondaryDamage; flDamage = pPlayer->m_Shared.ModifySkillValue(flDamage, 0.2f, SKILL_BOUNCER); if (pPlayer->m_Shared.IsDiving()) flDamage *= 1.5f; else if (!pPlayer->GetGroundEntity()) flDamage *= 1.2f; return flDamage; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CBaseSDKGrenade::PrimaryAttack() { if ( m_bRedraw || m_bPinPulled ) return; CSDKPlayer *pPlayer = GetPlayerOwner(); if ( !pPlayer || pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) <= 0 ) return; // The pull pin animation has to finish, then we wait until they aren't holding the primary // attack button, then throw the grenade. SendWeaponAnim( ACT_VM_PULLPIN ); m_bPinPulled = true; // Don't let weapon idle interfere in the middle of a throw! SetWeaponIdleTime( gpGlobals->curtime + SequenceDuration() ); m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); }
void CWeaponShotgun::PrimaryAttack() { CSDKPlayer *pPlayer = GetPlayerOwner(); if ( !pPlayer ) return; // don't fire underwater if (pPlayer->GetWaterLevel() == 3) { PlayEmptySound( ); m_flNextPrimaryAttack = GetCurrentTime() + 0.15; return; } BaseClass::PrimaryAttack(); if ( m_iClip1 > 0 ) m_iInSpecialReload = 0; }
//------------------------------------------------------------------------------ // Purpose : Update weapon //------------------------------------------------------------------------------ void CWeaponSDKMelee::ItemPostFrame( void ) { CSDKPlayer *pPlayer = GetPlayerOwner(); if ( pPlayer == NULL ) return; if (IsThrowingGrenade()) { if (MaintainGrenadeToss()) return; } else if ((pPlayer->m_nButtons & IN_ALT2) && !IsThrowingGrenade() && pPlayer->GetAmmoCount(GetAmmoDef()->Index("grenades")) && pPlayer->CanAttack()) { bool bAllow = (m_flNextPrimaryAttack < GetCurrentTime()); if (m_bInReload) bAllow = true; if (bAllow) { StartGrenadeToss(); return; } } if (GetSwingTime() > 0 && GetSwingTime() <= GetCurrentTime()) { Swing(); } else if ( (pPlayer->m_nButtons & IN_ATTACK) && (m_flNextPrimaryAttack <= GetCurrentTime()) && pPlayer->CanAttack() ) { PrimaryAttack(); } else if ( (pPlayer->m_nButtons & IN_ATTACK2) && (m_flNextSecondaryAttack <= GetCurrentTime()) && pPlayer->CanAttack() ) { SecondaryAttack(); } else { WeaponIdle(); } }
CBlockBase *CWeaponCombatCannon::FindTraceBlock( void ) { CSDKPlayer *pPlayer = ToSDKPlayer( GetOwner() ); CBaseEntity *pEntity = NULL; if ( m_grabController.GetAttached() ) { pEntity = m_grabController.GetAttached(); } else { Vector vecSrc, vecEnd, vecDir; vecSrc = pPlayer->Weapon_ShootPosition(); pPlayer->EyeVectors( &vecDir ); // Calculate max distance as twice the radius of the block float max_distance = pPlayer->CollisionProp()->BoundingRadius() + lf_freeze_distance_combat.GetFloat(); vecEnd = vecSrc + vecDir * max_distance; UTIL_TraceLine( vecSrc, vecEnd, MASK_SHOT, GetOwner(), COLLISION_GROUP_NONE, &m_tr ); pEntity = m_tr.m_pEnt; } if ( !pEntity || !pEntity->IsBlock() ) { ResetFreezing(); return NULL; } CBlockBase *pBlock = dynamic_cast < CBlockBase * > ( pEntity ); if( !pBlock ) { DevMsg( "Not a block\n" ); return NULL; } return pBlock; }
//----------------------------------------------------------------------------- // Purpose: // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool CBaseSDKGrenade::Holster( CBaseCombatWeapon *pSwitchingTo ) { m_bRedraw = false; m_bPinPulled = false; // when this is holstered make sure the pin isn’t pulled. m_fThrowTime = 0; #ifndef CLIENT_DLL // If they attempt to switch weapons before the throw animation is done, // allow it, but kill the weapon if we have to. CSDKPlayer *pPlayer = GetPlayerOwner(); if( pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0 ) { CBaseCombatCharacter *pOwner = (CBaseCombatCharacter *)pPlayer; pOwner->Weapon_Drop( this ); UTIL_Remove(this); } #endif return BaseClass::Holster( pSwitchingTo ); }
void CSDKGameRules::ReCalculateSlowMo() { // Reset all passive players to none, to prevent circular activations for (int i = 1; i < gpGlobals->maxClients; i++) { CBasePlayer* pPlayer = UTIL_PlayerByIndex(i); if (!pPlayer) continue; CSDKPlayer* pSDKPlayer = static_cast<CSDKPlayer*>(pPlayer); if (pSDKPlayer->GetSlowMoType() == SLOWMO_PASSIVE) pSDKPlayer->SetSlowMoType(SLOWMO_NONE); } for (int i = 1; i < gpGlobals->maxClients; i++) { CBasePlayer* pPlayer = UTIL_PlayerByIndex(i); if (!pPlayer) continue; CSDKPlayer* pSDKPlayer = static_cast<CSDKPlayer*>(pPlayer); // If the player is passive it means they've already been reached recursively. // If the player activated their own slowmo then they don't need to be calculated. if (pSDKPlayer->GetSlowMoType() == SLOWMO_PASSIVE || pSDKPlayer->GetSlowMoType() == SLOWMO_ACTIVATED || pSDKPlayer->GetSlowMoType() == SLOWMO_STYLESKILL) GiveSlowMoToNearbyPlayers(pSDKPlayer); else CalculateSlowMoForPlayer(pSDKPlayer); } m_flNextSlowMoUpdate = gpGlobals->curtime + 0.5f; }
//------------------------------------------------------------------------------ // Purpose: Implement impact function //------------------------------------------------------------------------------ void CWeaponSDKMelee::Hit( trace_t &traceHit, Activity nHitActivity ) { CSDKPlayer *pPlayer = ToSDKPlayer( GetOwner() ); //Do view kick // AddViewKick(); CBaseEntity *pHitEntity = traceHit.m_pEnt; //Apply damage to a hit target if ( pHitEntity != NULL ) { Vector hitDirection; pPlayer->EyeVectors( &hitDirection, NULL, NULL ); VectorNormalize( hitDirection ); #ifndef CLIENT_DLL CTakeDamageInfo info( GetOwner(), GetOwner(), GetDamageForActivity( nHitActivity ), DMG_CLUB ); if( pPlayer && pHitEntity->IsNPC() ) { // If bonking an NPC, adjust damage. info.AdjustPlayerDamageInflictedForSkillLevel(); } CalculateMeleeDamageForce( &info, hitDirection, traceHit.endpos ); pHitEntity->DispatchTraceAttack( info, hitDirection, &traceHit ); ApplyMultiDamage(); // Now hit all triggers along the ray that... TraceAttackToTriggers( info, traceHit.startpos, traceHit.endpos, hitDirection ); #endif WeaponSound( MELEE_HIT ); } // Apply an impact effect ImpactEffect( traceHit ); }
void CSDKGameRules::GiveSlowMoToNearbyPlayers(CSDKPlayer* pPlayer) { if (!pPlayer) return; if (!pPlayer->IsAlive()) { pPlayer->SetSlowMoType(SLOWMO_NONE); return; } if (pPlayer->GetSlowMoType() == SLOWMO_NONE) return; // I have some slowmo on me. Pass it to other players nearby. CUtlVector<CSDKPlayer*> apOthersInPVS; CBaseEntity* pOther = NULL; while ((pOther = UTIL_EntitiesInPVS(pPlayer, pOther)) != NULL) { CSDKPlayer* pOtherPlayer = ToSDKPlayer(pOther); if (!pOtherPlayer) continue; if (pOtherPlayer == pPlayer) continue; // If they already have slow mo, we don't need to pass it to them. if (pOtherPlayer->GetSlowMoType() == SLOWMO_STYLESKILL) continue; if (pOtherPlayer->GetSlowMoType() == SLOWMO_ACTIVATED) continue; if (pOtherPlayer->GetSlowMoType() == SLOWMO_PASSIVE) continue; apOthersInPVS.AddToTail(pOtherPlayer); } for (int i = 0; i < apOthersInPVS.Size(); i++) { CSDKPlayer* pOtherPlayer = apOthersInPVS[i]; // It could have been already done by a previous iteration of the recursion below. if (pOtherPlayer->GetSlowMoType() != SLOWMO_NONE) continue; pOtherPlayer->SetSlowMoType(SLOWMO_PASSIVE); GiveSlowMoToNearbyPlayers(pOtherPlayer); } }
void CWeaponShotgun::WeaponIdle() { CSDKPlayer *pPlayer = GetPlayerOwner(); if (m_flPumpTime && m_flPumpTime < gpGlobals->curtime) { // play pumping sound m_flPumpTime = 0; } if (m_flTimeWeaponIdle < gpGlobals->curtime) { if (m_iClip1 == 0 && m_fInSpecialReload == 0 && pPlayer->GetAmmoCount( m_iPrimaryAmmoType )) { Reload( ); } else if (m_fInSpecialReload != 0) { if (m_iClip1 != 8 && pPlayer->GetAmmoCount( m_iPrimaryAmmoType )) { Reload( ); } else { // reload debounce has timed out //MIKETODO: shotgun anims SendWeaponAnim( ACT_SHOTGUN_RELOAD_FINISH ); // play cocking sound m_fInSpecialReload = 0; SetWeaponIdleTime( gpGlobals->curtime + 1.5 ); } } else { SendWeaponAnim( ACT_VM_IDLE ); } } }
void CDataManager::SavePositions() { if (IsSendingData()) return; m_flNextPositionsUpdate = gpGlobals->curtime + da_data_positions_interval.GetFloat(); for (int i = 1; i <= gpGlobals->maxClients; i++) { CSDKPlayer *pPlayer = ToSDKPlayer(UTIL_PlayerByIndex( i )); if (!pPlayer) continue; if (pPlayer->IsBot()) continue; if (!pPlayer->IsAlive()) continue; m_avecPlayerPositions.AddToTail(pPlayer->GetAbsOrigin()); } }