Exemplo n.º 1
0
//-----------------------------------------------------------------------------
void Raven_TargetingSystem::Update()
{
  double ClosestDistSoFar = MaxDouble;
  m_pCurrentTarget       = 0;

  //grab a list of all the opponents the owner can sense
  std::list<Raven_Bot*> SensedBots;
  SensedBots = m_pOwner->GetSensoryMem()->GetListOfRecentlySensedOpponents();
  
  std::list<Raven_Bot*>::const_iterator curBot = SensedBots.begin();
  for (curBot; curBot != SensedBots.end(); ++curBot)
  {
    //make sure the bot is alive and that it is not the owner
	  if ((*curBot)->isAlive() && (*curBot != m_pOwner) && (*curBot)->getEquipe()!=m_pOwner->getEquipe())
    {
      double dist = Vec2DDistanceSq((*curBot)->Pos(), m_pOwner->Pos());

      if (dist < ClosestDistSoFar)
      {
        ClosestDistSoFar = dist;
        m_pCurrentTarget = *curBot;
      }
    }
  }
}
Raven_Bot* Raven_Projectile::GetClosestIntersectingBot(Vector2D    From,
                                                       Vector2D    To)const
{
  Raven_Bot* ClosestIntersectingBot = 0;
  double ClosestSoFar = MaxDouble;

  //iterate through all entities checking against the line segment FromTo
  std::list<Raven_Bot*>::const_iterator curBot;
  for (curBot =  m_pWorld->GetAllBots().begin();
       curBot != m_pWorld->GetAllBots().end();
       ++curBot)
  {
    //make sure we don't check against the shooter of the projectile
    if ( ((*curBot)->ID() != m_iShooterID))
    {
      //if the distance to FromTo is less than the entity's bounding radius then
      //there is an intersection
      if (DistToLineSegment(From, To, (*curBot)->Pos()) < (*curBot)->BRadius())
      {
        //test to see if this is the closest so far
        double Dist = Vec2DDistanceSq((*curBot)->Pos(), m_vOrigin);

        if (Dist < ClosestSoFar)
        {
          Dist = ClosestSoFar;
          ClosestIntersectingBot = *curBot;
        }
      }
    }

  }

  return ClosestIntersectingBot;
}
//------------------------ GetClosestNodeToPosition ---------------------------
//
//  returns the index of the closest visible graph node to the given position
//-----------------------------------------------------------------------------
int Raven_PathPlanner::GetClosestNodeToPosition(Vector2D pos)const
{
  double ClosestSoFar = MaxDouble;
  int   ClosestNode  = no_closest_node_found;

  //when the cell space is queried this the the range searched for neighboring
  //graph nodes. This value is inversely proportional to the density of a 
  //navigation graph (less dense = bigger values)
  const double range = m_pOwner->GetWorld()->GetMap()->GetCellSpaceNeighborhoodRange();

  //calculate the graph nodes that are neighboring this position
  m_pOwner->GetWorld()->GetMap()->GetCellSpace()->CalculateNeighbors(pos, range);

  //iterate through the neighbors and sum up all the position vectors
  for (NodeType* pN = m_pOwner->GetWorld()->GetMap()->GetCellSpace()->begin();
                 !m_pOwner->GetWorld()->GetMap()->GetCellSpace()->end();     
                 pN = m_pOwner->GetWorld()->GetMap()->GetCellSpace()->next())
  {
    //if the path between this node and pos is unobstructed calculate the
    //distance
    if (m_pOwner->canWalkBetween(pos, pN->Pos()))
    {
      double dist = Vec2DDistanceSq(pos, pN->Pos());

      //keep a record of the closest so far
      if (dist < ClosestSoFar)
      {
        ClosestSoFar = dist;
        ClosestNode  = pN->Index();
      }
    }
  }
   
  return ClosestNode;
}
void Rocket::TestForImpact()
{
   
    //if the projectile has reached the target position or it hits an entity
    //or wall it should explode/inflict damage/whatever and then mark itself
    //as dead


    //test to see if the line segment connecting the rocket's current position
    //and previous position intersects with any bots.
    Raven_Bot* hit = GetClosestIntersectingBot(m_vPosition - m_vVelocity, m_vPosition);
    
    //if hit
    if (hit)
    {
      m_bImpacted = true;

      //send a message to the bot to let it know it's been hit, and who the
      //shot came from
      Dispatcher->DispatchMsg(SEND_MSG_IMMEDIATELY,
                              m_iShooterID,
                              hit->ID(),
                              Msg_TakeThatMF,
                              (void*)&m_iDamageInflicted);

      //test for bots within the blast radius and inflict damage
      InflictDamageOnBotsWithinBlastRadius();
    }

    //test for impact with a wall
    double dist;
     if( FindClosestPointOfIntersectionWithWalls(m_vPosition - m_vVelocity,
                                                 m_vPosition,
                                                 dist,
                                                 m_vImpactPoint,
                                                 m_pWorld->GetMap()->GetWalls()))
     {
        m_bImpacted = true;
      
        //test for bots within the blast radius and inflict damage
        InflictDamageOnBotsWithinBlastRadius();

        m_vPosition = m_vImpactPoint;

        return;
    }
    
    //test to see if rocket has reached target position. If so, test for
     //all bots in vicinity
    const double tolerance = 5.0;   
    if (Vec2DDistanceSq(Pos(), m_vTarget) < tolerance*tolerance)
    {
      m_bImpacted = true;

      InflictDamageOnBotsWithinBlastRadius();
    }
}
Vector2D B020612E_Steering::FollowPath(){
	if (Vec2DDistanceSq(_pPath->CurrentWaypoint()->waypoint->GetPosition(), _pTank->GetCentrePosition()) < (10 * 10))
		_pPath->SetNextWaypoint();

	if (!_pPath->Finished())
		return Seek(_pPath->CurrentWaypoint()->waypoint->GetPosition());
	else
		return Arrive(_pPath->CurrentWaypoint()->waypoint->GetPosition(), NORMAL);
}
Exemplo n.º 6
0
Entity* Projectile::GetClosestIntersectingEntity(Vector2D From, Vector2D To)const
{

	Entity* ClosestIntersectingEntity = 0;
	double ClosestSoFar = MaxDouble;

	//iterate through all game entities
	std::list<Entity*>::const_iterator curEntity;
	for(curEntity = m_pWorld->GetAllEntities().begin();
		curEntity != m_pWorld->GetAllEntities().end();
		++curEntity)
	{

		//don't check the entity who shot the projectile
		if(((*curEntity)->ID() != m_iShooterID))
		{

			//if the distasnce to the segment between From and To is less than the entities bounding
			//radius then thre is an intersection
			if(DistToLineSegment(From, To, (*curEntity)->Pos()) < (*curEntity)->BRadius())
			{

				//check if this the closest intersecting entity so far
				double Dist = Vec2DDistanceSq((*curEntity)->Pos(), m_vOrigin);

				//if so then set this to be the new closest entity
				if(Dist < ClosestSoFar)
				{

					Dist = ClosestSoFar;
					ClosestIntersectingEntity = *curEntity;

				}

			}

		}

	}

	return ClosestIntersectingEntity;

}
Exemplo n.º 7
0
//--------------------------- Hide ---------------------------------------
//
//------------------------------------------------------------------------
Vector2D SteeringBehavior::Hide()
{
	double    DistToClosest = MaxDouble;
	Vector2D BestHidingSpot;

	std::set<Obstacle*>::const_iterator curOb = Obstacle::getAll().begin();
	std::set<Obstacle*>::const_iterator closest;

	while(curOb != Obstacle::getAll().end())
	{
		//calculate the position of the hiding spot for this obstacle
		Vector2D HidingSpot = GetHidingPosition((*curOb)->Pos(),
			(*curOb)->BRadius(),
			hideTarget->Pos());

		//work in distance-squared space to find the closest hiding
		//spot to the agent
		double dist = Vec2DDistanceSq(HidingSpot, m_pMovingEntity->Pos());

		if (dist < DistToClosest)
		{
			DistToClosest = dist;

			BestHidingSpot = HidingSpot;

			closest = curOb;
		}  

		++curOb;

	}//end while

	//if no suitable obstacles found then Evade the hunter
	if (DistToClosest == MaxFloat)
	{
		return Flee(hideTarget->Pos());
	}

	//else use Arrive on the hiding spot
	return Arrive(BestHidingSpot, fast);
}
Exemplo n.º 8
0
//--------------------- GetPosOfClosestSwitch -----------------------------
//
//  returns the position of the closest visible switch that triggers the
//  door of the specified ID
//-----------------------------------------------------------------------------
Vector2D 
Raven_Game::GetPosOfClosestSwitch(Vector2D botPos, unsigned int doorID)const
{
  std::vector<unsigned int> SwitchIDs;
  
  //first we need to get the ids of the switches attached to this door
  std::vector<Raven_Door*>::const_iterator curDoor;
  for (curDoor = m_pMap->GetDoors().begin();
       curDoor != m_pMap->GetDoors().end();
       ++curDoor)
  {
    if ((*curDoor)->ID() == doorID)
    {
       SwitchIDs = (*curDoor)->GetSwitchIDs(); break;
    }
  }

  Vector2D closest;
  double ClosestDist = MaxDouble;
  
  //now test to see which one is closest and visible
  std::vector<unsigned int>::iterator it;
  for (it = SwitchIDs.begin(); it != SwitchIDs.end(); ++it)
  {
    BaseGameEntity* trig = EntityMgr->GetEntityFromID(*it);

    if (isLOSOkay(botPos, trig->Pos()))
    {
      double dist = Vec2DDistanceSq(botPos, trig->Pos());

      if ( dist < ClosestDist)
      {
        ClosestDist = dist;
        closest = trig->Pos();
      }
    }
  }

  return closest;
}
Exemplo n.º 9
0
bool Level::isPathObstructed(Vector2D A,
	Vector2D B,
	double    BoundingRadius)const
{
	Vector2D ToB = Vec2DNormalize(B - A);

	Vector2D curPos = A;

	while (Vec2DDistanceSq(curPos, B) > BoundingRadius*BoundingRadius)
	{
		//advance curPos one step
		curPos += ToB * 0.5 * BoundingRadius;

		//test all walls against the new position
		//if (doWallsIntersectCircle(m_pMap->GetWalls(), curPos, BoundingRadius))
		{
			return true;
		}
	}

	return false;
}
Exemplo n.º 10
0
//------------------------ isAtPosition ---------------------------------------
//
//  returns true if the bot is close to the given position
//-----------------------------------------------------------------------------
bool Raven_Bot::isAtPosition(Vector2D pos)const
{
  const static double tolerance = 10.0;
  
  return Vec2DDistanceSq(Pos(), pos) < tolerance * tolerance;
}
bool GoalKeeper::BallWithinRangeForIntercept()const
{
  return (Vec2DDistanceSq(Team()->HomeGoal()->Center(), Ball()->Pos()) <=
          Prm.GoalKeeperInterceptRangeSq);
}
bool GoalKeeper::TooFarFromGoalMouth()const
{
  return (Vec2DDistanceSq(Pos(), GetRearInterposeTarget()) >
          Prm.GoalKeeperInterceptRangeSq);
}
Exemplo n.º 13
0
bool PlayerBase::AtTarget() const
{
    return (Vec2DDistanceSq(Pos(), Steering()->Target()) < 3.0);
}
Exemplo n.º 14
0
bool PlayerBase::BallWithinControlRange() const
{
    double dist = Vec2DDistanceSq(this->Ball()->Pos(), Pos());
    return (Vec2DDistanceSq(this->Ball()->Pos(), Pos()) < 0.4);
}
Exemplo n.º 15
0
bool PlayerBase::BallWithinReceivingRange() const
{
    return (Vec2DDistanceSq(Pos(), Ball()->Pos()) < 0.3);
}