Esempio n. 1
0
// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CAutoTargetMgr::AddMagnets()
//
//	PURPOSE:	Add any aim magnets in our cone to the array
//
// ----------------------------------------------------------------------- //
void CAutoTargetMgr::AddMagnets()
{
	CSFXMgr* psfxMgr = g_pGameClientShell->GetSFXMgr();

	//step through the chars
	CSpecialFXList* const pMagnetList = psfxMgr->GetFXList(SFX_AIMMAGNET_ID);	
	int nNumSFX  = pMagnetList->GetSize();
	
	for (int nMag=0; nMag < nNumSFX; nMag++)
	{
		CAimMagnetFX* pMag = (CAimMagnetFX*)(*pMagnetList)[nMag];
		if (pMag)
		{
			uint32 dwFlags;
			g_pCommonLT->GetObjectFlags(pMag->GetServerObj(), OFT_Flags, dwFlags);

			if (!(dwFlags & FLAG_VISIBLE))
				continue;

			//filter out anyone outside the cone
			LTVector vTargetPos;
			g_pLTClient->GetObjectPos(pMag->GetTarget(), &vTargetPos);

			if (IsPointInCone( vTargetPos ) && m_nNodeCount < MAX_AUTOTARGET_NODES)
			{
				m_NodeArray[m_nNodeCount].vPos = vTargetPos;
				m_NodeArray[m_nNodeCount].hChar = pMag->GetTarget();
				m_nNodeCount++;
			}
		}
	}

}
Esempio n. 2
0
// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CAutoTargetMgr::GenerateCharArray()
//
//	PURPOSE:	Fill array with list of chars sorted by distance
//
// ----------------------------------------------------------------------- //
void CAutoTargetMgr::GenerateCharArray()
{
	//clear our target array
	m_Targets.resize(0);

	CSFXMgr* psfxMgr = g_pGameClientShell->GetSFXMgr();

	//step through the chars
	CSpecialFXList* const pCharList = psfxMgr->GetFXList(SFX_CHARACTER_ID);	
	int nNumSFX  = pCharList->GetSize();
	
	for (int nChar=0; nChar < nNumSFX; nChar++)
	{
		CCharacterFX* pChar = (CCharacterFX*)(*pCharList)[nChar];
		if (pChar)
		{
			if (pChar->m_cs.bIsPlayer)
			{
				//filter out local player
			    HLOCALOBJ hPlayerObj = g_pLTClient->GetClientObject();
			    if (hPlayerObj == pChar->GetServerObj())
					continue;
				if(pChar->IsPlayerDead())
					continue;

				//if this is a team game filter out our teammates
				if (GameModeMgr::Instance( ).m_grbUseTeams )
				{
					// Get the client information of the body and us.
					uint32 nId = pChar->m_cs.nClientID;
					CClientInfoMgr* pCIMgr = g_pInterfaceMgr->GetClientInfoMgr();
					CLIENT_INFO* pCI = pCIMgr->GetClientByID(nId);
					CLIENT_INFO *pLocalCI = g_pInterfaceMgr->GetClientInfoMgr()->GetLocalClient();

					// Only allow us to auto-target people on the other team.
					if( pCI && pLocalCI )
					{
						if (pCI->nTeamID == pLocalCI->nTeamID)
							continue;
					}

				}
			}
			else
			{
				// Check alignment of non-players
				if(pChar->m_cs.eCrosshairPlayerStance != kCharStance_Hate)
					continue;
			}

			//filter out anyone outside the cone
			LTVector vTargetPos;
			g_pLTClient->GetObjectPos(pChar->GetServerObj(), &vTargetPos);
			LTVector vOffset(0.0f,32.0f,0.0f);

			// we check both upper and lower parts of the body and if either is in the cone, we're good
			if (IsPointInCone( vTargetPos - vOffset) || IsPointInCone( vTargetPos + vOffset) )
			{
				// we only care about the n closest characters, so...
				// if the new one farther away than the n-th one, drop it, 
				//	otherwise drop the n-th one and insert the new one
			
				//step through the chars we already know about...
				CharFXArray::iterator iter = m_Targets.begin();
				bool bInserted = false;
				while (iter != m_Targets.end() && !bInserted)
				{
					//figure out how far away this one is
					CCharacterFX* pTestChar = (CCharacterFX*)(*iter);
					LTVector vTestPos;
					g_pLTClient->GetObjectPos(pTestChar->GetServerObj(), &vTestPos);
					float fTestDistSqr = m_vFirePos.DistSqr(vTestPos);

					//if this char is farther away than the one we're inserting
					if (fTestDistSqr > m_fRangeSqr)
					{
						//if our list is full, pop off the last one...
						if (m_Targets.size() >= MAX_AUTOTARGET_CHARACTERS)
							m_Targets.pop_back();

						m_Targets.insert(iter,pChar);
						bInserted = true;
					}

					iter++;
				}

				//if we haven't inseted it yet, and we have room, add it to the back
				if (!bInserted && m_Targets.size() < MAX_AUTOTARGET_CHARACTERS)
					m_Targets.push_back(pChar);
			}
		}

	}

}