Beispiel #1
0
        /// <summary>
        ///     Generates the roof through the boxserver
        /// </summary>
        /// <param name="height">The height at which generation should happen</param>
        /// <param name="hue">The hue for the items</param>
        public void GenerateThroughServer(int height, int hue)
        {
            var roofIDs = new int[m_RoofImage.Width * m_RoofImage.Height];
            var fail    = false;

            // Revert any sign changes due to image processing
            for (var i = 0; i < m_RoofImage.Width * m_RoofImage.Height; i++)
            {
                // Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert
                if (m_RoofImage.Data[i] < 0)
                {
                    m_RoofImage.Data[i] = -m_RoofImage.Data[i];
                }
                // Issue 10 - End
            }

            // Calculate the roof ids
            for (var i = 0; i < m_RoofImage.Width * m_RoofImage.Height; i++)
            {
                // Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert
                if (m_RoofImage.Data[i] == 0)
                // Issue 10 - End
                {
                    roofIDs[i] = 0;
                }
                else
                {
                    var flags = RoofingHelper.GetFlags(MakeLine(i - m_RoofImage.Width), MakeLine(i), MakeLine(i + m_RoofImage.Width));
                    roofIDs[i] = TileSet.FindID(flags);

                    if (roofIDs[i] == 0)
                    {
                        // Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert
                        m_RoofImage.Data[i] = -m_RoofImage.Data[i];
                        // Issue 10 - End
                        fail = true;
                    }
                }
            }

            if (fail)
            {
                m_RoofImage.CreateImage();

                // Request redraw image
                if (RoofImageChanged != null)
                {
                    RoofImageChanged(this, new EventArgs());
                }

                if (MessageBox.Show(
                        Pandora.Localization.TextProvider["Roofing.MissTiles"],
                        "",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
            }

            var idFormat = hue > 0 ? "static {0} set hue " + hue : "static {0}";

            var p = 0;

            // Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert
            var items = new List <BuildItem>();

            // Issue 10 - End

            for (var y = 0; y < m_RoofImage.Height; y++)
            {
                for (var x = 0; x < m_RoofImage.Width; x++, p++)
                {
                    if (roofIDs[p] == 0)
                    {
                        continue;
                    }

                    // Build item
                    var item = new BuildItem();

                    item.Hue = hue;
                    item.ID  = roofIDs[p];

                    item.X = m_BasePoint.X + x;
                    item.Y = m_BasePoint.Y + y;
                    // Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert
                    item.Z = height + (3 * m_RoofImage.Data[p]) - 3;
                    // Issue 10 - End

                    items.Add(item);
                }
            }

            var msg = new BuildMessage();

            msg.Items = items;

            Pandora.BoxConnection.SendToServer(msg);
        }
Beispiel #2
0
        /// <summary>
        ///     Does classic generation of the roof
        /// </summary>
        /// <param name="mode">The mode for this generation</param>
        /// <param name="height">The height at which the tiling occurs</param>
        /// <param name="hue">The hue for the roof</param>
        /// <returns>True if generation is succesful</returns>
        public bool GenerateClassic(TestMode mode, int height, int hue)
        {
            var roofIDs = new int[m_RoofImage.Width * m_RoofImage.Height];
            var fail    = false;

            // Revert any sign changes due to image processing
            for (var i = 0; i < m_RoofImage.Width * m_RoofImage.Height; i++)
            {
                // Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert
                if (m_RoofImage.Data[i] < 0)
                {
                    m_RoofImage.Data[i] = -m_RoofImage.Data[i];
                }
                // Issue 10 - End
            }

            // Calculate the roof ids
            for (var i = 0; i < m_RoofImage.Width * m_RoofImage.Height; i++)
            {
                // Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert
                if (m_RoofImage.Data[i] == 0)
                // Issue 10 - End
                {
                    roofIDs[i] = 0;
                }
                else
                {
                    var flags = RoofingHelper.GetFlags(MakeLine(i - m_RoofImage.Width), MakeLine(i), MakeLine(i + m_RoofImage.Width));
                    roofIDs[i] = TileSet.FindID(flags);

                    if (roofIDs[i] == 0)
                    {
                        // Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert
                        m_RoofImage.Data[i] = -m_RoofImage.Data[i];
                        // Issue 10 - End
                        fail = true;
                    }

                    if (mode != TestMode.NoTest)
                    {
                        var corner = !((flags & ~0x88878778) != 0) || !((flags & ~0x88887877) != 0) || !((flags & ~0x77878888) != 0) ||
                                     !((flags & ~0x87787888) != 0) || !((flags & ~0x87777777) != 0) || !((flags & ~0x77877777) != 0) ||
                                     !((flags & ~0x77777877) != 0) || !((flags & ~0x77777778) != 0);

                        if (mode == TestMode.Test && !corner)
                        {
                            roofIDs[i] = 0;
                        }

                        if (mode == TestMode.Rest && corner)
                        {
                            roofIDs[i] = 0;
                        }
                    }
                }
            }

            if (fail)
            {
                m_RoofImage.CreateImage();

                // Request redraw image
                if (RoofImageChanged != null)
                {
                    RoofImageChanged(this, new EventArgs());
                }

                if (MessageBox.Show(
                        Pandora.Localization.TextProvider["Roofing.MissTiles"],
                        "",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question) == DialogResult.No)
                {
                    return(false);
                }
            }

            var idFormat = hue > 0 ? "static {0} set hue " + hue : "static {0}";

            var dx = 0;
            var dy = 0;
            var p  = 0;

            var tilex = 0;
            var tiley = 0;
            var tilew = 0;
            var tileh = 0;

            var tilez  = 0;
            var tileid = 0;

            for (var y = 0; y < m_RoofImage.Height; y++)
            {
                for (var x = 0; x < m_RoofImage.Width; x++, p++)
                {
                    if (roofIDs[p] == 0)
                    {
                        continue;
                    }

                    for (dx = 1; dx + x < m_RoofImage.Width; dx++)
                    {
                        // Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert
                        if ((roofIDs[p + dx] != roofIDs[p]) || (m_RoofImage.Data[p] != m_RoofImage.Data[p + dx]))
                        // Issue 10 - End
                        {
                            break;
                        }
                    }

                    for (dy = 1; dy + y < m_RoofImage.Height; dy++)
                    {
                        if ((roofIDs[p + m_RoofImage.Width * dy] != roofIDs[p]) ||
                            // Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert
                            (m_RoofImage.Data[p] != m_RoofImage.Data[p + m_RoofImage.Width * dy]))
                        // Issue 10 - End
                        {
                            break;
                        }
                    }

                    dx--;
                    dy--;

                    // Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert
                    tilez = height + (3 * m_RoofImage.Data[p]) - 3;
                    // Issue 10 - End
                    tileid = roofIDs[p];

                    if (dx > 0 || dy > 0)
                    {
                        tilex = m_BasePoint.X + x;
                        tiley = m_BasePoint.Y + y;

                        if (dy > dx)
                        {
                            tilew = 1;
                            tileh = dy + 1;

                            while (dy >= 0)
                            {
                                roofIDs[p + m_RoofImage.Width * dy] = 0;
                                dy--;
                            }
                        }
                        else
                        {
                            tilew = dx + 1;
                            tileh = 1;

                            while (dx >= 0)
                            {
                                roofIDs[p + dx] = 0;
                                dx--;
                            }
                        }

                        x += dx;
                        p += dx;
                    }
                    else
                    {
                        tilex = m_BasePoint.X + x;
                        tiley = m_BasePoint.Y + y;
                        tilew = 1;
                        tileh = 1;
                    }

                    // Build command
                    var item = string.Format(idFormat, tileid);
                    var cmd  = string.Format("TileXYZ {0} {1} {2} {3} {4} {5}", tilex, tiley, tilew, tileh, tilez, item);
                    Pandora.SendToUO(cmd, true);
                }
            }

            return(true);
        }