Exemplo n.º 1
0
        private DesignItemCol GetFilteredItems(DesignItemCol items, bool foundation, bool hues)
        {
            DesignItemCol buildItems = new DesignItemCol();

            for (int i = 0; i < items.Count; ++i)
            {
                if (!foundation && items[i].Level == 0)
                {
                    continue;
                }

                int z     = foundation ? items[i].Z : (items[i].Z - 7);
                int index = items[i].ItemID;
                int x     = items[i].X;
                int y     = items[i].Y;
                int hue   = 0;

                if (hues)
                {
                    hue = items[i].Hue;
                }

                buildItems.Add(new DesignItem(index, x, y, z, 0, hue));
            }

            return(buildItems);
        }
Exemplo n.º 2
0
        private void ExtractFrozenItems(Rect2D rect, string mapName, bool hued)
        {
            Map map = GetMapByName(mapName);

            if (map == null)
            {
                MessageBox.Show("Failed to extract the frozen items from the map " + mapName);
            }
            else
            {
                int xCount = rect.TopX + rect.Width;
                int yCount = rect.TopY + rect.Height;

                for (int x = rect.TopX; x < xCount; ++x)
                {
                    for (int y = rect.TopY; y < yCount; ++y)
                    {
                        HuedTile[] tiles = map.Tiles.GetStaticTiles(x, y);

                        if (tiles == null || tiles.Length == 0)
                        {
                            continue;
                        }

                        for (int i = 0; i < tiles.Length; ++i)
                        {
                            HuedTile tile = tiles[i];

                            if (_useMinZ && tile.Z < _minZ)
                            {
                                continue;
                            }
                            else if (_useMaxZ && tile.Z > _maxZ)
                            {
                                continue;
                            }

                            DesignItem item = new DesignItem();

                            item.ItemID = (short)(tile.ID ^ 0x4000);
                            item.X      = x;
                            item.Y      = y;
                            item.Z      = tile.Z;

                            if (hued)
                            {
                                item.Hue = (short)tile.Hue;
                            }

                            if (_items.IndexOf(item) == -1)
                            {
                                _items.Add(item);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public override DesignData ImportDesign()
        {
            string filename = GetImportFileName();

            if (!File.Exists(filename))
            {
                return(null);
            }

            DesignData    design      = new DesignData();
            DesignItemCol designItems = new DesignItemCol();

            StreamReader reader = new StreamReader(File.OpenRead(filename));

            string[] TextArr;
            string   Text;

            char[] Separator = { ' ' };

            try
            {
                while (reader.Peek() > -1)
                {
                    Text = reader.ReadLine();

                    if (IsMultiBlock(Text))
                    {
                        TextArr = Text.Split(Separator);

                        DesignItem designItem = new DesignItem();
                        designItem.ItemID = short.Parse(TextArr[0]);
                        designItem.X      = int.Parse(TextArr[1]);
                        designItem.Y      = int.Parse(TextArr[2]);
                        designItem.Z      = int.Parse(TextArr[3]);

                        designItems.Add(designItem);
                    }
                }

                design.ImportItems(designItems, true, false);
            }
            catch
            {
            }
            finally
            {
                reader.Close();
            }

            return(design);
        }
Exemplo n.º 4
0
        // import design from extracted design data
        public void ImportItems(DesignItemCol items, bool calculateOffsets, bool foundation)
        {
            if (items.Count == 0)
            {
                return;
            }

            _items.Clear();

            for (int i = 0; i < items.Count; ++i)
            {
                DesignItem item = items[i];

                int xoffset = 0;
                int yoffset = 0;
                int zoffset = 0;

                if (!foundation)
                {
                    item.Z += LevelZ[1];
                }

                if (calculateOffsets)
                {
                    xoffset = item.X - items.OriginX;
                    yoffset = item.Y - items.OriginY;
                    zoffset = item.Z - items.OriginZ;
                }
                else
                {
                    xoffset = item.X;
                    yoffset = item.Y;
                    zoffset = item.Z;
                }

                _items.Add(new DesignItem(item.ItemID, xoffset, yoffset, zoffset, GetZLevel(zoffset), item.Hue));
            }

            UpdateSize();
        }
Exemplo n.º 5
0
        public ArrayList ImportDesigns()
        {
            ArrayList designs  = new ArrayList();
            string    filename = GetImportFileName();

            if (filename == null || !File.Exists(filename))
            {
                return(designs);
            }

            try
            {
                using (StreamReader reader = new StreamReader(File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read)))
                {
                    string        line;
                    char[]        delimiter   = new char[] { '\t' };
                    DesignData    design      = null;
                    DesignItemCol designItems = new DesignItemCol();

                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line.Length == 0)
                        {
                            continue;
                        }

                        string[] Values = line.Split(delimiter);

                        if (Values.Length > 5)                        // this is the multi header line
                        {
                            if (design != null && designItems.Count > 0)
                            {
                                design.ImportItems(designItems, true, true);
                                designs.Add(design);
                                design = null;
                                designItems.Clear();
                            }

                            design = new DesignData("Multi " + designs.Count + 1, "multicache", "misc");
                        }
                        else if (Values.Length == 5)                         // this is a multi component
                        {
                            if (design != null)
                            {
                                DesignItem item = new DesignItem();

                                item.ItemID = Convert.ToInt16(Values[0]);
                                item.X      = Convert.ToInt32(Values[2]);
                                item.Y      = Convert.ToInt32(Values[3]);
                                item.Z      = Convert.ToInt32(Values[4]);

                                if (item.ItemID != 1)
                                {
                                    designItems.Add(item);
                                }
                            }
                        }
                    }

                    reader.Close();

                    if (design != null && designItems.Count > 0)
                    {
                        design.ImportItems(designItems, true, true);
                        designs.Add(design);
                    }
                }
            }
            catch
            {
            }

            return(designs);
        }
Exemplo n.º 6
0
        public override DesignData ImportDesign()
        {
            string filename = GetImportFileName();

            if (!File.Exists(filename))
            {
                return(null);
            }

            DesignData    design      = new DesignData();
            DesignItemCol designItems = new DesignItemCol();

            char[] Separator = { ' ' };

            try
            {
                XmlDocument document = new XmlDocument();
                document.Load(filename);

                XmlNodeList itemNodes = document.SelectNodes("//export/tile");

                for (int i = 0; i < itemNodes.Count; ++i)
                {
                    XmlNode node  = itemNodes[i];
                    string  Value = null;

                    int id  = 0;
                    int x   = 0;
                    int y   = 0;
                    int z   = 0;
                    int hue = 0;

                    Value = node.Attributes.GetNamedItem("id").Value;

                    if (Value != null && Value.Length > 0)
                    {
                        id = int.Parse(Value);
                    }

                    Value = node.Attributes.GetNamedItem("x").Value;

                    if (Value != null && Value.Length > 0)
                    {
                        x = int.Parse(Value);
                    }

                    Value = node.Attributes.GetNamedItem("y").Value;

                    if (Value != null && Value.Length > 0)
                    {
                        y = int.Parse(Value);
                    }

                    Value = node.Attributes.GetNamedItem("z").Value;

                    if (Value != null && Value.Length > 0)
                    {
                        z = int.Parse(Value);
                    }

                    Value = node.Attributes.GetNamedItem("hue").Value;

                    if (Value != null && Value.Length > 0)
                    {
                        hue = int.Parse(Value);
                    }

                    designItems.Add(new DesignItem(id, x, y, z, GetZLevel(z), hue));
                }

                design.ImportItems(designItems, true, false);
            }
            catch (Exception e)
            {
                design = null;
                MessageBox.Show("The import failed due to the following error.\n" + e.Message);
            }

            return(design);
        }