// функция отрывания и выбрасывания головы
// Cremator's head is separated from the body and dropped on death. 
// Input: head's velocity.
// TODO: make it part of brickbat ammo list.
void CNPC_Cremator::DropHead( int iVelocity ) 
{
	CPhysicsProp *pGib = assert_cast<CPhysicsProp*>(CreateEntityByName( "prop_physics" ));
	pGib->SetAbsOrigin( GetAbsOrigin() );
	pGib->SetAbsAngles( GetAbsAngles() );
	pGib->SetAbsVelocity( GetAbsVelocity() );
	pGib->SetModel( GetHeadpropModel() );
	pGib->Spawn();
	pGib->SetMoveType( MOVETYPE_VPHYSICS );

	Vector vecVelocity;
	pGib->GetMassCenter( &vecVelocity );
	vecVelocity -= WorldSpaceCenter();
	vecVelocity.z = fabs(vecVelocity.z);
	VectorNormalize( vecVelocity );

	float flRandomVel = random->RandomFloat( 35, 75 );
	vecVelocity *= (iVelocity * flRandomVel) / 15;
	vecVelocity.z += 100.0f;
	AngularImpulse angImpulse = RandomAngularImpulse( -500, 500 );
			
	IPhysicsObject *pObj = pGib->VPhysicsGetObject();
	if ( pObj != NULL )
	{
		pObj->AddVelocity( &vecVelocity, &angImpulse );
	}
	pGib->SetCollisionGroup( COLLISION_GROUP_INTERACTIVE );
}
Exemplo n.º 2
0
//-----------------------------------------------------------------------------
// Create a corpse 
//-----------------------------------------------------------------------------
void CPropAPC::CreateCorpse( )
{
	m_lifeState = LIFE_DEAD;

	for ( int i = 0; i < APC_MAX_GIBS; ++i )
	{
		CPhysicsProp *pGib = assert_cast<CPhysicsProp*>(CreateEntityByName( "prop_physics" ));
		pGib->SetAbsOrigin( GetAbsOrigin() );
		pGib->SetAbsAngles( GetAbsAngles() );
		pGib->SetAbsVelocity( GetAbsVelocity() );
		pGib->SetModel( s_pGibModelName[i] );
		pGib->Spawn();
		pGib->SetMoveType( MOVETYPE_VPHYSICS );

		float flMass = pGib->GetMass();
		if ( flMass < 200 )
		{
			Vector vecVelocity;
			pGib->GetMassCenter( &vecVelocity );
			vecVelocity -= WorldSpaceCenter();
			vecVelocity.z = fabs(vecVelocity.z);
			VectorNormalize( vecVelocity );

			// Apply a force that would make a 100kg mass travel 150 - 300 m/s
			float flRandomVel = random->RandomFloat( 150, 300 );
			vecVelocity *= (100 * flRandomVel) / flMass;
			vecVelocity.z += 100.0f;
			AngularImpulse angImpulse = RandomAngularImpulse( -500, 500 );
			
			IPhysicsObject *pObj = pGib->VPhysicsGetObject();
			if ( pObj != NULL )
			{
				pObj->AddVelocity( &vecVelocity, &angImpulse );
			}
			pGib->SetCollisionGroup( COLLISION_GROUP_DEBRIS );
		}	
		if( hl2_episodic.GetBool() )
		{
			// EP1 perf hit
			pGib->Ignite( 6, false );
		}
		else
		{
			pGib->Ignite( 60, false );
		}
	}

	AddSolidFlags( FSOLID_NOT_SOLID );
	AddEffects( EF_NODRAW );
	UTIL_Remove( this );
}
void QUA_helicopter::CreateCorpse( )
{
	m_lifeState = LIFE_DEAD;

	for ( int i = 0; i < HELICOPTER_MAX_GIBS; ++i )
	{
		CPhysicsProp *pGib = assert_cast<CPhysicsProp*>(CreateEntityByName( "prop_physics_multiplayer" ));
		pGib->SetAbsOrigin( GetAbsOrigin() );
		pGib->SetAbsAngles( GetAbsAngles() );
		pGib->SetAbsVelocity( GetAbsVelocity() );
		pGib->SetModel( s_pGibModelName[i] );
		pGib->Spawn();
		pGib->SetMoveType( MOVETYPE_VPHYSICS );

		float flMass = pGib->GetMass();
		/*if ( flMass < 200 )
		{*/
			Vector vecVelocity;
			pGib->GetMassCenter( &vecVelocity );
			vecVelocity -= WorldSpaceCenter();
			vecVelocity.z = fabs(vecVelocity.z);
			VectorNormalize( vecVelocity );

			// Apply a force that would make a 100kg mass travel 150 - 300 m/s
			float flRandomVel = random->RandomFloat( 150, 300 );
			vecVelocity *= (100 * flRandomVel) / flMass;
			vecVelocity.z += 100.0f;
			AngularImpulse angImpulse = RandomAngularImpulse( -500, 500 );
			
			IPhysicsObject *pObj = pGib->VPhysicsGetObject();
			if ( pObj != NULL )
			{
				pObj->AddVelocity( &vecVelocity, &angImpulse );
			}
			pGib->SetCollisionGroup( COLLISION_GROUP_DEBRIS );
		/*}*/
		pGib->Ignite( 60, false );
		pGib->Dissolve( NULL, gpGlobals->curtime, false, ENTITY_DISSOLVE_NORMAL );
	}

	AddSolidFlags( FSOLID_NOT_SOLID );
	AddEffects( EF_NODRAW );
	UTIL_RemoveImmediate( this );
}
Exemplo n.º 4
0
    void UpdateVPhysicsObjects()
    {
        int nPhysicsObjectInterval = sv_benchmark_numticks.GetInt() / s_nBenchmarkPhysicsObjects;

        int nNextSpawnTick = m_nLastPhysicsObjectTick + nPhysicsObjectInterval;
        if ( GetTickOffset() >= nNextSpawnTick )
        {
            m_nLastPhysicsObjectTick = nNextSpawnTick;

            if ( m_PhysicsObjects.Count() < s_nBenchmarkPhysicsObjects )
            {
                // Find a bot to spawn it from.
                CUtlVector<CBasePlayer*> curPlayers;
                for ( int i = 1; i <= gpGlobals->maxClients; i++ )
                {
                    CBasePlayer *pPlayer = UTIL_PlayerByIndex( i );
                    if ( pPlayer && (pPlayer->GetFlags() & FL_FAKECLIENT) )
                    {
                        curPlayers.AddToTail( pPlayer );
                    }
                }

                if ( curPlayers.Count() > 0 && m_PhysicsModelNames.Count() > 0 )
                {
                    int iModelName = this->RandomInt( 0, m_PhysicsModelNames.Count() - 1 );
                    const char *pModelName = m_PhysicsModelNames[iModelName];

                    int iPlayer = this->RandomInt( 0, curPlayers.Count() - 1 );

                    Vector vSpawnPos = curPlayers[iPlayer]->EyePosition() + Vector( 0, 0, 50 );

                    // We'll try 15 locations around the player to spawn this thing.
                    for ( int i=0; i < 15; i++ )
                    {
                        Vector vOffset( this->RandomFloat( -2000, 2000 ), this->RandomFloat( -2000, 2000 ), 0 );
                        CPhysicsProp *pProp = CreatePhysicsProp( pModelName, vSpawnPos, vSpawnPos+vOffset, curPlayers[iPlayer], false, "prop_physics_multiplayer" );
                        if ( pProp )
                        {
                            m_PhysicsObjects.AddToTail( pProp );
                            pProp->SetAbsVelocity( Vector( this->RandomFloat(-500,500), this->RandomFloat(-500,500), this->RandomFloat(-500,500) ) );
                            break;
                        }
                    }
                }
            }
        }

        // Give them all a boost periodically.
        int nPhysicsForceInterval = sv_benchmark_numticks.GetInt() / 20;

        int nNextForceTick = m_nLastPhysicsForceTick + nPhysicsForceInterval;
        if ( GetTickOffset() >= nNextForceTick )
        {
            m_nLastPhysicsForceTick = nNextForceTick;

            for ( int i=0; i < m_PhysicsObjects.Count(); i++ )
            {
                CBaseEntity *pEnt = m_PhysicsObjects[i];
                if ( pEnt )
                {
                    IPhysicsObject *pPhysicsObject = pEnt->VPhysicsGetObject();
                    if ( pPhysicsObject )
                    {
                        float flAngImpulse = 300000;
                        float flForce = 500000;
                        AngularImpulse vAngularImpulse( this->RandomFloat(-flAngImpulse,flAngImpulse), this->RandomFloat(-flAngImpulse,flAngImpulse), this->RandomFloat(flAngImpulse,flAngImpulse) );
                        pPhysicsObject->ApplyForceCenter( Vector( this->RandomFloat(-flForce,flForce), this->RandomFloat(-flForce,flForce), this->RandomFloat(0,flForce) ) );
                    }
                }
            }
        }
    }
