//========================================================= // Traduce una animación. //========================================================= Activity CIN_Player::TranslateActivity(Activity baseAct, bool *pRequired) { // Esta será la nueva animación. Activity translated = baseAct; // El jugador tiene una arma, usar la animación con esa arma. if ( GetActiveWeapon() ) translated = GetActiveWeapon()->ActivityOverride(baseAct, pRequired); // Estamos desarmados, verificar si existe una animación. else if ( unarmedActtable ) { acttable_t *pTable = unarmedActtable; int actCount = ARRAYSIZE(unarmedActtable); for ( int i = 0; i < actCount; i++, pTable++ ) { if ( baseAct == pTable->baseAct ) translated = (Activity)pTable->weaponAct; } } else if ( pRequired ) *pRequired = false; // @DEBUG: Guardamos la animación nueva para poder usarla en la información de depuración: anim_showstatelog #ifndef CLIENT_DLL //DevMsg("[ANIM] %s \r\n", ActivityList_NameForIndex(translated)); #endif return translated; }
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- void CNPC_Monk::OnKilledNPC( CBaseCombatCharacter *pKilled ) { if ( !pKilled ) { return; } if ( pKilled->Classify() == CLASS_ZOMBIE ) { // Don't speak if the gun is empty, cause grigori will want to speak while he's reloading. if ( GetActiveWeapon() ) { if ( GetActiveWeapon()->UsesPrimaryAmmo() && !GetActiveWeapon()->HasPrimaryAmmo() ) { // Gun is empty. I'm about to reload. if( m_iNumZombies >= 2 ) { // Don't talk about killing a single zombie if there are more coming. // the reload behavior will say "come to me, children", etc. return; } } } if( m_iNumZombies == 1 || random->RandomInt( 1, 3 ) == 1 ) { SpeakIfAllowed( TLK_ENEMY_DEAD ); } } }
void CHL2MP_Player::Weapon_Drop( CBaseCombatWeapon *pWeapon, const Vector *pvecTarget, const Vector *pVelocity ) { //Drop a grenade if it's primed. if ( GetActiveWeapon() ) { CBaseCombatWeapon *pGrenade = Weapon_OwnsThisType("weapon_frag"); if ( GetActiveWeapon() == pGrenade ) { if ( ( m_nButtons & IN_ATTACK ) || (m_nButtons & IN_ATTACK2) ) { DropPrimedFragGrenade( this, pGrenade ); return; } //DHL - Skillet else { pGrenade->Drop( *pVelocity ); return; } } } BaseClass::Weapon_Drop( pWeapon, pvecTarget, pVelocity ); }
bool CSDKPlayer::Weapon_CanSwitchTo( CBaseCombatWeapon *pWeapon ) { if (IsPlayer()) { CBasePlayer *pPlayer = (CBasePlayer *)this; #if !defined( CLIENT_DLL ) IServerVehicle *pVehicle = pPlayer->GetVehicle(); #else IClientVehicle *pVehicle = pPlayer->GetVehicle(); #endif if (pVehicle && !pPlayer->UsingStandardWeaponsInVehicle()) return false; } if ( !pWeapon->CanDeploy() ) return false; if ( GetActiveWeapon() ) { if ( !GetActiveWeapon()->CanHolster() ) return false; } return true; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CBasePlayer::SelectItem( const char *pstr, int iSubType ) { if (!pstr) return; CBaseCombatWeapon *pItem = Weapon_OwnsThisType( pstr, iSubType ); if (!pItem) return; if( GetObserverMode() != OBS_MODE_NONE ) return;// Observers can't select things. if ( !Weapon_ShouldSelectItem( pItem ) ) return; // FIX, this needs to queue them up and delay // Make sure the current weapon can be holstered if ( GetActiveWeapon() ) { if ( !GetActiveWeapon()->CanHolster() ) return; ResetAutoaim( ); } Weapon_Switch( pItem ); }
//----------------------------------------------------------------------------- // Purpose: Abort any reloads we're in //----------------------------------------------------------------------------- void CBasePlayer::AbortReload( void ) { if ( GetActiveWeapon() ) { GetActiveWeapon()->AbortReload(); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CUnitBase::OnUserControl( CHL2WarsPlayer *pPlayer ) { #ifdef CLIENT_DLL if( GetActiveWeapon() ) GetActiveWeapon()->SetViewModel(); #endif // CLIENT_DLL }
void CNPC_Monk::StartTask( const Task_t *pTask ) { switch( pTask->iTask ) { case TASK_RELOAD: { if ( GetActiveWeapon() && GetActiveWeapon()->HasPrimaryAmmo() ) { // Don't reload if you have done so while moving (See BACK_AWAY_AND_RELOAD schedule). TaskComplete(); return; } if( m_iNumZombies >= 2 && random->RandomInt( 1, 3 ) == 1 ) { SpeakIfAllowed( TLK_ATTACKING ); } Activity reloadGesture = TranslateActivity( ACT_GESTURE_RELOAD ); if ( reloadGesture != ACT_INVALID && IsPlayingGesture( reloadGesture ) ) { ResetIdealActivity( ACT_IDLE ); return; } BaseClass::StartTask( pTask ); } break; default: BaseClass::StartTask( pTask ); break; } }
//----------------------------------------------------------------------------- // Purpose: // Output : const char //----------------------------------------------------------------------------- const char *CBasePlayer::GetTracerType( void ) { if ( GetActiveWeapon() ) { return GetActiveWeapon()->GetTracerType(); } return BaseClass::GetTracerType(); }
//----------------------------------------------------------------------------- // Purpose: // Input : &vecTracerSrc - // &tr - // iTracerType - //----------------------------------------------------------------------------- void CBasePlayer::MakeTracer( const Vector &vecTracerSrc, const trace_t &tr, int iTracerType ) { if ( GetActiveWeapon() ) { GetActiveWeapon()->MakeTracer( vecTracerSrc, tr, iTracerType ); return; } BaseClass::MakeTracer( vecTracerSrc, tr, iTracerType ); }
void C_HL2MP_Player::DoImpactEffect( trace_t &tr, int nDamageType ) { if ( GetActiveWeapon() ) { GetActiveWeapon()->DoImpactEffect( tr, nDamageType ); return; } BaseClass::DoImpactEffect( tr, nDamageType ); }
//----------------------------------------------------------------------------- // Purpose: // Input : &tr - // nDamageType - //----------------------------------------------------------------------------- void CUnitBase::DoImpactEffect( trace_t &tr, int nDamageType ) { if ( GetActiveWeapon() != NULL ) { GetActiveWeapon()->DoImpactEffect( tr, nDamageType ); return; } BaseClass::DoImpactEffect( tr, nDamageType ); }
void CBasePlayer::SelectLastItem(void) { if ( m_hLastWeapon.Get() == NULL ) return; if ( GetActiveWeapon() && !GetActiveWeapon()->CanHolster() ) return; SelectItem( m_hLastWeapon.Get()->GetClassname(), m_hLastWeapon.Get()->GetSubType() ); }
bool CNPC_Monk::IsValidEnemy( CBaseEntity *pEnemy ) { if ( BaseClass::IsValidEnemy( pEnemy ) && GetActiveWeapon() ) { float flDist; flDist = ( GetAbsOrigin() - pEnemy->GetAbsOrigin() ).Length(); if( flDist <= GetActiveWeapon()->m_fMaxRange1 ) return true; } return false; }
//----------------------------------------------------------------------------- // Purpose: check ammo //----------------------------------------------------------------------------- void CAI_BaseHumanoid::CheckAmmo( void ) { BaseClass::CheckAmmo(); // FIXME: put into GatherConditions()? // FIXME: why isn't this a baseclass function? if (!GetActiveWeapon()) return; // Don't do this while holstering / unholstering if ( IsWeaponStateChanging() ) return; if (GetActiveWeapon()->UsesPrimaryAmmo()) { if (!GetActiveWeapon()->HasPrimaryAmmo() ) { SetCondition(COND_NO_PRIMARY_AMMO); } else if (GetActiveWeapon()->UsesClipsForAmmo1() && GetActiveWeapon()->Clip1() < (GetActiveWeapon()->GetMaxClip1() / 4 + 1)) { // don't check for low ammo if you're near the max range of the weapon SetCondition(COND_LOW_PRIMARY_AMMO); } } if (!GetActiveWeapon()->HasSecondaryAmmo() ) { if ( GetActiveWeapon()->UsesClipsForAmmo2() ) { SetCondition(COND_NO_SECONDARY_AMMO); } } }
Activity CDODPlayer::TranslateActivity( Activity baseAct, bool *pRequired /* = NULL */ ) { Activity translated = baseAct; if ( GetActiveWeapon() ) { translated = GetActiveWeapon()->ActivityOverride( baseAct, pRequired ); } else if (pRequired) { *pRequired = false; } return translated; }
void CHL2MP_Player::FireBullets ( const FireBulletsInfo_t &info ) { #ifndef GE_DLL // Move other players back to history positions based on local player's lag lagcompensation->StartLagCompensation( this, this->GetCurrentCommand() ); FireBulletsInfo_t modinfo = info; CWeaponHL2MPBase *pWeapon = dynamic_cast<CWeaponHL2MPBase *>( GetActiveWeapon() ); if ( pWeapon ) { modinfo.m_iPlayerDamage = modinfo.m_iDamage = pWeapon->GetHL2MPWpnData().m_iPlayerDamage; } NoteWeaponFired(); BaseClass::FireBullets( modinfo ); // Move other players back to history positions based on local player's lag lagcompensation->FinishLagCompensation( this ); #else BaseClass::FireBullets( info ); #endif }
bool CAI_BaseHumanoid::OnMoveBlocked( AIMoveResult_t *pResult ) { if ( *pResult != AIMR_BLOCKED_NPC && GetNavigator()->GetBlockingEntity() && !GetNavigator()->GetBlockingEntity()->IsNPC() ) { CBaseEntity *pBlocker = GetNavigator()->GetBlockingEntity(); float massBonus = ( IsNavigationUrgent() ) ? 40.0 : 0; if ( pBlocker->GetMoveType() == MOVETYPE_VPHYSICS && pBlocker != GetGroundEntity() && !pBlocker->IsNavIgnored() && !dynamic_cast<CBasePropDoor *>(pBlocker) && pBlocker->VPhysicsGetObject() && pBlocker->VPhysicsGetObject()->IsMoveable() && ( pBlocker->VPhysicsGetObject()->GetMass() <= 35.0 + massBonus + 0.1 || ( pBlocker->VPhysicsGetObject()->GetMass() <= 50.0 + massBonus + 0.1 && IsSmall( pBlocker ) ) ) ) { DbgNavMsg1( this, "Setting ignore on object %s", pBlocker->GetDebugName() ); pBlocker->SetNavIgnore( 2.5 ); } #if 0 else { CPhysicsProp *pProp = dynamic_cast<CPhysicsProp*>( pBlocker ); if ( pProp && pProp->GetHealth() && pProp->GetExplosiveDamage() == 0.0 && GetActiveWeapon() && !GetActiveWeapon()->ClassMatches( "weapon_rpg" ) ) { Msg( "!\n" ); // Destroy! } } #endif } return BaseClass::OnMoveBlocked( pResult ); }
//----------------------------------------------------------------------------- // Purpose: Called every usercmd by the player PreThink //----------------------------------------------------------------------------- void CBasePlayer::ItemPreFrame() { // Handle use events PlayerUse(); CBaseCombatWeapon *pActive = GetActiveWeapon(); // Allow all the holstered weapons to update for ( int i = 0; i < WeaponCount(); ++i ) { CBaseCombatWeapon *pWeapon = GetWeapon( i ); if ( pWeapon == NULL ) continue; if ( pActive == pWeapon ) continue; pWeapon->ItemHolsterFrame(); } if ( gpGlobals->curtime < m_flNextAttack ) return; if (!pActive) return; #if defined( CLIENT_DLL ) // Not predicting this weapon if ( !pActive->IsPredicted() ) return; #endif pActive->ItemPreFrame(); }
//----------------------------------------------------------------------------- // Purpose //----------------------------------------------------------------------------- void C_BaseViewModel::FireEvent( const Vector& origin, const QAngle& angles, int event, const char *options ) { // We override sound requests so that we can play them locally on the owning player if ( ( event == AE_CL_PLAYSOUND ) || ( event == CL_EVENT_SOUND ) ) { // Only do this if we're owned by someone if ( GetOwner() != NULL ) { CLocalPlayerFilter filter; EmitSound( filter, GetOwner()->GetSoundSourceIndex(), options, &GetAbsOrigin() ); return; } } // Otherwise pass the event to our associated weapon C_BaseCombatWeapon *pWeapon = GetActiveWeapon(); if ( pWeapon ) { // NVNT notify the haptics system of our viewmodel's event if ( haptics ) haptics->ProcessHapticEvent(4,"Weapons",pWeapon->GetName(),"AnimationEvents",VarArgs("%i",event)); bool bResult = pWeapon->OnFireEvent( this, origin, angles, event, options ); if ( !bResult ) { BaseClass::FireEvent( origin, angles, event, options ); } } }
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; }
//----------------------------------------------------------------------------- // Purpose: Called every usercmd by the player PostThink //----------------------------------------------------------------------------- void CBasePlayer::ItemPostFrame() { VPROF( "CBasePlayer::ItemPostFrame" ); // Put viewmodels into basically correct place based on new player origin CalcViewModelView( EyePosition(), EyeAngles() ); // check if the player is using something if ( m_hUseEntity != NULL ) { #if !defined( CLIENT_DLL ) ImpulseCommands();// this will call playerUse #endif return; } if ( gpGlobals->curtime < m_flNextAttack ) { if ( GetActiveWeapon() ) { GetActiveWeapon()->ItemBusyFrame(); } } else { if ( GetActiveWeapon() ) { #if defined( CLIENT_DLL ) // Not predicting this weapon if ( GetActiveWeapon()->IsPredicted() ) #endif { GetActiveWeapon()->ItemPostFrame( ); } } } #if !defined( CLIENT_DLL ) ImpulseCommands(); #else // NOTE: If we ever support full impulse commands on the client, // remove this line and call ImpulseCommands instead. m_nImpulse = 0; #endif }
//----------------------------------------------------------------------------- // Purpose: called every frame to get ammo info from the weapon //----------------------------------------------------------------------------- void CDoDHudAmmo::OnThink() { C_BaseCombatWeapon *wpn = GetActiveWeapon(); C_BasePlayer *player = C_BasePlayer::GetLocalPlayer(); hudlcd->SetGlobalStat( "(weapon_print_name)", wpn ? wpn->GetPrintName() : " " ); hudlcd->SetGlobalStat( "(weapon_name)", wpn ? wpn->GetName() : " " ); if ( !wpn || !player || !wpn->UsesPrimaryAmmo() ) { hudlcd->SetGlobalStat( "(ammo_primary)", "n/a" ); hudlcd->SetGlobalStat( "(ammo_secondary)", "n/a" ); SetPaintEnabled( false ); SetPaintBackgroundEnabled( false ); return; } else { SetPaintEnabled( true ); SetPaintBackgroundEnabled( true ); } // get the ammo in our clip int ammo1 = wpn->Clip1(); int ammo2; if ( ammo1 < 0 ) { // we don't use clip ammo, just use the total ammo count ammo1 = player->GetAmmoCount( wpn->GetPrimaryAmmoType() ); ammo2 = 0; } else { // we use clip ammo, so the second ammo is the total ammo ammo2 = player->GetAmmoCount( wpn->GetPrimaryAmmoType() ); } hudlcd->SetGlobalStat( "(ammo_primary)", VarArgs( "%d", ammo1 ) ); hudlcd->SetGlobalStat( "(ammo_secondary)", VarArgs( "%d", ammo2 ) ); if ( wpn == m_hCurrentActiveWeapon ) { // same weapon, just update counts SetAmmo( ammo1, true ); SetAmmo2( ammo2, true ); } else { // diferent weapon, change without triggering SetAmmo( ammo1, false ); SetAmmo2( ammo2, false ); // update whether or not we show the total ammo display m_bUsesClips = wpn->UsesClipsForAmmo1(); m_hCurrentActiveWeapon = wpn; } }
//========================================================= // Calcula la nueva velocidad del jugador dependiendo del // peso de la arma. //========================================================= float CIN_Player::CalculateSpeed(CBaseCombatWeapon *pWeapon, float speed) { // No se especifico el arma, obtenerla automaticamente. if ( pWeapon == NULL ) pWeapon = GetActiveWeapon(); ConVarRef hl2_sprintspeed("hl2_sprintspeed"); ConVarRef hl2_walkspeed("hl2_walkspeed"); // Obtenemos la velocidad inicial. if ( speed == 0 && IsSprinting() ) speed = hl2_sprintspeed.GetFloat(); if ( speed == 0 && !IsSprinting() ) speed = hl2_walkspeed.GetFloat(); float newSpeed = speed; // Arma válida. if ( pWeapon ) { // Obtenemos el peso del arma. float weaponWeight = pWeapon->GetWpnData().m_WeaponWeight; // El arma es muy ligera, te da velocidad. if ( weaponWeight < 0 ) { weaponWeight = fabs(weaponWeight); newSpeed = newSpeed + weaponWeight; } else newSpeed = newSpeed - weaponWeight; } // Menos de 40% de salud. if ( GetHealth() <= 40 ) { // Disminuimos más velocidad entre menos salud tengamos. if ( GetHealth() <= 5 ) newSpeed = newSpeed - 10; else if ( GetHealth() <= 10 ) newSpeed = newSpeed - 5; else if ( GetHealth() <= 20 ) newSpeed = newSpeed - 3; else if ( GetHealth() <= 40 ) newSpeed = newSpeed - 2; } if ( newSpeed < 10 ) newSpeed = 10; return newSpeed; }
//----------------------------------------------------------------------------- // Purpose: Use correct view model FOV //----------------------------------------------------------------------------- float ClientModeHL2MPNormal::GetViewModelFOV() { CWeaponHL2MPBase *pWeapon = dynamic_cast<CWeaponHL2MPBase*>(GetActiveWeapon()); if (pWeapon) { return pWeapon->GetViewModelFOV(); } return BaseClass::GetViewModelFOV(); }
//----------------------------------------------------------------------------- // Only supports weapons that use clips. //----------------------------------------------------------------------------- bool CRebelZombie::ActiveWeaponIsFullyLoaded() { CBaseCombatWeapon *pWeapon = GetActiveWeapon(); if( !pWeapon ) return false; //Always loaded. return true; }
//----------------------------------------------------------------------------- // Purpose: // Input : &vecTracerSrc - // &tr - // iTracerType - //----------------------------------------------------------------------------- void CUnitBase::MakeTracer( const Vector &vecTracerSrc, const trace_t &tr, int iTracerType ) { CWarsWeapon *pWeapon = dynamic_cast<CWarsWeapon *>( GetActiveWeapon() ); if ( pWeapon ) { pWeapon->MakeTracer( vecTracerSrc, tr, iTracerType ); return; } BaseClass::MakeTracer( vecTracerSrc, tr, iTracerType ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void C_BaseViewModel::GetBoneControllers(float controllers[MAXSTUDIOBONECTRLS]) { BaseClass::GetBoneControllers( controllers ); // Tell the weapon itself that we've rendered, in case it wants to do something C_BaseCombatWeapon *pWeapon = GetActiveWeapon(); if ( pWeapon ) { pWeapon->GetViewmodelBoneControllers( this, controllers ); } }
Vector CBasePlayer::Weapon_ShootDirection( ) { if ( weapontracking && GetActiveWeapon() != NULL ) { return weaponangle; } Vector v; EyeVectors(&v); return v; }
//----------------------------------------------------------------------------- // Purpose: Override base class so player can reset autoaim // Input : // Output : //----------------------------------------------------------------------------- bool CBasePlayer::Weapon_Switch( CBaseCombatWeapon *pWeapon, int viewmodelindex /*=0*/ ) { CBaseCombatWeapon *pLastWeapon = GetActiveWeapon(); if ( BaseClass::Weapon_Switch( pWeapon, viewmodelindex )) { if ( pLastWeapon && Weapon_ShouldSetLast( pLastWeapon, GetActiveWeapon() ) ) { Weapon_SetLast( pLastWeapon->GetLastWeapon() ); } CBaseViewModel *pViewModel = GetViewModel( viewmodelindex ); Assert( pViewModel ); if ( pViewModel ) pViewModel->RemoveEffects( EF_NODRAW ); ResetAutoaim( ); return true; } return false; }