Example #1
0
        public static MapPackage GetMap(int X, int Y, int W, int H)
        {
            if (Map.m_X == X && Map.m_Y == Y && (Map.m_Width == W && Map.m_Height == H) && (Map.m_World == Engine.m_World && Map.m_IsCached && !Map.m_QueueInvalidate))
            {
                return(Map.m_Cached);
            }
            Map.m_QueueInvalidate = false;
            if (Map.m_Cached.cells != null)
            {
                int length1 = Map.m_Cached.cells.GetLength(0);
                int length2 = Map.m_Cached.cells.GetLength(1);
                for (int index1 = 0; index1 < length1; ++index1)
                {
                    for (int index2 = 0; index2 < length2; ++index2)
                    {
                        ArrayList arrayList = Map.m_Cached.cells[index1, index2];
                        if (arrayList != null)
                        {
                            int count = arrayList.Count;
                            for (int index3 = 0; index3 < count; ++index3)
                            {
                                ((IDisposable)arrayList[index3]).Dispose();
                            }
                        }
                    }
                }
            }
            Map.m_X      = X;
            Map.m_Y      = Y;
            Map.m_Width  = W;
            Map.m_Height = H;
            Map.m_World  = Engine.m_World;
            if (Map.m_StrongReferences == null)
            {
                Map.m_StrongReferences = new MapBlock[W * H];
            }
            int length3 = W << 3;
            int length4 = H << 3;

            if (Map.m_CellPool == null)
            {
                Map.m_CellPool = new ArrayList[length3, length4];
                for (int index1 = 0; index1 < length3; ++index1)
                {
                    for (int index2 = 0; index2 < length4; ++index2)
                    {
                        Map.m_CellPool[index1, index2] = new ArrayList(4);
                    }
                }
            }
            else
            {
                for (int index1 = 0; index1 < length3; ++index1)
                {
                    for (int index2 = 0; index2 < length4; ++index2)
                    {
                        ArrayList arrayList = Map.m_CellPool[index1, index2];
                        for (int index3 = 0; index3 < arrayList.Count; ++index3)
                        {
                            AgentCell agentCell = arrayList[index3] as AgentCell;
                            if (agentCell != null)
                            {
                                agentCell.Owner = (ArrayList)null;
                            }
                        }
                        arrayList.Clear();
                    }
                }
            }
            if (Map.m_LandTiles == null)
            {
                Map.m_LandTiles = new LandTile[length3, length4];
                for (int index1 = 0; index1 < length3; ++index1)
                {
                    for (int index2 = 0; index2 < length4; ++index2)
                    {
                        Map.m_LandTiles[index1, index2]   = new LandTile();
                        Map.m_LandTiles[index1, index2].x = index1;
                        Map.m_LandTiles[index1, index2].y = index2;
                    }
                }
            }
            if (Map.m_IndexPool == null)
            {
                Map.m_IndexPool = new byte[length3, length4];
            }
            if (Map.m_FlagPool == null)
            {
                Map.m_FlagPool = new byte[length3, length4];
            }
            ArrayList[,] arrayListArray = Map.m_CellPool;
            IComparer comparer = TileSorter.Comparer;

            Engine.Multis.Update(new MapPackage()
            {
                cells     = arrayListArray,
                CellX     = X << 3,
                    CellY = Y << 3
            });
            int        num1     = Engine.m_World;
            TileMatrix matrix   = Map.GetMatrix(num1);
            Viewport   viewport = World.Viewport;
            int        num2     = 0;
            int        x1       = X;

            while (num2 < W)
            {
                int num3 = 0;
                int y1   = Y;
                while (num3 < H)
                {
                    MapBlock block = matrix.GetBlock(x1, y1);
                    Map.m_StrongReferences[num3 * W + num2] = block;
                    HuedTile[][][] huedTileArray1 = block == null ? matrix.EmptyStaticBlock : block.m_StaticTiles;
                    if (block != null)
                    {
                        Tile[] tileArray = block.m_LandTiles;
                    }
                    else
                    {
                        Tile[] invalidLandBlock = matrix.InvalidLandBlock;
                    }
                    int index1 = 0;
                    int x2     = x1 << 3;
                    int index2 = num2 << 3;
                    while (index1 < 8)
                    {
                        int index3 = 0;
                        int y2     = y1 << 3;
                        int index4 = num3 << 3;
                        while (index3 < 8)
                        {
                            HuedTile[] huedTileArray2 = huedTileArray1[index1][index3];
                            for (int influence = 0; influence < huedTileArray2.Length; ++influence)
                            {
                                arrayListArray[index2, index4].Add((object)StaticItem.Instantiate(huedTileArray2[influence], influence, x2 * matrix.Height + y2 | influence << 25));
                            }
                            LandTile landTile = viewport.GetLandTile(x2, y2, num1);
                            landTile.x = index2;
                            landTile.y = index4;
                            arrayListArray[index2, index4].Add((object)landTile);
                            ++index3;
                            ++y2;
                            ++index4;
                        }
                        ++index1;
                        ++x2;
                        ++index2;
                    }
                    ++num3;
                    ++y1;
                }
                ++num2;
                ++x1;
            }
            int num4 = X << 3;
            int num5 = Y << 3;

            foreach (Item obj in World.Items.Values)
            {
                if (obj.InWorld && obj.Visible && !obj.IsMulti)
                {
                    int index1 = obj.X - num4;
                    int index2 = obj.Y - num5;
                    if (index1 >= 0 && index1 < length3 && (index2 >= 0 && index2 < length4))
                    {
                        AgentCell agentCell = obj.AcquireViewportCell();
                        arrayListArray[index1, index2].Add((object)agentCell);
                        agentCell.Owner = arrayListArray[index1, index2];
                    }
                }
            }
            foreach (Mobile mobile in World.Mobiles.Values)
            {
                if (mobile.InWorld && mobile.Visible)
                {
                    int index1 = mobile.X - num4;
                    int index2 = mobile.Y - num5;
                    if (index1 >= 0 && index1 < length3 && (index2 >= 0 && index2 < length4))
                    {
                        AgentCell agentCell = mobile.AcquireViewportCell();
                        arrayListArray[index1, index2].Add((object)agentCell);
                        agentCell.Owner = arrayListArray[index1, index2];
                    }
                }
            }
            for (int index1 = 0; index1 < length3; ++index1)
            {
                for (int index2 = 0; index2 < length4; ++index2)
                {
                    ArrayList arrayList = arrayListArray[index1, index2];
                    if (arrayList.Count > 1)
                    {
                        arrayList.Sort(comparer);
                    }
                }
            }
            MapPackage mapPackage = new MapPackage();

            mapPackage.cells = arrayListArray;
            mapPackage.CellX = X << 3;
            mapPackage.CellY = Y << 3;
            Map.m_Cached     = mapPackage;
            Map.m_IsCached   = true;
            for (int index = -1; index <= H; ++index)
            {
                Engine.QueueMapLoad(X - 1, Y + index, matrix);
            }
            for (int index = 0; index < W; ++index)
            {
                Engine.QueueMapLoad(X + index, Y - 1, matrix);
                Engine.QueueMapLoad(X + index, Y + H, matrix);
            }
            for (int index = -1; index <= H; ++index)
            {
                Engine.QueueMapLoad(X + W, Y + index, matrix);
            }
            return(mapPackage);
        }
