Ticket #3539: groupObstruction.patch

File groupObstruction.patch, 4.4 KB (added by mimo, 9 years ago)

patch to fix the obstruction group problem described in http://trac.wildfiregames.com/ticket/3539#comment:4

  • source/simulation2/components/CCmpUnitMotion.cpp

     
    553553        return m_State == STATE_FORMATIONMEMBER_PATH;
    554554    }
    555555
     556    entity_id_t GetGroup() const
     557    {
     558        return IsFormationMember() ? m_TargetEntity : GetEntityId();
     559    }
     560
    556561    bool HasValidPath() const
    557562    {
    558563        return m_PathState == PATHSTATE_FOLLOWING
     
    668673    /**
    669674     * Returns an appropriate obstruction filter for use with path requests.
    670675     */
    671     ControlGroupMovementObstructionFilter GetObstructionFilter(bool avoidPathfindingShapes) const;
     676    ControlGroupMovementObstructionFilter GetObstructionFilter(bool avoidPathfindingShapes, bool noTarget) const;
    672677
    673678    /**
    674679     * Checks our movement towards the next path waypoint.
     
    10801085
    10811086        PathGoal goal = { PathGoal::POINT, followingPoint.x, followingPoint.z };
    10821087        m_Planning.expectedPathTicket = cmpPathfinder->ComputeShortPathAsync(
    1083             nextPoint.x, nextPoint.z, m_Clearance, SHORT_PATH_SEARCH_RANGE, goal, m_PassClass, false, m_TargetEntity, GetEntityId());
     1088            nextPoint.x, nextPoint.z, m_Clearance, SHORT_PATH_SEARCH_RANGE, goal, m_PassClass, false, GetGroup(), GetEntityId());
    10841089    }
    10851090}
    10861091
     
    11241129        return false;
    11251130
    11261131    // Check if there's any collisions on that route
    1127     if (!cmpPathfinder->CheckMovement(GetObstructionFilter(true), from.X, from.Y, goalPos.X, goalPos.Y, m_Clearance, m_PassClass))
     1132    if (!cmpPathfinder->CheckMovement(GetObstructionFilter(true, false), from.X, from.Y, goalPos.X, goalPos.Y, m_Clearance, m_PassClass))
    11281133        return false;
    11291134
    11301135    // That route is okay, so update our path
     
    11591164    // Find the point on the goal shape that we should head towards
    11601165    CFixedVector2D goalPos = goal.NearestPointOnGoal(from);
    11611166
    1162     // Check if there's any collisions on that route
    1163     if (!cmpPathfinder->CheckMovement(GetObstructionFilter(true), from.X, from.Y, goalPos.X, goalPos.Y, m_Clearance, m_PassClass))
     1167    // Check if there's any collisions on that route (except the target itself)
     1168    if (!cmpPathfinder->CheckMovement(GetObstructionFilter(true, true), from.X, from.Y, goalPos.X, goalPos.Y, m_Clearance, m_PassClass))
    11641169        return false;
    11651170
    11661171    // That route is okay, so update our path
     
    12681273    }
    12691274}
    12701275
    1271 ControlGroupMovementObstructionFilter CCmpUnitMotion::GetObstructionFilter(bool avoidPathfindingShapes) const
     1276/**
     1277 * Notarget is true when used inside tryGoingStraightToTargetEntity, in which case we do not want the target obstruction
     1278 */
     1279ControlGroupMovementObstructionFilter CCmpUnitMotion::GetObstructionFilter(bool avoidPathfindingShapes, bool noTarget) const
    12721280{
    12731281    entity_id_t group;
    1274     if (IsFormationMember())
     1282    if (noTarget)
    12751283        group = m_TargetEntity;
    12761284    else
    1277         group = GetEntityId();
     1285        group = GetGroup();
    12781286
    12791287    return ControlGroupMovementObstructionFilter(avoidPathfindingShapes, ShouldAvoidMovingUnits(), group);
    12801288}
     
    12851293    if (m_PassabilityMapChangedRecently)
    12861294    {
    12871295        CmpPtr<ICmpPathfinder> cmpPathfinder(GetSystemEntity());
    1288         return cmpPathfinder && cmpPathfinder->CheckMovement(GetObstructionFilter(true), x0, z0, x1, z1, m_Clearance, m_PassClass);
     1296        return cmpPathfinder && cmpPathfinder->CheckMovement(GetObstructionFilter(true, false), x0, z0, x1, z1, m_Clearance, m_PassClass);
    12891297    }
    12901298
    12911299    // If an obstruction blocks tile-based pathfinding, it will be handled during the path computation
    12921300    // and doesn't need to be matched by this filter for the movement.
    1293     ControlGroupMovementObstructionFilter filter = GetObstructionFilter(false);
     1301    ControlGroupMovementObstructionFilter filter = GetObstructionFilter(false, false);
    12941302
    12951303    CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity());
    12961304    return cmpObstructionManager && !cmpObstructionManager->TestLine(filter, x0, z0, x1, z1, m_Clearance);
     
    13831391    if (!cmpPathfinder)
    13841392        return;
    13851393
    1386     m_ExpectedPathTicket = cmpPathfinder->ComputeShortPathAsync(from.X, from.Y, m_Clearance, SHORT_PATH_SEARCH_RANGE, goal, m_PassClass, avoidMovingUnits, m_TargetEntity, GetEntityId());
     1394    m_ExpectedPathTicket = cmpPathfinder->ComputeShortPathAsync(from.X, from.Y, m_Clearance, SHORT_PATH_SEARCH_RANGE, goal, m_PassClass, avoidMovingUnits, GetGroup(), GetEntityId());
    13871395}
    13881396
    13891397bool CCmpUnitMotion::MoveToPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange)