Ticket #3785: betterfix.patch

File betterfix.patch, 4.1 KB (added by wraitii, 7 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 1ab8932..55400d0 100644
    a b void CCmpPathfinder::ComputeShortPath(const IObstructionTestFilter& filter,  
    577577    vertexes.push_back(end);
    578578    const size_t GOAL_VERTEX_ID = 1;
    579579
    580     // Add terrain obstructions
    581     {
    582         u16 i0, j0, i1, j1;
    583         Pathfinding::NearestNavcell(rangeXMin, rangeZMin, i0, j0, m_MapSize*Pathfinding::NAVCELLS_PER_TILE, m_MapSize*Pathfinding::NAVCELLS_PER_TILE);
    584         Pathfinding::NearestNavcell(rangeXMax, rangeZMax, i1, j1, m_MapSize*Pathfinding::NAVCELLS_PER_TILE, m_MapSize*Pathfinding::NAVCELLS_PER_TILE);
    585         AddTerrainEdges(edges, vertexes, i0, j0, i1, j1, passClass, *m_TerrainOnlyGrid);
    586     }
    587 
    588580    // Find all the obstruction squares that might affect us
    589581    CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity());
    590582    std::vector<ICmpObstructionManager::ObstructionSquare> squares;
    void CCmpPathfinder::ComputeShortPath(const IObstructionTestFilter& filter,  
    623615        vert.quadInward = QUADRANT_NONE;
    624616        vert.quadOutward = QUADRANT_ALL;
    625617        vert.p.X = center.X - hd0.Dot(u); vert.p.Y = center.Y + hd0.Dot(v); if (aa) vert.quadInward = QUADRANT_BR; vertexes.push_back(vert);
     618        if (vert.p.X < rangeXMin) rangeXMin = vert.p.X; if (vert.p.Y < rangeZMin) rangeZMin = vert.p.Y;
     619        if (vert.p.X > rangeXMax) rangeXMax = vert.p.X; if (vert.p.Y > rangeZMax) rangeZMax = vert.p.Y;
    626620        vert.p.X = center.X - hd1.Dot(u); vert.p.Y = center.Y + hd1.Dot(v); if (aa) vert.quadInward = QUADRANT_TR; vertexes.push_back(vert);
     621        if (vert.p.X < rangeXMin) rangeXMin = vert.p.X; if (vert.p.Y < rangeZMin) rangeZMin = vert.p.Y;
     622        if (vert.p.X > rangeXMax) rangeXMax = vert.p.X; if (vert.p.Y > rangeZMax) rangeZMax = vert.p.Y;
    627623        vert.p.X = center.X + hd0.Dot(u); vert.p.Y = center.Y - hd0.Dot(v); if (aa) vert.quadInward = QUADRANT_TL; vertexes.push_back(vert);
     624        if (vert.p.X < rangeXMin) rangeXMin = vert.p.X; if (vert.p.Y < rangeZMin) rangeZMin = vert.p.Y;
     625        if (vert.p.X > rangeXMax) rangeXMax = vert.p.X; if (vert.p.Y > rangeZMax) rangeZMax = vert.p.Y;
    628626        vert.p.X = center.X + hd1.Dot(u); vert.p.Y = center.Y - hd1.Dot(v); if (aa) vert.quadInward = QUADRANT_BL; vertexes.push_back(vert);
     627        if (vert.p.X < rangeXMin) rangeXMin = vert.p.X; if (vert.p.Y < rangeZMin) rangeZMin = vert.p.Y;
     628        if (vert.p.X > rangeXMax) rangeXMax = vert.p.X; if (vert.p.Y > rangeZMax) rangeZMax = vert.p.Y;
    629629
    630630        // Add the edges:
    631631
    void CCmpPathfinder::ComputeShortPath(const IObstructionTestFilter& filter,  
    650650        // to reduce the search space
    651651    }
    652652
     653    // Add terrain obstructions
     654    {
     655        u16 i0, j0, i1, j1;
     656        Pathfinding::NearestNavcell(rangeXMin, rangeZMin, i0, j0, m_MapSize*Pathfinding::NAVCELLS_PER_TILE, m_MapSize*Pathfinding::NAVCELLS_PER_TILE);
     657        Pathfinding::NearestNavcell(rangeXMax, rangeZMax, i1, j1, m_MapSize*Pathfinding::NAVCELLS_PER_TILE, m_MapSize*Pathfinding::NAVCELLS_PER_TILE);
     658        AddTerrainEdges(edges, vertexes, i0, j0, i1, j1, passClass, *m_TerrainOnlyGrid);
     659    }
     660
    653661    // Clip out vertices that are inside an edgeSquare (i.e. trivially unreachable)
    654662    for (size_t i = 0; i < edgeSquares.size(); ++i)
    655663    {
    void CCmpPathfinder::ComputeShortPath(const IObstructionTestFilter& filter,  
    829837                    continue;
    830838            }
    831839
    832             bool visible = true;
    833             u16 i, j;
    834             Pathfinding::NearestNavcell(vertexes[curr.id].p.X, vertexes[curr.id].p.Y, i, j, m_Grid->m_W, m_Grid->m_H);
    835             if (!IS_PASSABLE(m_Grid->get(i, j), passClass))
    836             {
    837                 Pathfinding::NearestNavcell(npos.X, npos.Y, i, j, m_Grid->m_W, m_Grid->m_H);
    838                 // Do not allow path between two impassable vertexes to prevent cases
    839                 // where a path along an obstruction will end up in an impassable region
    840                 if (!IS_PASSABLE(m_Grid->get(i, j), passClass))
    841                     visible = false;
    842             }
    843 
    844             visible = visible &&
     840            bool visible =
    845841                CheckVisibilityLeft(vertexes[curr.id].p, npos, edgesLeft) &&
    846842                CheckVisibilityRight(vertexes[curr.id].p, npos, edgesRight) &&
    847843                CheckVisibilityBottom(vertexes[curr.id].p, npos, edgesBottom) &&