Example #2
0
        private static unsafe void Load(int x, int y, int w, int h, int world, Texture tex)
        {
            if (GRadar.m_Colors == null)
            {
                GRadar.LoadColors();
            }
            if (GRadar.m_StrongReferences == null || GRadar.m_StrongReferences.Length != w * h)
            {
                GRadar.m_StrongReferences = new MapBlock[w * h];
            }
            if (GRadar.m_Guarded == null || GRadar.m_Guarded.Length != w * h * 64)
            {
                GRadar.m_Guarded = new BitArray(w * h * 64);
            }
            else
            {
                GRadar.m_Guarded.SetAll(false);
            }
            Region[] guardedRegions = Region.GuardedRegions;
            int      num1           = x * 8;
            int      num2           = y * 8;
            int      num3           = w * 8;
            int      num4           = h * 8;

            for (int index1 = 0; index1 < guardedRegions.Length; ++index1)
            {
                Region      region = guardedRegions[index1];
                RegionWorld world1 = region.World;
                bool        flag   = false;
                switch (world1)
                {
                case RegionWorld.Britannia:
                    flag = world == 0 || world == 1;
                    break;

                case RegionWorld.Felucca:
                    flag = world == 0;
                    break;

                case RegionWorld.Trammel:
                    flag = world == 1;
                    break;

                case RegionWorld.Ilshenar:
                    flag = world == 2;
                    break;

                case RegionWorld.Malas:
                    flag = world == 3;
                    break;

                case RegionWorld.Tokuno:
                    flag = world == 4;
                    break;
                }
                if (flag)
                {
                    int num5 = region.X - num1;
                    int num6 = region.Y - num2;
                    if (num5 < num3 && num6 < num4 && (num5 > -region.Width && num6 > -region.Height))
                    {
                        int num7 = num5 + region.Width;
                        int num8 = num6 + region.Height;
                        if (num5 < 0)
                        {
                            num5 = 0;
                        }
                        if (num6 < 0)
                        {
                            num6 = 0;
                        }
                        for (int index2 = num5; index2 < num7 && index2 < num3; ++index2)
                        {
                            for (int index3 = num6; index3 < num8 && index3 < num4; ++index3)
                            {
                                GRadar.m_Guarded[index3 * num3 + index2] = true;
                            }
                        }
                    }
                }
            }
            TileMatrix matrix   = Map.GetMatrix(world);
            LockData   lockData = tex.Lock(LockFlags.WriteOnly);
            int        num9     = lockData.Pitch >> 1;

            fixed(short *numPtr1 = GRadar.m_Colors)
            {
                for (int index1 = 0; index1 < w; ++index1)
                {
                    short *numPtr2 = (short *)((IntPtr)lockData.pvSrc + (index1 << 3) * 2);
                    for (int index2 = 0; index2 < h; ++index2)
                    {
                        MapBlock block = matrix.GetBlock(x + index1, y + index2);
                        GRadar.m_StrongReferences[index2 * w + index1] = block;
                        HuedTile[][][] huedTileArray = block == null ? matrix.EmptyStaticBlock : block.m_StaticTiles;
                        Tile[]         tileArray     = block == null ? matrix.InvalidLandBlock : block.m_LandTiles;
                        int            index3        = 0;
                        int            num5          = 0;
                        while (index3 < 8)
                        {
                            for (int index4 = 0; index4 < 8; ++index4)
                            {
                                int num6   = -255;
                                int num7   = -255;
                                int index5 = 0;
                                int num8   = 0;
                                for (int index6 = 0; index6 < huedTileArray[index4][index3].Length; ++index6)
                                {
                                    HuedTile huedTile = huedTileArray[index4][index3][index6];
                                    int      num10    = 16384 + (int)huedTile.itemId;
                                    switch (num10)
                                    {
                                    case 16385:
                                    case 22422:
                                    case 24996:
                                    case 24984:
                                    case 25020:
                                    case 24985:
                                        goto case 16385;

                                    default:
                                        int num11 = (int)huedTile.z;
                                        int num12 = num11 + (int)Map.GetItemHeight(huedTile.itemId);
                                        if (num12 > num6 || num11 > num7 && num12 >= num6)
                                        {
                                            num6   = num12;
                                            num7   = num11;
                                            index5 = num10;
                                            num8   = (int)huedTile.hueId;
                                            goto case 16385;
                                        }
                                        else
                                        {
                                            goto case 16385;
                                        }
                                    }
                                }
                                if ((int)tileArray[num5 + index4].z > num6 && tileArray[num5 + index4].Visible)
                                {
                                    index5 = (int)tileArray[num5 + index4].landId;
                                    num8   = 0;
                                }
                                numPtr2[index4] = num8 != 0 ? (short)Hues.Load(num8 & 16383 | 32768).Pixel((ushort)numPtr1[index5]) : numPtr1[index5];
                            }
                            numPtr2 += num9;
                            ++index3;
                            num5 += 8;
                        }
                    }
                }
                ArrayList items = Engine.Multis.Items;

                for (int index1 = 0; index1 < items.Count; ++index1)
                {
                    Item obj = (Item)items[index1];
                    if (obj.InWorld)
                    {
                        CustomMultiEntry customMulti = CustomMultiLoader.GetCustomMulti(obj.Serial, obj.Revision);
                        Multi            multi       = (Multi)null;
                        if (customMulti != null)
                        {
                            multi = customMulti.Multi;
                        }
                        if (multi == null)
                        {
                            multi = obj.Multi;
                        }
                        if (multi != null)
                        {
                            short[][] radar = multi.Radar;
                            if (radar != null)
                            {
                                int xMin;
                                int yMin;
                                int xMax;
                                int yMax;
                                multi.GetBounds(out xMin, out yMin, out xMax, out yMax);
                                int index2 = 0;
                                int num5   = obj.Y - (y << 3) + yMin;
                                while (index2 < radar.Length)
                                {
                                    if (num5 >= 0 && num5 < h << 3)
                                    {
                                        short * numPtr2  = (short *)((IntPtr)lockData.pvSrc + (num5 * num9) * 2);
                                        short[] numArray = radar[index2];
                                        int     index3   = 0;
                                        int     index4   = obj.X - (x << 3) + xMin;
                                        while (index3 < numArray.Length)
                                        {
                                            if (index4 >= 0 && index4 < w << 3 && (int)numArray[index3] != 0)
                                            {
                                                numPtr2[index4] = numPtr1[16384 + (int)numArray[index3]];
                                            }
                                            ++index3;
                                            ++index4;
                                        }
                                    }
                                    ++index2;
                                    ++num5;
                                }
                            }
                        }
                    }
                }
            }

            tex.Unlock();
        }