private void RaycastCheck <TSetCellVisible>(GameFowManager pFowMgr, FowLos.CRaycastQuadrant quadrant, VInt2 newSurfPos, VInt3 unitLoc, int sightSqr, COM_PLAYERCAMP camp, bool bDrawDebugLines, byte inStartViewblockId, ref TSetCellVisible setCellVisible) where TSetCellVisible : ISetCellVisible
    {
        VInt2 aa        = new VInt2(unitLoc.x, unitLoc.y);
        int   x         = quadrant.min.x;
        int   x2        = quadrant.max.x;
        int   y         = quadrant.min.y;
        int   y2        = quadrant.max.y;
        VInt2 zero      = VInt2.zero;
        int   halfSizeX = pFowMgr.m_halfSizeX;
        int   halfSizeY = pFowMgr.m_halfSizeY;

        for (int i = x; i <= x2; i++)
        {
            for (int j = y; j <= y2; j++)
            {
                VInt2 vInt = new VInt2(i, j);
                if (i == newSurfPos.x && j == newSurfPos.y)
                {
                    setCellVisible.SetVisible(vInt, camp, true);
                }
                else if ((vInt - newSurfPos).sqrMagnitude < sightSqr)
                {
                    FieldObj.SViewBlockAttr sViewBlockAttr;
                    if (!pFowMgr.m_pFieldObj.GrassBlockView && pFowMgr.m_pFieldObj.QueryAttr(vInt, out sViewBlockAttr) && sViewBlockAttr.BlockType == 1)
                    {
                        int num = (int)pFowMgr.m_pFieldObj.QueryViewblockId(vInt.x, vInt.y);
                        if (num != (int)inStartViewblockId)
                        {
                            setCellVisible.SetVisible(vInt, camp, false);
                            goto IL_6DD;
                        }
                    }
                    VInt3 zero2 = VInt3.zero;
                    pFowMgr.m_pFieldObj.LevelGrid.GridToWorldPos(i, j, out zero2);
                    VInt2 vInt2 = new VInt2(zero2.x, zero2.y);
                    VInt2 bb    = vInt2;
                    bb.x -= halfSizeX;
                    bb.y -= halfSizeY;
                    VInt2 bb2 = vInt2;
                    bb2.x += halfSizeX;
                    bb2.y -= halfSizeY;
                    VInt2 bb3 = vInt2;
                    bb3.x += halfSizeX;
                    bb3.y += halfSizeY;
                    VInt2 bb4 = vInt2;
                    bb4.x -= halfSizeX;
                    bb4.y += halfSizeY;
                    FowLos.SGridWall sGridWall = default(FowLos.SGridWall);
                    bool             flag      = false;
                    bool             flag2     = false;
                    bool             flag3     = false;
                    bool             flag4     = i < newSurfPos.x;
                    bool             flag5     = j < newSurfPos.y;
                    int num2 = flag4 ? newSurfPos.x : (newSurfPos.x + 1);
                    int num3 = flag5 ? newSurfPos.y : (newSurfPos.y + 1);
                    int num4 = 0;
                    while (!flag && (!flag2 || !flag3))
                    {
                        if (!flag2)
                        {
                            int num5 = num2 + (flag4 ? (-num4) : num4);
                            if (flag4 && num5 < i + 1)
                            {
                                flag2 = true;
                            }
                            else if (!flag4 && num5 > i)
                            {
                                flag2 = true;
                            }
                            if (!flag2 && quadrant.wallsVertical.Contains((byte)num5))
                            {
                                List <FowLos.SBlockWalls> .Enumerator enumerator = quadrant.viewBlockArrayFinal.GetEnumerator();
                                while (enumerator.MoveNext() && !flag)
                                {
                                    FowLos.SBlockWalls      current = enumerator.get_Current();
                                    List <FowLos.SGridWall> list    = null;
                                    if (current.m_wallsVertical.TryGetValue((byte)num5, ref list))
                                    {
                                        int count = list.get_Count();
                                        int num6  = 0;
                                        while (num6 < count && !flag)
                                        {
                                            FowLos.SGridWall sGridWall2 = list.get_Item(num6);
                                            if (bDrawDebugLines)
                                            {
                                                if (FowLos.SegmentIntersect(aa, vInt2, sGridWall2.m_start, sGridWall2.m_end, ref zero))
                                                {
                                                    flag = true;
                                                }
                                                else if (FowLos.SegmentIntersect(aa, bb, sGridWall2.m_start, sGridWall2.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb2, sGridWall2.m_start, sGridWall2.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb3, sGridWall2.m_start, sGridWall2.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb4, sGridWall2.m_start, sGridWall2.m_end, ref zero))
                                                {
                                                    flag = true;
                                                }
                                            }
                                            else if (FowLos.SegmentIntersect(aa, vInt2, sGridWall2.m_start, sGridWall2.m_end))
                                            {
                                                flag = true;
                                            }
                                            else if (FowLos.SegmentIntersect(aa, bb, sGridWall2.m_start, sGridWall2.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb2, sGridWall2.m_start, sGridWall2.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb3, sGridWall2.m_start, sGridWall2.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb4, sGridWall2.m_start, sGridWall2.m_end, ref zero))
                                            {
                                                flag = true;
                                            }
                                            num6++;
                                        }
                                    }
                                }
                            }
                        }
                        if (!flag3 && !flag)
                        {
                            int num7 = num3 + (flag5 ? (-num4) : num4);
                            if (flag5 && num7 < j + 1)
                            {
                                flag3 = true;
                            }
                            else if (!flag5 && num7 > j)
                            {
                                flag3 = true;
                            }
                            if (!flag3 && quadrant.wallsHorizontal.Contains((byte)num7))
                            {
                                List <FowLos.SBlockWalls> .Enumerator enumerator2 = quadrant.viewBlockArrayFinal.GetEnumerator();
                                while (enumerator2.MoveNext() && !flag)
                                {
                                    FowLos.SBlockWalls      current2 = enumerator2.get_Current();
                                    List <FowLos.SGridWall> list2    = null;
                                    if (current2.m_wallsHorizontal.TryGetValue((byte)num7, ref list2))
                                    {
                                        int count2 = list2.get_Count();
                                        int num8   = 0;
                                        while (num8 < count2 && !flag)
                                        {
                                            FowLos.SGridWall sGridWall3 = list2.get_Item(num8);
                                            if (bDrawDebugLines)
                                            {
                                                if (FowLos.SegmentIntersect(aa, vInt2, sGridWall3.m_start, sGridWall3.m_end, ref zero))
                                                {
                                                    flag = true;
                                                }
                                                else if (FowLos.SegmentIntersect(aa, bb, sGridWall3.m_start, sGridWall3.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb2, sGridWall3.m_start, sGridWall3.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb3, sGridWall3.m_start, sGridWall3.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb4, sGridWall3.m_start, sGridWall3.m_end, ref zero))
                                                {
                                                    flag = true;
                                                }
                                            }
                                            else if (FowLos.SegmentIntersect(aa, vInt2, sGridWall3.m_start, sGridWall3.m_end))
                                            {
                                                flag = true;
                                            }
                                            else if (FowLos.SegmentIntersect(aa, bb, sGridWall3.m_start, sGridWall3.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb2, sGridWall3.m_start, sGridWall3.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb3, sGridWall3.m_start, sGridWall3.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb4, sGridWall3.m_start, sGridWall3.m_end, ref zero))
                                            {
                                                flag = true;
                                            }
                                            num8++;
                                        }
                                    }
                                }
                            }
                        }
                        num4++;
                    }
                    if (!flag)
                    {
                        setCellVisible.SetVisible(vInt, camp, true);
                    }
                }
                IL_6DD :;
            }
        }
    }
 public void ExploreCellsInternal <TSetCellVisible>(ref TSetCellVisible setCellVisible, VInt2 newSurfPos, VInt3 unitLoc, int surfSightRange, GameFowManager pFowMgr, COM_PLAYERCAMP camp, FowLos.EViewExploringMode ViewExploringMode, bool bDrawDebugLines) where TSetCellVisible : ISetCellVisible
 {
     if (pFowMgr == null || pFowMgr.m_pFieldObj == null)
     {
         return;
     }
     if (ViewExploringMode != FowLos.EViewExploringMode.EViewExploringMode_ShadowCast)
     {
         if (ViewExploringMode == FowLos.EViewExploringMode.EViewExploringMode_DistOnly)
         {
             for (int i = -surfSightRange - 1; i <= surfSightRange + 1; i++)
             {
                 for (int j = -surfSightRange - 1; j <= surfSightRange + 1; j++)
                 {
                     VInt2 b     = new VInt2(i, j);
                     VInt2 inPos = newSurfPos + b;
                     if (pFowMgr.IsInsideSurface(inPos.x, inPos.y) && b.sqrMagnitude < surfSightRange * surfSightRange)
                     {
                         setCellVisible.SetVisible(inPos, camp, true);
                     }
                 }
             }
         }
         else if (ViewExploringMode != FowLos.EViewExploringMode.EViewExploringMode_WatchTower && ViewExploringMode == FowLos.EViewExploringMode.EViewExploringMode_RayCast)
         {
             int sightSqr = surfSightRange * surfSightRange;
             int num      = newSurfPos.x - surfSightRange;
             int num2     = newSurfPos.x + surfSightRange;
             int num3     = newSurfPos.y - surfSightRange;
             int num4     = newSurfPos.y + surfSightRange;
             num  = Mathf.Clamp(num, 0, pFowMgr.m_pFieldObj.NumX - 1);
             num2 = Mathf.Clamp(num2, 0, pFowMgr.m_pFieldObj.NumX - 1);
             num3 = Mathf.Clamp(num3, 0, pFowMgr.m_pFieldObj.NumY - 1);
             num4 = Mathf.Clamp(num4, 0, pFowMgr.m_pFieldObj.NumY - 1);
             byte viewBlockId = pFowMgr.m_pFieldObj.LevelGrid.GetGridCell(newSurfPos).m_viewBlockId;
             FieldObj.SViewBlockAttr sViewBlockAttr = default(FieldObj.SViewBlockAttr);
             pFowMgr.m_pFieldObj.QueryAttr(newSurfPos, out sViewBlockAttr);
             FowLos.CRaycastQuadrant cRaycastQuadrant = new FowLos.CRaycastQuadrant();
             cRaycastQuadrant.min = new VInt2(num, num3);
             cRaycastQuadrant.max = new VInt2(num2, num4);
             if (pFowMgr.m_pFieldObj.ViewBlockArrayImpl != null)
             {
                 List <FowLos.SBlockWalls> .Enumerator enumerator = pFowMgr.m_pFieldObj.ViewBlockArrayImpl.GetEnumerator();
                 while (enumerator.MoveNext())
                 {
                     FowLos.SBlockWalls current = enumerator.get_Current();
                     int areaId = (int)current.m_areaId;
                     DebugHelper.Assert(areaId != 0);
                     FieldObj.SViewBlockAttr sViewBlockAttr2;
                     if (((int)viewBlockId != areaId || sViewBlockAttr.BlockType != 1) && (pFowMgr.m_pFieldObj.GrassBlockView || !pFowMgr.m_pFieldObj.ViewBlockAttrMap.TryGetValue((byte)areaId, ref sViewBlockAttr2) || sViewBlockAttr2.BlockType != 1) && this.ValidateViewBlock(current, cRaycastQuadrant.min.x, cRaycastQuadrant.max.x, cRaycastQuadrant.min.y, cRaycastQuadrant.max.y))
                     {
                         cRaycastQuadrant.viewBlockArrayFinal.Add(current);
                         Dictionary <byte, List <FowLos.SGridWall> > .Enumerator enumerator2 = current.m_wallsHorizontal.GetEnumerator();
                         while (enumerator2.MoveNext())
                         {
                             List <byte> wallsHorizontal = cRaycastQuadrant.wallsHorizontal;
                             KeyValuePair <byte, List <FowLos.SGridWall> > current2 = enumerator2.get_Current();
                             BaseAlgorithm.AddUniqueItem <byte>(wallsHorizontal, current2.get_Key());
                         }
                         enumerator2 = current.m_wallsVertical.GetEnumerator();
                         while (enumerator2.MoveNext())
                         {
                             List <byte> wallsVertical = cRaycastQuadrant.wallsVertical;
                             KeyValuePair <byte, List <FowLos.SGridWall> > current3 = enumerator2.get_Current();
                             BaseAlgorithm.AddUniqueItem <byte>(wallsVertical, current3.get_Key());
                         }
                     }
                 }
                 this.RaycastCheck <TSetCellVisible>(pFowMgr, cRaycastQuadrant, newSurfPos, unitLoc, sightSqr, camp, bDrawDebugLines, viewBlockId, ref setCellVisible);
             }
             cRaycastQuadrant.Clear();
         }
     }
 }