//-----------------------------------------------------------------------------
// Purpose: Called every frame when the door is blocked while opening or closing.
// Input  : pOther - The blocking entity.
//-----------------------------------------------------------------------------
void CBaseDoor::Blocked( CBaseEntity *pOther )
{
	// Hurt the blocker a little.
	if ( m_flBlockDamage )
	{
		// if the door is marked "force closed" or it has a negative wait, then there's nothing to do but 
		// push/damage the object.
		// If block damage is set, but this object is a physics prop that can't be damaged, just
		// give up and disable collisions
		if ( (m_bForceClosed || m_flWait < 0) && pOther->GetMoveType() == MOVETYPE_VPHYSICS && 
		   (pOther->m_takedamage == DAMAGE_NO || pOther->m_takedamage == DAMAGE_EVENTS_ONLY) )
		{
			EntityPhysics_CreateSolver( this, pOther, true, 4.0f );
		}
		else
		{
			pOther->TakeDamage( CTakeDamageInfo( this, this, m_flBlockDamage, DMG_CRUSH ) );
		}
	}

	// If we're set to force ourselves closed, keep going
	if ( m_bForceClosed )
		return;

	// if a door has a negative wait, it would never come back if blocked,
	// so let it just squash the object to death real fast
	if (m_flWait >= 0)
	{
		if (m_toggle_state == TS_GOING_DOWN)
		{
			DoorGoUp();
		}
		else
		{
			DoorGoDown();
		}
	}

	// Block all door pieces with the same targetname here.
	if ( GetEntityName() != NULL_STRING )
	{
		CBaseDoor *pDoorList[64];
		int doorCount = GetDoorMovementGroup( pDoorList, ARRAYSIZE(pDoorList) );

		for ( int i = 0; i < doorCount; i++ )
		{
			CBaseDoor *pDoor = pDoorList[i];

			if ( pDoor->m_flWait >= 0)
			{
				if (m_bDoorGroup && pDoor->m_vecMoveDir == m_vecMoveDir && pDoor->GetAbsVelocity() == GetAbsVelocity() && pDoor->GetLocalAngularVelocity() == GetLocalAngularVelocity())
				{
					pDoor->m_nSimulationTick = m_nSimulationTick;	// don't run simulation this frame if you haven't run yet

					// this is the most hacked, evil, bastardized thing I've ever seen. kjb
					if ( !pDoor->IsRotatingDoor() )
					{// set origin to realign normal doors
						pDoor->SetLocalOrigin( GetLocalOrigin() );
						pDoor->SetAbsVelocity( vec3_origin );// stop!

					}
					else
					{// set angles to realign rotating doors
						pDoor->SetLocalAngles( GetLocalAngles() );
						pDoor->SetLocalAngularVelocity( vec3_angle );
					}
				}
			
				if ( pDoor->m_toggle_state == TS_GOING_DOWN)
					pDoor->DoorGoUp();
				else
					pDoor->DoorGoDown();
			}
		}
	}
}
示例#2
0
文件: doors.cpp 项目: XashDev/XashXT
void CBaseDoor::Blocked( CBaseEntity *pOther )
{
	// hurt the blocker a little.
	if( pev->dmg ) pOther->TakeDamage( pev, pev, pev->dmg, DMG_CRUSH );

	// if a door has a negative wait, it would never come back if blocked,
	// so let it just squash the object to death real fast
	if( m_flWait >= 0 )
	{
		if( !FBitSet( pev->spawnflags, SF_DOOR_SILENT ))
			STOP_SOUND( edict(), CHAN_STATIC, STRING( pev->noise1 ));

		if( m_iState == STATE_TURN_OFF )
		{
			DoorGoUp();
		}
		else
		{
			DoorGoDown();
		}
	}

	// block all door pieces with the same targetname here.
	if( !FStringNull( pev->targetname ))
	{
		CBaseDoor *pDoorList[64];
		int doorCount = GetDoorMovementGroup( pDoorList, ARRAYSIZE( pDoorList ));

		for( int i = 0; i < doorCount; i++ )
		{
			CBaseDoor *pDoor = pDoorList[i];

			if( pDoor->m_flWait >= 0)
			{
				if( m_bDoorGroup && pDoor->pev->movedir == pev->movedir && pDoor->GetAbsVelocity() == GetAbsVelocity() && pDoor->GetLocalAvelocity() == GetLocalAvelocity( ))
				{
					pDoor->m_iPhysicsFrame = g_ulFrameCount; // don't run physics this frame if you haven't run yet

					// this is the most hacked, evil, bastardized thing I've ever seen. kjb
					if( !pDoor->IsRotatingDoor( ))
					{
						// set origin to realign normal doors
						pDoor->SetLocalOrigin( GetLocalOrigin( ));
						pDoor->SetAbsVelocity( g_vecZero ); // stop!

					}
					else
					{
						// set angles to realign rotating doors
						pDoor->SetLocalAngles( GetLocalAngles( ));
						pDoor->SetLocalAvelocity( g_vecZero );
					}
				}
			
				if( pDoor->m_iState == STATE_TURN_OFF )
					pDoor->DoorGoUp();
				else pDoor->DoorGoDown();
			}
		}
	}
}
示例#3
0
void CBaseDoor::Blocked( CBaseEntity *pOther )
{
	CBaseDoor	*pDoor = NULL;


	// Hurt the blocker a little.
	if( GetDamage() )
		pOther->TakeDamage( this, this, GetDamage(), DMG_CRUSH );

	// if a door has a negative wait, it would never come back if blocked,
	// so let it just squash the object to death real fast

	if( m_flWait >= 0 )
	{
		if( m_toggle_state == TS_GOING_DOWN )
		{
			DoorGoUp();
		}
		else
		{
			DoorGoDown();
		}
	}

	// Block all door pieces with the same targetname here.
	if( HasTargetname() )
	{
		CBaseEntity* pTarget = nullptr;
		while( ( pTarget = UTIL_FindEntityByTargetname( pTarget, GetTargetname() ) ) != nullptr )
		{
			if( pTarget != this )
			{
				if( pTarget->ClassnameIs( "func_door" ) || pTarget->ClassnameIs( "func_door_rotating" ) )
				{
					pDoor = static_cast<CBaseDoor*>( pTarget );

					if( pDoor->m_flWait >= 0 )
					{
						//TODO: comparing avel with vel is probably wrong - Solokiller
						if( pDoor->GetAbsVelocity() == GetAbsVelocity() && pDoor->GetAngularVelocity() == GetAbsVelocity() )
						{
							// this is the most hacked, evil, bastardized thing I've ever seen. kjb
							if( pTarget->ClassnameIs( "func_door" ) )
							{// set origin to realign normal doors
								pDoor->SetAbsOrigin( GetAbsOrigin() );
								pDoor->SetAbsVelocity( g_vecZero );// stop!
							}
							else
							{// set angles to realign rotating doors
								pDoor->SetAbsAngles( GetAbsAngles() );
								pDoor->SetAngularVelocity( g_vecZero );
							}
						}

						if( !GetSpawnFlags().Any( SF_DOOR_SILENT ) )
							STOP_SOUND( this, CHAN_STATIC, ( char* ) STRING( pev->noiseMoving ) );

						if( pDoor->m_toggle_state == TS_GOING_DOWN )
							pDoor->DoorGoUp();
						else
							pDoor->DoorGoDown();
					}
				}
			}
		}
	}
}