void CNPC_HL1Barney::SUB_LVFadeOut( void ) { if( VPhysicsGetObject() ) { if( VPhysicsGetObject()->GetGameFlags() & FVPHYSICS_PLAYER_HELD || GetEFlags() & EFL_IS_BEING_LIFTED_BY_BARNACLE ) { // Try again in a few seconds. SetNextThink( gpGlobals->curtime + 5 ); SetRenderColorA( 255 ); return; } } float dt = gpGlobals->frametime; if ( dt > 0.1f ) { dt = 0.1f; } m_nRenderMode = kRenderTransTexture; int speed = max(3,256*dt); // fade out over 3 seconds SetRenderColorA( UTIL_Approach( 0, m_clrRender->a, speed ) ); NetworkStateChanged(); if ( m_clrRender->a == 0 ) { UTIL_Remove(this); } else { SetNextThink( gpGlobals->curtime ); } }
//----------------------------------------------------------------------------- // Purpose: Do not test against hit boxes, but against the bounding box. // Much cheaper and we don't really need hitboxes for hl2wars. //----------------------------------------------------------------------------- bool CUnitBase::TestHitboxes( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr ) { #if 1 if( unit_cheaphitboxtest.GetBool() == false ) return BaseClass::TestHitboxes( ray, fContentsMask, tr ); CStudioHdr *pStudioHdr = GetModelPtr( ); if (!pStudioHdr) return false; Ray_t ray2 = ray; Vector start = GetAbsOrigin() - ray.m_Start; ray2.Init(start, start+ray.m_Delta); IntersectRayWithBox(ray2, WorldAlignMins(), WorldAlignMaxs(), 0.0f, &tr); if ( tr.DidHit() ) { tr.surface.name = "**studio**"; tr.surface.flags = SURF_HITBOX; tr.surface.surfaceProps = VPhysicsGetObject() ? VPhysicsGetObject()->GetMaterialIndex() : 0; //NDebugOverlay::SweptBox(ray.m_Start, tr.endpos, -Vector(32, 32, 32), Vector(32, 32, 32), GetAbsAngles(), 255, 0, 0, 255, 1.0f); return true; } return false; #else return BaseClass::TestHitboxes( ray, fContentsMask, tr ); #endif // 0 }
//--------------------------------------------------------- //--------------------------------------------------------- void CBounceBomb::CloseHooks() { if( !m_bLockSilently ) { EmitSound( "NPC_CombineMine.CloseHooks" ); } if( VPhysicsGetObject() ) { // It's possible to not have a valid physics object here, since this function doubles as an initialization function. PhysSetGameFlags( VPhysicsGetObject(), FVPHYSICS_CONSTRAINT_STATIC ); } // Only lock silently the first time we call this. m_bLockSilently = false; SetPoseParameter( m_iAllHooks, 0 ); VPhysicsGetObject()->EnableMotion( false ); // Once I lock down, forget how many tries it took. m_iFlipAttempts = 0; #ifdef _XBOX AddEffects( EF_NOSHADOW ); #endif }
void CNPC_Portal_FloorTurret::InactiveThink( void ) { LaserOff(); RopesOff(); // Update our PVS state CheckPVSCondition(); SetNextThink( gpGlobals->curtime + 1.0f ); // Wake up if we're not on our side if ( !OnSide() && VPhysicsGetObject()->GetContactPoint( NULL, NULL ) && m_bEnabled ) { // Never return to life! SetCollisionGroup( COLLISION_GROUP_NONE ); //ReturnToLife(); } else { IPhysicsObject *pTurretPhys = VPhysicsGetObject(); if ( !(pTurretPhys->GetGameFlags() & FVPHYSICS_PLAYER_HELD) && pTurretPhys->IsAsleep() ) SetCollisionGroup( COLLISION_GROUP_DEBRIS_TRIGGER ); else SetCollisionGroup( COLLISION_GROUP_NONE ); } }
bool CPhysBox::CreateVPhysics() { solid_t tmpSolid; PhysModelParseSolid( tmpSolid, this, GetModelIndex() ); if ( m_massScale > 0 ) { float mass = tmpSolid.params.mass * m_massScale; mass = clamp( mass, 0.5, 1e6 ); tmpSolid.params.mass = mass; } PhysSolidOverride( tmpSolid, m_iszOverrideScript ); IPhysicsObject *pPhysics = VPhysicsInitNormal( GetSolid(), GetSolidFlags(), true, &tmpSolid ); if ( m_damageType == 1 ) { PhysSetGameFlags( pPhysics, FVPHYSICS_DMG_SLICE ); } // Wake it up if not asleep if ( !HasSpawnFlags(SF_PHYSBOX_ASLEEP) ) { VPhysicsGetObject()->Wake(); } if ( HasSpawnFlags(SF_PHYSBOX_MOTIONDISABLED) || m_damageToEnableMotion > 0 ) { VPhysicsGetObject()->EnableMotion( false ); } // only send data when physics moves this object NetworkStateManualMode( true ); return true; }
bool CBounceBomb::IsValidLocation() { CBaseEntity *pAvoidObject = NULL; float flAvoidForce = 0.0f; CAI_Hint *pHint; CHintCriteria criteria; criteria.SetHintType( HINT_WORLD_INHIBIT_COMBINE_MINES ); criteria.SetFlag( bits_HINT_NODE_NEAREST ); criteria.AddIncludePosition( GetAbsOrigin(), 12.0f * 15.0f ); pHint = CAI_HintManager::FindHint( GetAbsOrigin(), criteria ); if( pHint ) { pAvoidObject = pHint; flAvoidForce = 120.0f; } else { // Look for other mines that are too close to me. CBaseEntity *pEntity = gEntList.FirstEnt(); Vector vecMyPosition = GetAbsOrigin(); while( pEntity ) { if( pEntity->m_iClassname == m_iClassname && pEntity != this ) { // Don't lock down if I'm near a mine that's already locked down. if( vecMyPosition.DistToSqr(pEntity->GetAbsOrigin()) < MINE_MIN_PROXIMITY_SQR ) { pAvoidObject = pEntity; flAvoidForce = 60.0f; break; } } pEntity = gEntList.NextEnt( pEntity ); } } if( pAvoidObject ) { // Build a force vector to push us away from the inhibitor. // Start by pushing upwards. Vector vecForce = Vector( 0, 0, VPhysicsGetObject()->GetMass() * 200.0f ); // Now add some force in the direction that takes us away from the inhibitor. Vector vecDir = GetAbsOrigin() - pAvoidObject->GetAbsOrigin(); vecDir.z = 0.0f; VectorNormalize( vecDir ); vecForce += vecDir * VPhysicsGetObject()->GetMass() * flAvoidForce; Flip( vecForce, AngularImpulse( 100, 0, 0 ) ); // Tell the code that asked that this position isn't valid. return false; } return true; }
bool C_PhysPropClientside::IsAsleep() { if ( VPhysicsGetObject() ) { return VPhysicsGetObject()->IsAsleep(); } return true; }
float C_PhysPropClientside::GetMass() { if ( VPhysicsGetObject() ) { return VPhysicsGetObject()->GetMass(); } return 0.0f; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPhysicsCannister::CannisterActivate( CBaseEntity *pActivator, const Vector &thrustOffset ) { // already active or spent if ( m_active || !m_thrustTime ) { return; } m_hLauncher = pActivator; Vector thrustDirection = CalcLocalThrust( thrustOffset ); m_onActivate.FireOutput( pActivator, this, 0 ); m_thruster.CalcThrust( m_thrustOrigin, thrustDirection, VPhysicsGetObject() ); m_pController = physenv->CreateMotionController( &m_thruster ); IPhysicsObject *pPhys = VPhysicsGetObject(); m_pController->AttachObject( pPhys, true ); // Make sure the object is simulated pPhys->Wake(); m_active = true; m_activateTime = gpGlobals->curtime; SetNextThink( gpGlobals->curtime + m_thrustTime ); SetThink( &CPhysicsCannister::BeginShutdownThink ); QAngle angles; VectorAngles( -thrustDirection, angles ); m_pJet = dynamic_cast<CSteamJet *>( CBaseEntity::Create( "env_steam", m_thrustOrigin, angles, this ) ); m_pJet->SetParent( this ); float extra = m_thruster.m_thrust * (1/5000.f); extra = clamp( extra, 0, 1 ); m_pJet->m_SpreadSpeed = 15 * m_thruster.m_thrust * 0.001; m_pJet->m_Speed = 128 + 100 * extra; m_pJet->m_StartSize = 10; m_pJet->m_EndSize = 25; m_pJet->m_Rate = 52 + (int)extra*20; m_pJet->m_JetLength = 64; m_pJet->m_clrRender = m_clrRender; m_pJet->Use( this, this, USE_ON, 1 ); if ( m_gasSound != NULL_STRING ) { CPASAttenuationFilter filter( this ); EmitSound_t ep; ep.m_nChannel = CHAN_ITEM; ep.m_pSoundName = STRING(m_gasSound); ep.m_flVolume = 1.0f; ep.m_SoundLevel = SNDLVL_NORM; EmitSound( filter, entindex(), ep ); } }
//----------------------------------------------------------------------------- // Purpose: If we are shot after being stuck to the world, move a bit //----------------------------------------------------------------------------- int CTFGrenadePipebombProjectile::OnTakeDamage( const CTakeDamageInfo &info ) { if ( !info.GetAttacker() ) { Assert( !info.GetAttacker() ); return 0; } bool bSameTeam = ( info.GetAttacker()->GetTeamNumber() == GetTeamNumber() ); if ( m_bTouched && ( info.GetDamageType() & (DMG_BULLET|DMG_BUCKSHOT|DMG_BLAST) ) && bSameTeam == false ) { Vector vecForce = info.GetDamageForce(); if ( info.GetDamageType() & DMG_BULLET ) { vecForce *= tf_grenade_forcefrom_bullet.GetFloat(); } else if ( info.GetDamageType() & DMG_BUCKSHOT ) { vecForce *= tf_grenade_forcefrom_buckshot.GetFloat(); } else if ( info.GetDamageType() & DMG_BLAST ) { vecForce *= tf_grenade_forcefrom_blast.GetFloat(); } // If the force is sufficient, detach & move the pipebomb float flForce = tf_pipebomb_force_to_move.GetFloat(); if ( vecForce.LengthSqr() > (flForce*flForce) ) { if ( VPhysicsGetObject() ) { VPhysicsGetObject()->EnableMotion( true ); } CTakeDamageInfo newInfo = info; newInfo.SetDamageForce( vecForce ); VPhysicsTakeDamage( newInfo ); // The pipebomb will re-stick to the ground after this time expires m_flMinSleepTime = gpGlobals->curtime + tf_grenade_force_sleeptime.GetFloat(); m_bTouched = false; // It has moved the data is no longer valid. m_bUseImpactNormal = false; m_vecImpactNormal.Init(); return 1; } } return 0; }
//--------------------------------------------------------- //--------------------------------------------------------- void CBounceBomb::OnRestore() { BaseClass::OnRestore(); if ( gpGlobals->eLoadType == MapLoad_Transition && !m_hSprite && m_LastSpriteColor.GetRawColor() != 0 ) { UpdateLight( true, m_LastSpriteColor.r(), m_LastSpriteColor.g(), m_LastSpriteColor.b(), m_LastSpriteColor.a() ); } if( VPhysicsGetObject() ) { VPhysicsGetObject()->Wake(); } }
void C_BasePropDoor::OnDataChanged( DataUpdateType_t type ) { BaseClass::OnDataChanged( type ); if ( type == DATA_UPDATE_CREATED ) { SetSolid(SOLID_VPHYSICS); VPhysicsInitShadow( false, false ); } else if ( VPhysicsGetObject() ) { VPhysicsGetObject()->UpdateShadow( GetAbsOrigin(), GetAbsAngles(), false, TICK_INTERVAL ); } }
//--------------------------------------------------------- // Bouncbomb flips to try to right itself, try to get off // of and object that it's not allowed to clamp to, or // to get away from a hint node that inhibits placement // of mines. //--------------------------------------------------------- void CBounceBomb::Flip( const Vector &vecForce, const AngularImpulse &torque ) { if( m_iFlipAttempts > BOUNCEBOMB_MAX_FLIPS ) { // Not allowed to try anymore. SetThink(NULL); return; } EmitSound( "NPC_CombineMine.FlipOver" ); VPhysicsGetObject()->ApplyForceCenter( vecForce ); VPhysicsGetObject()->ApplyTorqueCenter( torque ); m_iFlipAttempts++; }
bool CNPC_Crow::BecomeRagdollOnClient( const Vector &force ) { Vector newForce = force; if( VPhysicsGetObject() ) { float flMass = VPhysicsGetObject()->GetMass(); float speed = VectorNormalize( newForce ); speed = min( speed, (CROW_RAGDOLL_SPEED_LIMIT * flMass) ); newForce *= speed; } return BaseClass::BecomeRagdollOnClient( newForce ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CObjectSiegePlatform::SetObjectCollisionBox( void ) { if ( VPhysicsGetObject() ) { Vector absmins, absmaxs; physcollision->CollideGetAABB( absmins, absmaxs, VPhysicsGetObject()->GetCollide(), GetAbsOrigin(), GetAbsAngles() ); SetAbsMins( absmins ); SetAbsMaxs( absmaxs ); return; } else { BaseClass::SetObjectCollisionBox(); } }
void C_HL2MPRagdoll::ImpactTrace( trace_t *pTrace, int iDamageType, char *pCustomImpactName ) { IPhysicsObject *pPhysicsObject = VPhysicsGetObject(); if( !pPhysicsObject ) return; Vector dir = pTrace->endpos - pTrace->startpos; if ( iDamageType == DMG_BLAST ) { dir *= 4000; // adjust impact strenght // apply force at object mass center pPhysicsObject->ApplyForceCenter( dir ); } else { Vector hitpos; VectorMA( pTrace->startpos, pTrace->fraction, dir, hitpos ); VectorNormalize( dir ); dir *= 4000; // adjust impact strenght // apply force where we hit it pPhysicsObject->ApplyForceOffset( dir, hitpos ); // Blood spray! // FX_CS_BloodSpray( hitpos, dir, 10 ); } m_pRagdoll->ResetRagdollSleepAfterTime(); }
void CPhysicsCannister::Spawn( void ) { Precache(); SetModel( STRING(GetModelName()) ); SetBloodColor( DONT_BLEED ); AddSolidFlags( FSOLID_CUSTOMRAYTEST ); m_takedamage = DAMAGE_YES; SetNextThink( TICK_NEVER_THINK ); if ( m_iHealth <= 0 ) m_iHealth = 25; m_flAnimTime = gpGlobals->curtime; m_flPlaybackRate = 0.0; SetCycle( 0 ); m_bFired = false; // not thrusting m_active = false; CreateVPhysics(); if ( !VPhysicsGetObject() ) { // must have a physics object or code will crash later UTIL_Remove(this); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CItem::Spawn( void ) { if ( g_pGameRules->IsAllowedToSpawn( this ) == false ) { UTIL_Remove( this ); return; } SetMoveType( MOVETYPE_FLYGRAVITY ); SetSolid( SOLID_BBOX ); SetBlocksLOS( false ); AddEFlags( EFL_NO_ROTORWASH_PUSH ); if( IsX360() ) { AddEffects( EF_ITEM_BLINK ); } // This will make them not collide with the player, but will collide // against other items + weapons SetCollisionGroup( COLLISION_GROUP_WEAPON ); CollisionProp()->UseTriggerBounds( true, ITEM_PICKUP_BOX_BLOAT ); SetTouch(&CItem::ItemTouch); if ( CreateItemVPhysicsObject() == false ) return; m_takedamage = DAMAGE_EVENTS_ONLY; #if !defined( CLIENT_DLL ) // Constrained start? if ( HasSpawnFlags( SF_ITEM_START_CONSTRAINED ) ) { //Constrain the weapon in place IPhysicsObject *pReferenceObject, *pAttachedObject; pReferenceObject = g_PhysWorldObject; pAttachedObject = VPhysicsGetObject(); if ( pReferenceObject && pAttachedObject ) { constraint_fixedparams_t fixed; fixed.Defaults(); fixed.InitWithCurrentObjectState( pReferenceObject, pAttachedObject ); fixed.constraint.forceLimit = lbs2kg( 10000 ); fixed.constraint.torqueLimit = lbs2kg( 10000 ); m_pConstraint = physenv->CreateFixedConstraint( pReferenceObject, pAttachedObject, NULL, fixed ); m_pConstraint->SetGameData( (void *) this ); } } #endif //CLIENT_DLL #if defined( HL2MP ) SetThink( &CItem::FallThink ); SetNextThink( gpGlobals->curtime + 0.1f ); #endif }
//----------------------------------------------------------------------------- // Purpose: Items that have just spawned run this think to catch them when // they hit the ground. Once we're sure that the object is grounded, // we change its solid type to trigger and set it in a large box that // helps the player get it. //----------------------------------------------------------------------------- void CItem::FallThink ( void ) { SetNextThink( gpGlobals->curtime + 0.1f ); bool shouldMaterialize = false; IPhysicsObject *pPhysics = VPhysicsGetObject(); if ( pPhysics ) { shouldMaterialize = pPhysics->IsAsleep(); } else { shouldMaterialize = (GetFlags() & FL_ONGROUND) ? true : false; } if ( shouldMaterialize ) { SetThink ( NULL ); m_vOriginalSpawnOrigin = GetAbsOrigin(); m_vOriginalSpawnAngles = GetAbsAngles(); HL2MPRules()->AddLevelDesignerPlacedObject( this ); } }
//--------------------------------------------------------- //--------------------------------------------------------- void CRebelZombie::SetZombieModel( void ) { //if ( m_iZombieSex == 1 ) // Male //{ SetModel( "models/zombie/classic.mdl" ); /*} else // Female { SetModel( "models/zombie/classic_female.mdl" ); }*/ SetHullType( HULL_HUMAN ); m_nSkin = m_iRebelZombieSkin; SetBodygroup( ZOMBIE_BODYGROUP_HEADCRAB, !m_fIsHeadless ); SetHullSizeNormal( true ); SetDefaultEyeOffset(); SetActivity( ACT_IDLE ); // hull changed size, notify vphysics // UNDONE: Solve this generally, systematically so other // NPCs can change size if ( VPhysicsGetObject() ) { SetupVPhysicsHull(); } }
//----------------------------------------------------------------------------- // Purpose: Items that have just spawned run this think to catch them when // they hit the ground. Once we're sure that the object is grounded, // we change its solid type to trigger and set it in a large box that // helps the player get it. //----------------------------------------------------------------------------- void CBaseCombatWeapon::FallThink ( void ) { SetNextThink( gpGlobals->curtime + 0.1f ); bool shouldMaterialize = false; IPhysicsObject *pPhysics = VPhysicsGetObject(); if ( pPhysics ) { shouldMaterialize = pPhysics->IsAsleep(); } else { shouldMaterialize = (GetFlags() & FL_ONGROUND) ? true : false; } if ( shouldMaterialize ) { // clatter if we have an owner (i.e., dropped by someone) // don't clatter if the gun is waiting to respawn (if it's waiting, it is invisible!) if ( GetOwnerEntity() ) { EmitSound( "BaseCombatWeapon.WeaponDrop" ); } Materialize(); } }
//----------------------------------------------------------------------------- // Purpose: // // NOTE: This function is still heavy with common code (found at the bottom). // we should consider moving some into the base class! (sjb) //----------------------------------------------------------------------------- void CNPC_Monster::SetZombieModel( void ) { Hull_t lastHull = GetHullType(); SetModel( cModel.ToCStr() ); if (m_fIsTorso) SetHullType(HULL_TINY); else SetHullType(HULL_HUMAN); SetHullSizeNormal( true ); SetDefaultEyeOffset(); SetActivity( ACT_IDLE ); m_nSkin = m_iSkin; if ( lastHull != GetHullType() ) { if ( VPhysicsGetObject() ) { SetupVPhysicsHull(); } } CollisionProp()->SetSurroundingBoundsType( USE_OBB_COLLISION_BOUNDS ); }
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- void CWeaponStriderBuster::OnFlechetteAttach( Vector &vecFlechetteVelocity ) { if ( m_bLaunched ) { Vector vecForce = vecFlechetteVelocity; VectorNormalize( vecForce ); vecForce *= 1000; vecForce.z = -5000; VPhysicsGetObject()->ApplyForceCenter( vecForce ); } if ( !GetParent() || !GetParent()->ClassMatches( g_iszVehicle ) ) { if ( !m_bNoseDiving ) { //m_hGlowTrail->StopParticleSystem(); StopParticleEffects( this ); if( m_iBusterFlags & STRIDERBUSTER_FLAG_KNOCKED_OFF_STRIDER ) { DispatchParticleEffect( "striderbuster_shotdown_trail", PATTACH_ABSORIGIN_FOLLOW, this ); } else { DispatchParticleEffect( "striderbuster_flechette_attached", PATTACH_ABSORIGIN_FOLLOW, this ); } } m_bNoseDiving = true; } m_nAttachedFlechettes++; }
//--------------------------------------------------------- //--------------------------------------------------------- void CZombie::SetZombieModel( void ) { Hull_t lastHull = GetHullType(); if ( m_fIsTorso ) { SetModel( "models/zombie/classic_torso.mdl" ); SetHullType( HULL_TINY ); } else { SetModel( "models/zombie/classic.mdl" ); SetHullType( HULL_HUMAN ); } SetBodygroup( ZOMBIE_BODYGROUP_HEADCRAB, !m_fIsHeadless ); SetHullSizeNormal( true ); SetDefaultEyeOffset(); SetActivity( ACT_IDLE ); // hull changed size, notify vphysics // UNDONE: Solve this generally, systematically so other // NPCs can change size if ( lastHull != GetHullType() ) { if ( VPhysicsGetObject() ) { SetupVPhysicsHull(); } } }
void CTripmineGrenade::AttachToEntity(CBaseEntity *pOther) { if (!pOther) return; if ( !VPhysicsGetObject() ) return; m_bAttached = true; m_hAttachEntity = pOther; SetMoveType ( MOVETYPE_NONE ); if (pOther->GetSolid() == SOLID_VPHYSICS && pOther->VPhysicsGetObject() != NULL ) { SetSolid(SOLID_BBOX); //Tony; switch to bbox solid instead of vphysics, because we've made the physics object non-solid MakeConstraint(pOther); SetMoveType ( MOVETYPE_VPHYSICS ); // use vphysics while constrained!! } //if it isnt vphysics or bsp, use SetParent to follow it. else if (pOther->GetSolid() != SOLID_BSP) { SetSolid(SOLID_BBOX); //Tony; switch to bbox solid instead of vphysics, because we've made the physics object non-solid SetParent( m_hAttachEntity.Get() ); } }
bool CTripmineGrenade::MakeConstraint( CBaseEntity *pObject ) { IPhysicsObject *cMinePhysics = VPhysicsGetObject(); Assert( cMinePhysics ); IPhysicsObject *pAttached = pObject->VPhysicsGetObject(); if ( !cMinePhysics || !pAttached ) return false; // constraining to the world means object 1 is fixed if ( pAttached == g_PhysWorldObject ) PhysSetGameFlags( cMinePhysics, FVPHYSICS_CONSTRAINT_STATIC ); IPhysicsConstraintGroup *pGroup = NULL; constraint_fixedparams_t fixed; fixed.Defaults(); fixed.InitWithCurrentObjectState( cMinePhysics, pAttached ); fixed.constraint.Defaults(); m_pConstraint = physenv->CreateFixedConstraint( cMinePhysics, pAttached, pGroup, fixed ); if (!m_pConstraint) return false; m_pConstraint->SetGameData( (void *)this ); return true; }
void CZombie::SetZombieModel( void ) { Hull_t lastHull = GetHullType(); if(m_iZombieType == ZOMBIE_BISOU) SetModel( "models/zombie/Bisounours.mdl" ); else SetModel( "models/zombie/classic.mdl" ); SetHullType( HULL_HUMAN ); //Commenté en attendant de trouver à quoi ça sert //SetBodygroup( ZOMBIE_BODYGROUP_HEADCRAB, !m_fIsHeadless ); SetHullSizeNormal( true ); SetDefaultEyeOffset(); SetActivity( ACT_IDLE ); // hull changed size, notify vphysics // UNDONE: Solve this generally, systematically so other // NPCs can change size if ( lastHull != GetHullType() ) if ( VPhysicsGetObject() ) SetupVPhysicsHull(); }
int CNPC_BaseTurret::OnTakeDamage( const CTakeDamageInfo &info ) { int retVal = 0; if (!m_takedamage) return 0; switch( m_lifeState ) { case LIFE_ALIVE: retVal = OnTakeDamage_Alive( info ); if ( m_iHealth <= 0 ) { IPhysicsObject *pPhysics = VPhysicsGetObject(); if ( pPhysics ) { pPhysics->EnableCollisions( false ); } Event_Killed( info ); Event_Dying(); } return retVal; break; case LIFE_DYING: return OnTakeDamage_Dying( info ); default: case LIFE_DEAD: return OnTakeDamage_Dead( info ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CGETKnife::Spawn( void ) { Precache(); BaseClass::Spawn(); SetModel( "models/weapons/knife/w_tknife.mdl" ); SetSize( -Vector(8,8,8), Vector(8,8,8) ); // Init our physics definition VPhysicsInitNormal( SOLID_VPHYSICS, GetSolidFlags() | FSOLID_TRIGGER, false ); SetMoveType( MOVETYPE_VPHYSICS ); SetCollisionGroup( COLLISION_GROUP_GRENADE ); // No Air-Drag, lower gravity VPhysicsGetObject()->EnableDrag( false ); SetGravity( UTIL_ScaleForGravity( 540.0f ) ); m_bInAir = true; m_takedamage = DAMAGE_NO; AddSolidFlags( FSOLID_NOT_STANDABLE ); m_flStopFlyingTime = gpGlobals->curtime + 4.5f; // const CBaseEntity *host = te->GetSuppressHost(); // te->SetSuppressHost( NULL ); // DispatchParticleEffect( "tracer_tknife", PATTACH_POINT_FOLLOW, this, "tip" ); // te->SetSuppressHost( (CBaseEntity*)host ); SetTouch( &CGETKnife::DamageTouch ); SetThink( &CGETKnife::SoundThink ); SetNextThink( gpGlobals->curtime ); }
//----------------------------------------------------------------------------- // 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 ); }