Пример #1
0
void RobotAI::SearchViewTarget(int64_t nNowMS)
{
	if (nNowMS < m_nNextSearchTime)
	{
		return;
	}
	m_nNextSearchTime = nNowMS + 2000;

	Point& oMyPos = m_poActor->GetPos();
	Scene* poScene = m_poActor->GetScene();
	MapConf* poMapConf = poScene->GetMapConf();

	m_poTarget = NULL;
	int nMaxHateVal = 0;

	Array<AOIOBJ*>& oObjList = poScene->GetAreaObserveds(m_poActor->GetAOIID(), 0);
	for (int i = 0; i < oObjList.Size(); ++i)
	{
		Object* poObj = oObjList[i]->poGameObj;
		int nObjType = poObj->GetType();
		if (nObjType != eOT_Role && nObjType != eOT_Robot)
		{
			continue;
		}

		Actor* poTarget = (Actor*)poObj;
		//if (m_poActor == poTarget || poTarget->IsDead() || poTarget->GetScene() != poScene || !m_poActor->CheckCamp(poTarget))
		//{
		//	continue;
		//}

		int nHateVal = 0;
		//HATE* poHate = m_poActor->GetHate(poTarget->GetID());
		//if (poHate != NULL)
		//{
		//	int nRelives = poTarget->GetRelives();
		//	if (nRelives != poHate->uRelives)
		//	{
		//		poHate->nValue = 0;
		//		poHate->uRelives = (uint8_t)nRelives;
		//	}
		//	nHateVal = poHate->nValue;
		//}
		//XLog(LEVEL_DEBUG, "%s Hate %s %d\n", m_poActor->GetName(), poTarget->GetName(), nHateVal);

		Point& oTarPos = poTarget->GetPos();
		if ((nMaxHateVal == 0 || nHateVal > nMaxHateVal) && BattleUtil::FloydCrossAble(poMapConf, oMyPos.x, oMyPos.y, oTarPos.x, oTarPos.y))
		{
			m_poTarget = poTarget;
			nMaxHateVal = nHateVal;
		}
	}
	//XLog(LEVEL_DEBUG, "%s Search hate target %s\n", m_poActor->GetName(), m_poTarget?m_poTarget->GetName():"null");
}
Пример #2
0
void RobotAI::SearchNearTarget(int64_t nNowMS)
{ 
	if (nNowMS < m_nNextSearchTime)
	{
		return;
	}
	m_nNextSearchTime = nNowMS + 2000;

	m_poTarget = NULL;
	int nMinDistance = 0;
	Point& oMyPos = m_poActor->GetPos();

	Scene* poScene = m_poActor->GetScene();
	Array<AOIOBJ*>& oObjList = poScene->GetAreaObserveds(m_poActor->GetAOIID(), 0);
	for (int i = 0; i < oObjList.Size(); ++i)
	{
		Object* poObj = oObjList[i]->poGameObj;
		if (poObj->GetType() != eOT_Role
			&& poObj->GetType() != eOT_Robot)
		{
			continue;
		}

		Actor* poActor = (Actor*)poObj;
		//if (m_poActor == poActor || poActor->IsDead() || poActor->GetScene() != poScene || !m_poActor->CheckCamp(poActor))
		//{
		//	continue;
		//}

		Point& oTarPos = poActor->GetPos();
		int nDistance = oMyPos.Distance(oTarPos);
		if (nMinDistance == 0 || nDistance < nMinDistance)
		{
			nMinDistance = nDistance;
			m_poTarget = poActor;
		}
	}
}