Пример #1
0
    public bool ExploreCellsFast(VInt3 location, int surfSightRange, GameFowManager pFowMgr, FieldObj inFieldObj, COM_PLAYERCAMP camp, bool bStaticExplore, bool bDistOnly)
    {
        if (pFowMgr == null || inFieldObj == null)
        {
            return(false);
        }
        VInt2 vInt = VInt2.zero;

        pFowMgr.WorldPosToGrid(location, out vInt.x, out vInt.y);
        FieldObj.SViewBlockAttr sViewBlockAttr = default(FieldObj.SViewBlockAttr);
        if (inFieldObj.QueryAttr(vInt, out sViewBlockAttr) && sViewBlockAttr.BlockType == 2)
        {
            VInt2 zero = VInt2.zero;
            if (inFieldObj.FindNearestGrid(vInt, location, FieldObj.EViewBlockType.Brick, true, 3, null, out zero))
            {
                vInt = zero;
            }
        }
        if (bStaticExplore)
        {
            FowLos.TraverseStaticSurCell(surfSightRange, vInt.x, vInt.y, inFieldObj.NumX, inFieldObj.NumY, camp);
        }
        else
        {
            FowLos.TraverseSurCell(surfSightRange, vInt.x, vInt.y, inFieldObj.NumX, inFieldObj.NumY, camp, bDistOnly);
        }
        return(true);
    }
Пример #2
0
        public static bool CheckGrassAttaching(ref VInt3 newPos)
        {
            FieldObj pFieldObj = Singleton <GameFowManager> .instance.m_pFieldObj;
            VInt3    vInt      = new VInt3(newPos.x, newPos.z, 0);
            VInt2    zero      = VInt2.zero;

            pFieldObj.LevelGrid.WorldPosToGrid(vInt, out zero.x, out zero.y);
            FieldObj.SViewBlockAttr sViewBlockAttr = default(FieldObj.SViewBlockAttr);
            pFieldObj.QueryAttr(zero, out sViewBlockAttr);
            if (sViewBlockAttr.BlockType == 0 && pFieldObj.FindNearestGrid(zero, vInt, FieldObj.EViewBlockType.Grass, false, 1, null, out zero))
            {
                pFieldObj.LevelGrid.GridToWorldPos(zero.x, zero.y, out vInt);
                int num = MonoSingleton <GlobalConfig> .instance.GrassEyeAbsorbDist;
                num += pFieldObj.PaneX / 2;
                if (vInt.x + num > newPos.x && vInt.x - num < newPos.x && vInt.y + num > newPos.z && vInt.y - num < newPos.z)
                {
                    newPos = new VInt3(vInt.x, newPos.y, vInt.y);
                    return(true);
                }
            }
            return(false);
        }
Пример #3
0
 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();
         }
     }
 }
    public bool TryLoad(FieldObj inFieldObj)
    {
        DebugHelper.Assert(inFieldObj != null);
        if (inFieldObj.fowOfflineData == null || inFieldObj.fowOfflineData.Length == 0)
        {
            return(false);
        }
        MemoryStream memoryStream = new MemoryStream(inFieldObj.fowOfflineData);
        BinaryReader binaryReader = new BinaryReader(memoryStream);
        uint         num          = binaryReader.ReadUInt32();
        uint         num2         = binaryReader.ReadUInt32();
        uint         num3         = binaryReader.ReadUInt32();

        if (num != this.VerificationCode || this.Version != num2)
        {
            return(false);
        }
        int num4 = inFieldObj.NumX * inFieldObj.NumY;
        int num5 = binaryReader.ReadInt32();

        if (num4 != num5)
        {
            return(false);
        }
        GameFowManager.InitSurfCellsArray(num4);
        GameFowManager.InitLevelGrid(num4, inFieldObj.LevelGrid.GridInfo.CellNumX, inFieldObj.LevelGrid.GridInfo.CellNumY, inFieldObj.LevelGrid.GridInfo.CellSizeX, inFieldObj.LevelGrid.GridInfo.CellSizeY, inFieldObj.LevelGrid.GridInfo.GridPos.x, inFieldObj.LevelGrid.GridInfo.GridPos.y);
        int num6 = 0;

        inFieldObj.UnrealToGridX(Horizon.QueryGlobalSight(), out num6);
        for (int i = 0; i < num4; i++)
        {
            int gridCellX = inFieldObj.LevelGrid.GetGridCellX(i);
            int gridCellY = inFieldObj.LevelGrid.GetGridCellY(i);
            int xMin      = Mathf.Max(0, gridCellX - num6);
            int xMax      = Mathf.Min(inFieldObj.NumX - 1, gridCellX + num6);
            int yMin      = Mathf.Max(0, gridCellY - num6);
            int yMax      = Mathf.Min(inFieldObj.NumY - 1, gridCellY + num6);
            int num7      = binaryReader.ReadInt32();
            if (num7 > 0)
            {
                byte[] array = new byte[num7];
                binaryReader.Read(array, 0, num7);
                uint[] array2 = FOGameFowOfflineSerializer.ByteArrToUIntArr(array);
                DebugHelper.Assert(array2.Length == num7 / 4);
                GameFowManager.InitSurfCell(i, xMin, xMax, yMin, yMax, true);
                IntPtr intPtr = Marshal.AllocHGlobal(num7);
                Marshal.Copy(array, 0, intPtr, num7);
                GameFowManager.SetSurfCellData(i, intPtr);
                Marshal.FreeHGlobal(intPtr);
            }
            else
            {
                GameFowManager.InitSurfCell(i, xMin, xMax, yMin, yMax, false);
            }
            FieldObj.SViewBlockAttr sViewBlockAttr = default(FieldObj.SViewBlockAttr);
            inFieldObj.QueryAttr(gridCellX, gridCellY, out sViewBlockAttr);
            GameFowManager.InitLevelGridCell(i, (int)sViewBlockAttr.BlockType, (int)sViewBlockAttr.LightType);
        }
        int num8 = binaryReader.ReadInt32();

        if (num8 != 987654321)
        {
        }
        binaryReader.Close();
        memoryStream.Close();
        return(true);
    }