Ticket #3790: planNext.patch

File planNext.patch, 2.5 KB (added by mimo, 8 years ago)
  • source/simulation2/components/CCmpUnitMotion.cpp

     
    638638     * If yes, try to anticipate.
    639639     * TODO: remove this and use a more general "pushing" manager.
    640640     */
    641     void PlanNextStep(const CFixedVector2D& pos, const CFixedVector2D& currentOffset);
     641    void PlanNextStep(const CFixedVector2D& pos, const CFixedVector2D& currentOffset, const fixed& maxSteps);
    642642
    643643    /**
    644644     * Decide whether to approximate the given range from a square target as a circle,
     
    829829
    830830        // else we could, so reset our number of tries.
    831831        m_Tries = 0;
    832        
     832
    833833        // Now we've got a short path that we can follow
    834834        if (!HasValidPath())
    835835            StartSucceeded();
     
    977977
    978978                if (cmpPathfinder->CheckMovement(GetObstructionFilter(), pos.X, pos.Y, target.X, target.Y, m_Clearance, m_PassClass))
    979979                {
    980                     PlanNextStep(pos, offset);
    981980                    pos = target;
     981                    fixed maxSteps = (offsetLength - maxdist) / maxdist;
     982                    PlanNextStep(pos, offset, maxSteps);
    982983                    break;
    983984                }
    984985                else
     
    11191120    }
    11201121}
    11211122
    1122 void CCmpUnitMotion::PlanNextStep(const CFixedVector2D& pos, const CFixedVector2D& currentOffset)
     1123void CCmpUnitMotion::PlanNextStep(const CFixedVector2D& pos, const CFixedVector2D& currentOffset, const fixed& maxSteps)
    11231124{
    11241125    if (m_LongPath.m_Waypoints.empty())
    11251126        return;
    1126    
     1127    // Do not plan if a path is already being computed
     1128    if (m_ExpectedPathTicket)
     1129        return;
     1130
    11271131    CmpPtr<ICmpPathfinder> cmpPathfinder(GetSystemEntity());
    11281132    CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity());
    11291133    if (!cmpPathfinder || !cmpObstructionManager)
    11301134        return;
    1131    
    1132     m_Planning = SUnitMotionPlanning();
    1133    
    1134     // see 2 turns in advance, otherwise this would start to lag in MP
    1135     CFixedVector2D futurePos = pos + currentOffset*2;
    1136    
     1135
     1136    // Plan 1 turn in advance
     1137    fixed step = std::min(fixed::FromFloat(1.0f), maxSteps);
     1138    CFixedVector2D futurePos = pos + currentOffset.Multiply(step);
     1139
    11371140    // Don't actually use CheckMovement since we want to check against units only, we assume the rest is taken care of.
    11381141    if (!cmpObstructionManager->TestLine(GetObstructionFilter(true, false), pos.X, pos.Y, futurePos.X, futurePos.Y, m_Clearance, true))
    11391142        return;
    1140    
     1143
    11411144    // we will run into a static unit obstruction. Try to shortpath around it.
    11421145    PathGoal goal;
    11431146    if (m_LongPath.m_Waypoints.size() > 1 || m_FinalGoal.DistanceToPoint(pos) > LONG_PATH_MIN_DIST)