示例#1
0
bool Turret::CreateWeapon( )
{
	HWEAPON hWeapon = g_pWeaponDB->GetRecordLink( m_hTurret, WDB_TURRET_rWeapon );
	if( !hWeapon )
		return false;

	const char *pszWeapon = g_pWeaponDB->GetRecordName( hWeapon );

	// Create a weapon at the pivot point...
	CActiveWeapon* pActiveWeapon = m_Arsenal.ActivateWeapon( pszWeapon, "Pivot" );
	if( pActiveWeapon == NULL )
		return false;

	// Make it our current weapon...
	if( !m_Arsenal.ChangeWeapon( pActiveWeapon ))
		return false;

	CWeapon *pWeapon = m_Arsenal.GetCurWeapon( );
	if( !pWeapon )
		return false;
	
	// Give us plenty of ammo..
	m_Arsenal.AddAmmo( pWeapon->GetAmmoRecord(), 10000 );

	HATTACHMENT hAttachment = NULL;
	g_pLTServer->FindAttachment( m_hObject, pWeapon->GetModelObject( ), &hAttachment );

    if( hAttachment )
	{
		// Undo the attachment so the position and rotation can be manually set...
		g_pLTServer->RemoveAttachment( hAttachment );
	}

	return true;
}
示例#2
0
void Turret::CreateSpecialFX( bool bUpdateClients )
{
	CWeapon *pWeapon = m_Arsenal.GetCurWeapon( );

	TURRETCREATESTRUCT csTurret;
	csTurret.m_hTurret = m_hTurret;
	csTurret.m_hOperatingObject = m_hOperatingObject;
	csTurret.m_hTurretWeapon = (pWeapon ? pWeapon->GetModelObject( ) : NULL );
	csTurret.m_bRemoteActivation = false;
	csTurret.m_nDamageState = m_nCurDamageState;	
	
	// Give derived classes a chance at updating the client data...
	PreCreateSpecialFX( csTurret );

	{
		CAutoMessage cMsg;
		cMsg.Writeuint8( SFX_TURRET_ID );
		csTurret.Write( cMsg );
		g_pLTServer->SetObjectSFXMessage( m_hObject, cMsg.Read( ));
	}
	

	if( bUpdateClients )
	{
		CAutoMessage cMsg;
		cMsg.Writeuint8( MID_SFX_MESSAGE );
		cMsg.Writeuint8( SFX_TURRET_ID );
		cMsg.WriteObject( m_hObject );
		cMsg.Writeuint8( kTurretFXMsg_All );
		csTurret.Write( cMsg );
		g_pLTServer->SendToClient( cMsg.Read( ), NULL, MESSAGE_GUARANTEED );
	}
}
示例#3
0
// ----------------------------------------------------------------------- //
//
//	ROUTINE:	GunMount::GetFirePos
//
//	PURPOSE:	Changes visibility on gun.
//
// ----------------------------------------------------------------------- //
void GunMount::SetVisible( bool bVisible )
{
	m_bVisible = bVisible;

	CWeapon* pWeapon = m_Arsenal.GetCurWeapon( );
	if( pWeapon )
	{
		g_pCommonLT->SetObjectFlags( pWeapon->GetModelObject( ), OFT_Flags, m_bVisible ? ( FLAG_VISIBLE | FLAG_FORCECLIENTUPDATE ) : FLAG_FORCECLIENTUPDATE, ( FLAG_VISIBLE | FLAG_FORCECLIENTUPDATE ));
	}
}
示例#4
0
bool GunMount::GetFirePos( LTVector& vPos )
{
	CWeapon* pWeapon = m_Arsenal.GetCurWeapon( );
	if( !pWeapon )
		return false;

	HATTACHMENT hAttachment;
    if( g_pLTServer->FindAttachment(m_hObject, pWeapon->GetModelObject(), &hAttachment) != LT_OK )
	{
		return false;
	}

	HMODELSOCKET hSocket;
    if (g_pModelLT->GetSocket(pWeapon->GetModelObject(), "Flash", hSocket) != LT_OK)
	{
		return false;
	}

	LTTransform transform;
	g_pCommonLT->GetAttachedModelSocketTransform(hAttachment, hSocket, transform);
	vPos = transform.m_vPos;
	
	return true;
}
示例#5
0
bool GunMount::FireWeapon( )
{
	CWeapon* pWeapon = m_Arsenal.GetCurWeapon( );
	if( !pWeapon )
		return false;

	// Get the direction we're firing.
	LTRotation rot;
	g_pLTServer->GetObjectRotation( m_hObject, &rot );
	LTVector vDir = rot.Forward( );

	LTVector vPos;
	if( !GetFirePos( vPos ))
	{
		g_pLTServer->GetObjectPos( m_hObject, &vPos );
	}

	// Tell the weapon to fire.
	WeaponFireInfo weaponFireInfo;
	static uint8 s_nCount = GetRandom( 0, 255 );
	s_nCount++;

	weaponFireInfo.hFiredFrom	= m_hObject;
	weaponFireInfo.hFiringWeapon = pWeapon->GetModelObject( );
	weaponFireInfo.vPath		= vDir;
	weaponFireInfo.vFirePos		= vPos;
	weaponFireInfo.vFlashPos	= vPos;
	weaponFireInfo.nSeed		= (uint8)GetRandom( 2, 255 );
	weaponFireInfo.nPerturbCount	= s_nCount;
	weaponFireInfo.nFireTimestamp = g_pLTServer->GetRealTimeMS( );

	WeaponState eWeaponState = pWeapon->UpdateWeapon( weaponFireInfo, true );
	if( eWeaponState == W_FIRED )
	{
		// Count the round as fired.
		if( m_nRoundsToFire > 0 )
			m_nRoundsToFire--;

	}

	// Keep ammo count up and clip loaded.  The weapon could have refused
	// firing due to weapon fire time limitations, but it still decrements
	// ammo.
	m_Arsenal.AddAmmo( pWeapon->GetAmmoRecord(), 10 );
	pWeapon->ReloadClip( false );

	return true;
}
示例#6
0
// ----------------------------------------------------------------------- //
//
//	ROUTINE:	GunMount::AnimationComplete
//
//	PURPOSE:	Starts the prefiring state.
//
// ----------------------------------------------------------------------- //
bool GunMount::IsAnimationComplete( )
{
	CWeapon* pWeapon = m_Arsenal.GetCurWeapon( );
	if( !pWeapon )
	{
		ASSERT( !"GunMount::IsAnimationComplete:  Invalid weapon." );
		return true;
	}

	uint32 dwFlags = 0;
	if( g_pModelLT->GetPlaybackState( pWeapon->GetModelObject( ), MAIN_TRACKER, dwFlags ) != LT_OK )
		return true;

	if( dwFlags & MS_PLAYDONE )
		return true;

	return false;
}
示例#7
0
void Turret::Update( )
{
	if( m_hOperatingObject && IsPlayer( m_hOperatingObject ))
	{
		if( m_swtDestroyedDeactivationDelay.IsStarted( ) && m_swtDestroyedDeactivationDelay.IsTimedOut( ))
		{
			Deactivate( );

			// Remove the turret weapon since the turret is getting removed as well...
			m_Arsenal.RemoveAllActiveWeapons( );

			// Remove ourselves now that we're dead...
			g_pLTServer->RemoveObject( m_hObject );

			return;
		}
		
		CPlayerObj *pPlayer = dynamic_cast<CPlayerObj*>(g_pLTServer->HandleToObject( m_hOperatingObject ));
		if( !pPlayer || !pPlayer->IsAlive( ))
		{
			Deactivate( );
			return;
		}
		
		CWeapon *pPlayerWeapon = pPlayer->GetArsenal( )->GetCurWeapon( );
		if( pPlayerWeapon )
			pPlayerWeapon->HideWeapon( true );

		LTRigidTransform tView;
		pPlayer->GetTrueViewTransform( tView );

		CWeapon *pTurretWeapon = m_Arsenal.GetCurWeapon( );
		if( pTurretWeapon )
		{
			HMODELSOCKET hPivot = INVALID_MODEL_SOCKET;
			g_pModelLT->GetSocket( m_hObject, "Pivot", hPivot );

			LTTransform tPivot;
			g_pModelLT->GetSocketTransform( m_hObject, hPivot, tPivot, true );

			HOBJECT hWeapon = pTurretWeapon->GetModelObject( );

			LTRigidTransform rtCur;
			g_pLTServer->GetObjectTransform( hWeapon, &rtCur );

			// Update the position if it's changed.
			if( !rtCur.m_vPos.NearlyEquals( tPivot.m_vPos, 0.0001f ) || !rtCur.m_rRot.NearlyEquals( tView.m_rRot, 0.00001f ))
			{
				g_pLTServer->SetObjectTransform( hWeapon, LTRigidTransform(tPivot.m_vPos, tView.m_rRot) );
			}
		}

	}
	else
	{
		CWeapon *pTurretWeapon = m_Arsenal.GetCurWeapon( );
		if( pTurretWeapon )
		{
			HMODELSOCKET hPivot = INVALID_MODEL_SOCKET;
			g_pModelLT->GetSocket( m_hObject, "Pivot", hPivot );

			LTTransform tPivot;
			g_pModelLT->GetSocketTransform( m_hObject, hPivot, tPivot, true );

			HOBJECT hWeapon = pTurretWeapon->GetModelObject( );

			LTRigidTransform rtCur;
			g_pLTServer->GetObjectTransform( hWeapon, &rtCur );

			// Update the position if it's changed.
			if( !rtCur.m_vPos.NearlyEquals( tPivot.m_vPos, 0.0001f ) || !rtCur.m_rRot.NearlyEquals( tPivot.m_rRot, 0.00001f ))
			{
				g_pLTServer->SetObjectTransform( hWeapon, tPivot );
			}
		}
	}

	SetNextUpdate( UPDATE_NEXT_FRAME );
}