//-----------------------------------------------------------------------------
// Create a corpse 
//-----------------------------------------------------------------------------
void CPropAPC2::CreateCorpse( )
{
	m_lifeState = LIFE_DEAD;

	for ( int i = 0; i < APC_MAX_GIBS; ++i )
	{
		CPhysicsProp *pGib = assert_cast<CPhysicsProp*>(CreateEntityByName( "prop_physics_multiplayer" ));
		pGib->SetAbsOrigin( GetAbsOrigin() );
		pGib->SetAbsAngles( GetAbsAngles() );
		pGib->SetAbsVelocity( GetAbsVelocity() );
		pGib->SetModel( s_pGibModelName[i] );
		pGib->Spawn();
		pGib->SetMoveType( MOVETYPE_VPHYSICS );

		float flMass = pGib->GetMass();
		/*if ( flMass < 200 )
		{*/
			Vector vecVelocity;
			pGib->GetMassCenter( &vecVelocity );
			vecVelocity -= WorldSpaceCenter();
			vecVelocity.z = fabs(vecVelocity.z);
			VectorNormalize( vecVelocity );

			// Apply a force that would make a 100kg mass travel 150 - 300 m/s
			float flRandomVel = random->RandomFloat( 150, 300 );
			vecVelocity *= (100 * flRandomVel) / flMass;
			vecVelocity.z += 100.0f;
			AngularImpulse angImpulse = RandomAngularImpulse( -500, 500 );
			
			IPhysicsObject *pObj = pGib->VPhysicsGetObject();
			if ( pObj != NULL )
			{
				pObj->AddVelocity( &vecVelocity, &angImpulse );
			}
			pGib->SetCollisionGroup( COLLISION_GROUP_DEBRIS );
		/*}*/
		//pGib->Ignite( 60, false );
		pGib->Dissolve( NULL, gpGlobals->curtime, false, ENTITY_DISSOLVE_NORMAL );
	}

//

	CPropAPC2 *pAPC = (CPropAPC2 *)CreateEntityByName( "prop_vehicle_apc2" );
		
	if ( pAPC )
	{
		pAPC->InicialSpawn=m_vOriginalSpawnOrigin;
		pAPC->InicialAngle=m_vOriginalSpawnAngles;
		pAPC->m_bSpawn=true;
		pAPC->SetThink( &CPropAPC2::Materialize );
		pAPC->SetContextThink( &CPropAPC2::Materialize, gpGlobals->curtime + 5.0f, "RESPAWNING" );
		pAPC->SetNextThink( gpGlobals->curtime + 5.0f );
	}
	else
	{
		Warning("Respawn failed to create %s!\n", GetClassname() );
	}

//

	AddSolidFlags( FSOLID_NOT_SOLID );
	AddEffects( EF_NODRAW );
	UTIL_Remove( this );
}