Пример #1
0
bool CLightningFX::Init(ILTClient *pClientDE, FX_BASEDATA *pBaseData, const CBaseFXProps *pProps)
{
	LTVector vSave = pBaseData->m_vPos;

	// Perform base class initialisation

	if (!CBaseFX::Init(pClientDE, pBaseData, pProps)) 
		return false;

	ObjectCreateStruct ocs;
	INIT_OBJECTCREATESTRUCT(ocs);

	ocs.m_ObjectType		= OT_NORMAL;
	ocs.m_Flags				= pBaseData->m_dwObjectFlags | FLAG_NOLIGHT;
	ocs.m_Flags2			|= pBaseData->m_dwObjectFlags2;
	ocs.m_Pos				= m_vCreatePos;

	m_hObject = m_pLTClient->CreateObject(&ocs);
	if( !m_hObject )
		return false;

	// Are we rendering really close?

	m_bReallyClose = !!(pBaseData->m_dwObjectFlags & FLAG_REALLYCLOSE);

	
	// Create the max number of bolts 

	CLightningBolt *pBolt = LTNULL;
	PT_TRAIL_SECTION ts;

	for( uint32 nBolts = 0; nBolts < GetProps()->m_nMaxNumBolts; ++nBolts )
	{
		pBolt = debug_new( CLightningBolt );

		pBolt->m_nNumSegments = GetRandom( (int)GetProps()->m_nMinSegmentsPerBolt, (int)GetProps()->m_nMaxSegmentsPerBolt );

		// Add all the trail sections now since we don't need to constantly create and delete them...

		for( uint32 nSegs = 0; nSegs < pBolt->m_nNumSegments; ++nSegs )
		{
			ts.m_vPos = m_vCreatePos;
			pBolt->m_collPathPts.AddTail( ts );
		}

		m_lstBolts.push_back( pBolt );
	}
	

	// Setup the target data so we now where the lightning is going...

	if( pBaseData->m_bUseTargetData )
	{
		if( pBaseData->m_hTarget )
		{
			m_hTarget = pBaseData->m_hTarget;
		}
		else if( m_hParent )
		{
			m_hTarget = m_hParent;
		}
		else
		{
			m_hTarget = LTNULL;
		}
		
		m_vTargetPos = pBaseData->m_vTargetPos;
	}
	else
	{
		// Use our parent as the target if we have one otherwise just use ourselves...
		
		m_hTarget = (m_hParent ? m_hParent : m_hObject);
		m_vTargetPos = m_vCreatePos;
	}

	// Load the texture if one was specified...
	
	if( !m_hTexture && GetProps()->m_szTexture[0] )
	{
		m_pLTClient->GetTexInterface()->CreateTextureFromName( m_hTexture, GetProps()->m_szTexture );
	}

	// Create a list of attractor nodes 

	if( m_hTarget )
	{
		ILTModel		*pModelLT = m_pLTClient->GetModelLT();
		ILTCommon		*pCommonLT = m_pLTClient->Common();
		HMODELNODE		hNode = -1;
		HMODELSOCKET	hSocket = -1;
		HATTRACTOR		hAttractor = INVALID_ATTRACTOR;
		CAttractor		cAttractor;

		// Add any nodes to our attractor list...

		if( GetProps()->m_szNodeAttractors[0] )
		{
			ConParse parse( GetProps()->m_szNodeAttractors );
			while( pCommonLT->Parse( &parse ) == LT_OK )
			{
				if( parse.m_nArgs > 0 && parse.m_Args[0] )
				{
					if( pModelLT->GetNode( m_hTarget, parse.m_Args[0], hAttractor ) == LT_OK )
					{
						cAttractor.m_hModel		= m_hTarget;
						cAttractor.m_hAttractor	= hAttractor;
						cAttractor.m_eType		= CAttractor::eNode;
					
						m_lstAttractors.push_back( cAttractor );
					}
				}
			}
		}

		// Add any sockets to our attractor list...

		if( GetProps()->m_szSocketAttractors[0] )
		{
			ConParse parse( GetProps()->m_szSocketAttractors );
			while( pCommonLT->Parse( &parse ) == LT_OK )
			{
				if( parse.m_nArgs > 0 && parse.m_Args[0] )
				{
					if( pModelLT->GetSocket( m_hTarget, parse.m_Args[0], hAttractor ) == LT_OK )
					{
						cAttractor.m_hModel		= m_hTarget;
						cAttractor.m_hAttractor = hAttractor;
						cAttractor.m_eType		= CAttractor::eSocket;
					
						m_lstAttractors.push_back( cAttractor );
					}
				}
			}
		}
	}

	m_tmElapsedEmission = 0.0f;
	m_fDelay = 0.0f;

	return true;
}