Ticket #3405: ticket3405-improv.diff

File ticket3405-improv.diff, 1.6 KB (added by mimo, 9 years ago)
  • source/simulation2/components/CCmpUnitMotion.cpp

     
    15901590    {
    15911591        // Too close to the square - need to move away
    15921592
    1593         // TODO: maybe we should do the ShouldTreatTargetAsCircle thing here?
     1593        // Circumscribe the square
     1594        entity_pos_t circleRadius = halfSize.Length();
    15941595
    15951596        entity_pos_t goalDistance = minRange + Pathfinding::GOAL_DELTA;
     1597        // ensure it's far enough to not intersect the building itself (TODO is it really needed for inverted move ?)
     1598        goalDistance = std::max(goalDistance, m_Clearance + entity_pos_t::FromInt(TERRAIN_TILE_SIZE)/16);
    15961599
    1597         goal.type = PathGoal::INVERTED_SQUARE;
    1598         goal.u = obstruction.u;
    1599         goal.v = obstruction.v;
    1600         entity_pos_t delta = std::max(goalDistance, m_Clearance + entity_pos_t::FromInt(TERRAIN_TILE_SIZE)/16); // ensure it's far enough to not intersect the building itself
    1601         goal.hw = obstruction.hw + delta;
    1602         goal.hh = obstruction.hh + delta;
     1600        if (ShouldTreatTargetAsCircle(minRange, obstruction.hw, obstruction.hh, circleRadius))
     1601        {
     1602            // The target is small relative to our range, so pretend it's a circle
     1603            goal.type = PathGoal::INVERTED_CIRCLE;
     1604            goal.hw = goalDistance;
     1605        }
     1606        else
     1607        {
     1608            goal.type = PathGoal::INVERTED_SQUARE;
     1609            goal.u = obstruction.u;
     1610            goal.v = obstruction.v;
     1611            goal.hw = obstruction.hw + goalDistance;
     1612            goal.hh = obstruction.hh + goalDistance;
     1613        }
    16031614    }
    16041615    else if (maxRange < entity_pos_t::Zero() || distance < maxRange || previousDistance < maxRange)
    16051616    {