예제 #1
0
bool
Raven_Game::isSecondVisibleToFirst(const Raven_Bot* pFirst,
                                   const Raven_Bot* pSecond)const
{
  //if the two bots are equal or if one of them is not alive return false
  if ( !(pFirst == pSecond) && pSecond->isAlive())
  {
    //first of all test to see if this bot is within the FOV
    if (isSecondInFOVOfFirst(pFirst->Pos(),
                             pFirst->Facing(),
                             pSecond->Pos(),
                             pFirst->FieldOfView()))
    {
      //test the line segment connecting the bot's positions against the walls.
      //If the bot is visible add it to the vector
      if (!doWallsObstructLineSegment(pFirst->Pos(),
                                      pSecond->Pos(),
                                      m_pMap->GetWalls()))
      {
        return true;
      }
    }
  }

  return false;
}
예제 #2
0
//----------------------------- GetAllBotsInFOV ------------------------------
//
//  returns a vector of pointers to bots within the given bot's field of view
//-----------------------------------------------------------------------------
std::vector<Raven_Bot*>
Raven_Game::GetAllBotsInFOV(const Raven_Bot* pBot)const
{
  std::vector<Raven_Bot*> VisibleBots;

  std::list<Raven_Bot*>::const_iterator curBot = m_Bots.begin();
  for (curBot; curBot != m_Bots.end(); ++curBot)
  {
    //make sure time is not wasted checking against the same bot or against a
    // bot that is dead or re-spawning
    if (*curBot == pBot ||  !(*curBot)->isAlive()) continue;

    //first of all test to see if this bot is within the FOV
    if (isSecondInFOVOfFirst(pBot->Pos(),
                             pBot->Facing(),
                             (*curBot)->Pos(),
                             pBot->FieldOfView()))
    {
      //cast a ray from between the bots to test visibility. If the bot is
      //visible add it to the vector
      if (!doWallsObstructLineSegment(pBot->Pos(),
                              (*curBot)->Pos(),
                              m_pMap->GetWalls()))
      {
        VisibleBots.push_back(*curBot);
      }
    }
  }

  return VisibleBots;
}
예제 #3
0
//----------------------------- UpdateVision ----------------------------------
//
//  this method iterates through all the bots in the game world to test if
//  they are in the field of view. Each bot's memory record is updated
//  accordingly
//-----------------------------------------------------------------------------
void Raven_SensoryMemory::UpdateVision()
{
  //for each bot in the world test to see if it is visible to the owner of
  //this class
  const std::list<Raven_Bot*>& bots = m_pOwner->GetWorld()->GetAllBots();
  std::list<Raven_Bot*>::const_iterator curBot;
  for (curBot = bots.begin(); curBot!=bots.end(); ++curBot)
  {
    //make sure the bot being examined is not this bot
    if (m_pOwner != *curBot)
    {
      //make sure it is part of the memory map
      MakeNewRecordIfNotAlreadyPresent(*curBot);

      //get a reference to this bot's data
      MemoryRecord& info = m_MemoryMap[*curBot];

      //test if there is LOS between bots 
      if (m_pOwner->GetWorld()->isLOSOkay(m_pOwner->Pos(), (*curBot)->Pos()))
      {
        info.bShootable = true;

              //test if the bot is within FOV
        if (isSecondInFOVOfFirst(m_pOwner->Pos(),
                                 m_pOwner->Facing(),
                                 (*curBot)->Pos(),
                                  m_pOwner->FieldOfView()))
        {
          info.fTimeLastSensed     = Clock->GetCurrentTime();
          info.vLastSensedPosition = (*curBot)->Pos();
          info.fTimeLastVisible    = Clock->GetCurrentTime();

          if (info.bWithinFOV == false)
          {
            info.bWithinFOV           = true;
            info.fTimeBecameVisible    = info.fTimeLastSensed;
          
          }
        }

        else
        {
          info.bWithinFOV = false;         
        }
      }

      else
      {
        info.bShootable = false;
        info.bWithinFOV = false;
      }
    }
  }//next bot
}