Ticket #1200: 1200noscope.patch

File 1200noscope.patch, 2.1 KB (added by fsincos, 8 years ago)
  • source/simulation2/components/CCmpPathfinder_Vertex.cpp

    diff --git a/source/simulation2/components/CCmpPathfinder_Vertex.cpp b/source/simulation2/components/CCmpPathfinder_Vertex.cpp
    index 5ab11b6..e9f46c2 100644
    a b struct SquareSort  
    556556    }
    557557};
    558558
     559static const u8 LAZINESS = 2; // Maximum tradeoff: improvement to distance from goal <-> path length
     560
    559561void CCmpPathfinder::ComputeShortPath(const IObstructionTestFilter& filter,
    560562    entity_pos_t x0, entity_pos_t z0, entity_pos_t clearance,
    561563    entity_pos_t range, const PathGoal& goal, pass_class_t passClass, WaypointPath& path)
    void CCmpPathfinder::ComputeShortPath(const IObstructionTestFilter& filter,  
    791793    open.push(qiStart);
    792794
    793795    u16 idBest = START_VERTEX_ID;
    794     fixed hBest = start.h;
     796    fixed hBest = start.h.Multiply(start.h);
    795797
    796798    while (!open.empty())
    797799    {
    void CCmpPathfinder::ComputeShortPath(const IObstructionTestFilter& filter,  
    799801        VertexPriorityQueue::Item curr = open.pop();
    800802        vertexes[curr.id].status = Vertex::CLOSED;
    801803
     804
     805        // The following trick selects the end point using a different criterion.
     806        // This is mostly done because by the time the unit has traversed the path much could have changed,
     807        // e.g. in case of lots of units swarming around a point.
     808
     809        if (vertexes[curr.id].h.Multiply(vertexes[curr.id].h)  + (vertexes[curr.id].g << LAZINESS) < hBest)
     810        {
     811            idBest = curr.id;
     812            hBest = vertexes[curr.id].h.Multiply(vertexes[curr.id].h) + (vertexes[curr.id].g << LAZINESS);
     813        }
     814
    802815        // If we've reached the destination, stop
    803816        if (curr.id == GOAL_VERTEX_ID)
    804817        {
    void CCmpPathfinder::ComputeShortPath(const IObstructionTestFilter& filter,  
    910923
    911924                    VertexPriorityQueue::Item t = { (u16)n, g + vertexes[n].h, vertexes[n].h };
    912925                    open.push(t);
    913 
    914                     // Remember the heuristically best vertex we've seen so far, in case we never actually reach the target
    915                     if (vertexes[n].h < hBest)
    916                     {
    917                         idBest = (u16)n;
    918                         hBest = vertexes[n].h;
    919                     }
    920926                }
    921927                else // must be OPEN
    922928                {