View Single Post
Re: Yay - Bots move to given vector location...
Old
  (#27)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: Yay - Bots move to given vector location... - 12-01-2005

hey stevec, thats what Bots-United is for... to work together on kick-ass bots. Or alteast, at a kick-ass-framework

my snippet:

Code:
void BotFindEnemy(bot_t *pBot)
{
	// FIXME: Make this use UTIL_TRACELINE some day?
	Vector vFrom, vTo;	
	Ray_t mRay;		 // the ray itself
 CTraceFilterHitAll mTraceFilter;	
	CGameTrace tRay;	// the results 
	CBaseEntity *pEnemyBaseEntity=NULL;
	if (pBot->pEnemy)
	{
		BotAttackEnemy(pBot);
		return;
	}
	float fDistance=9999;
	// scan for enemy activities
 for ( int i = 1; i <= 32; i++ )  // EVIL: shouldn't just assume maxplayers is 32!!!
 {
  edict_t *pPlayerEdict = INDEXENT( i );
 
		if (pPlayerEdict)   // valid edict		
		{			   
			if (pPlayerEdict == pBot->edict)
				continue; // do not check self
			pEnemyBaseEntity = CBaseEntity::Instance(pPlayerEdict);// get the player entity
			if (pEnemyBaseEntity == NULL)
				continue; // failed
			// Check if its a player. (thx botman for pointing me out on this <shame>)
			if (!pEnemyBaseEntity->IsPlayer())
				continue; 
			if ( !pPlayerEdict->IsFree() ) // valid client
			{		   
				// HACK HACK
			   
				// ok, this COULD be our enemy, so check this team status				
				IPlayerInfo* pInfo = NULL;
				
				if (playerinfomanager)
					pInfo = playerinfomanager->GetPlayerInfo(pPlayerEdict);
		
				if (pInfo == NULL || !pInfo)
					return; // get out, this wont work :S					*/
				
				// Set team (in case the game dll changed it for us)
				int iTeam = pInfo->GetTeamIndex();
			   
				if (iTeam != pBot->iTeam)
				{					
					// potential enemy
					vFrom = pBot->vMyOrigin;
					gameclients->ClientEarPosition( pPlayerEdict, &vTo );   // to = his origin
					// TODO: How to make sure it is in our viewangles?
					QAngle viewangles;
					UTIL_VectorAngles( pBot->vLookAtVector, viewangles );
					if (FInViewCone(vFrom, vTo, viewangles) == false)
						continue;
					//bool FInViewCone (Vector vStart, Vector vLookDir, QAngle viewangles)
					// CHECK if enemy is behind wall or not
					
					if (UTIL_DistanceBetween(vFrom, vTo) > fDistance)
						continue; // too far
					mRay.Init(vFrom,vTo); // init
					
					enginetrace->TraceRay(mRay, MASK_PLAYERSOLID, &mTraceFilter, &tRay);

					//if (pEnemyBaseEntity == NU
					// success
					if (tRay.fraction == 1.0 || tRay.m_pEnt == pEnemyBaseEntity)
						{
						// could be our enemy
						fDistance = UTIL_DistanceBetween(vFrom, vTo);
						// Set as our enemy for now
						pBot->pEnemy = pPlayerEdict;
					}
				}
			}		
		}
 } 
}
Note:
my "FInViewCone" function... is a bit of a fuzz. I do not know if it works 100%, here it is. Btw, i did not notice odd behaviour just yet...

Code:
bool FInViewCone (Vector vStart, Vector vLookDir, QAngle viewangles)
{  
  float flDot;
  Vector vMoveDir;
  // We move to this
  AngleVectors(viewangles, &vMoveDir);
  
  Vector vRightLook, vUpLook;	
  VectorVectors(vLookDir, vRightLook, vUpLook); // get the vector perpendicular to the forward vector
  
  Vector vDest = vLookDir-vStart;
  // vLookDir 
  flDot = DotProduct(vDest, vLookDir);	
  //Msg("FlDOT=%f ", flDot);  
	  
  if (fabs(flDot) > 0.50)  // 60 degree field of view
	{
	  return TRUE;
	}
  else
	{
	  return FALSE;
	}
}


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote