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();
    }
}
Пример #2
0
//------------------------------ Update ---------------------------------------
//-----------------------------------------------------------------------------
void Bolt::Update()
{
  if (!m_bImpacted)
  {
    m_vVelocity = MaxSpeed() * Heading();

    //make sure vehicle does not exceed maximum velocity
    m_vVelocity.Truncate(m_dMaxSpeed);

    //update the position
    m_vPosition += m_vVelocity;

    
    //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 bolt'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;
      m_bDead     = 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 impact with a wall
    double dist;
     if( FindClosestPointOfIntersectionWithWalls(m_vPosition - m_vVelocity,
                                                 m_vPosition,
                                                 dist,
                                                 m_vImpactPoint,
                                                 m_pWorld->GetMap()->GetWalls()))
     {
       m_bDead     = true;
       m_bImpacted = true;

       m_vPosition = m_vImpactPoint;

       return;
     }
  }
}
//----------------------------------- TestForImpact ---------------------------
void Pellet::TestForImpact()
{
  //a shot gun shell is an instantaneous projectile so it only gets the chance
  //to update once 
  m_bImpacted = true;

  //first find the closest wall that this ray intersects with. Then we
  //can test against all entities within this range.
  double DistToClosestImpact;
  FindClosestPointOfIntersectionWithWalls(m_vOrigin,
                                          m_vPosition,
                                          DistToClosestImpact,
                                          m_vImpactPoint,
                                          m_pWorld->GetMap()->GetWalls());

  //test to see if the ray between the current position of the shell and 
  //the start position intersects with any bots.
  Raven_Bot* hit = GetClosestIntersectingBot(m_vOrigin, m_vPosition);
  
  //if no bots hit just return;
  if (!hit) return;

  //determine the impact point with the bot's bounding circle so that the
  //shell can be rendered properly
  GetLineSegmentCircleClosestIntersectionPoint(m_vOrigin,
                                               m_vImpactPoint,
                                               hit->Pos(),
                                               hit->BRadius(),
                                               m_vImpactPoint);

  //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);
}