//----------------------------------------------------------------------------- // Purpose: Every second, check total stress and fire an output if we have reached // our threshold. If the stress is relieved below our threshold, fire a different output. //----------------------------------------------------------------------------- void CWeightButton::TriggerThink( void ) { vphysics_objectstress_t vpobj_StressOut; IPhysicsObject* pMyPhysics = VPhysicsGetObject(); if ( !pMyPhysics ) { SetNextThink( TICK_NEVER_THINK ); return; } float fStress = CalculateObjectStress( pMyPhysics, this, &vpobj_StressOut ); // fStress = vpobj_StressOut.receivedStress; if ( fStress > m_fStressToActivate && !m_bHasBeenPressed ) { m_OnPressed.FireOutput( this, this ); m_bHasBeenPressed = true; } else if ( fStress < m_fStressToActivate && m_bHasBeenPressed ) { m_OnReleased.FireOutput( this, this ); m_bHasBeenPressed = false; } // think every tick SetNextThink( gpGlobals->curtime + TICK_INTERVAL ); }
void CPlayerPickupController::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) { if ( ToBasePlayer(pActivator) == m_pPlayer ) { CBaseEntity *pAttached = m_grabController.GetAttached(); // UNDONE: Use vphysics stress to decide to drop objects // UNDONE: Must fix case of forcing objects into the ground you're standing on (causes stress) before that will work if ( !pAttached || useType == USE_OFF || (m_pPlayer->m_nButtons & IN_ATTACK2) || m_grabController.ComputeError() > 12 ) { Shutdown(); return; } //Adrian: Oops, our object became motion disabled, let go! IPhysicsObject *pPhys = pAttached->VPhysicsGetObject(); if ( pPhys && pPhys->IsMoveable() == false ) { Shutdown(); return; } #if STRESS_TEST vphysics_objectstress_t stress; CalculateObjectStress( pPhys, pAttached, &stress ); if ( stress.exertedStress > 250 ) { Shutdown(); return; } #endif #ifndef PLAYER_DISABLE_THROWING // +ATTACK will throw phys objects if ( m_pPlayer->m_nButtons & IN_ATTACK ) { Shutdown( true ); Vector vecLaunch; m_pPlayer->EyeVectors( &vecLaunch ); // JAY: Scale this with mass because some small objects really go flying float massFactor = clamp( pPhys->GetMass(), 0.5, 15 ); massFactor = RemapVal( massFactor, 0.5, 15, 0.5, 4 ); vecLaunch *= player_throwforce.GetFloat() * massFactor; pPhys->ApplyForceCenter( vecLaunch ); AngularImpulse aVel = RandomAngularImpulse( -10, 10 ) * massFactor; pPhys->ApplyTorqueCenter( aVel ); return; } #endif if ( useType == USE_SET ) { // update position m_grabController.UpdateObject( m_pPlayer, 12 ); } } }