NScumm.Scumm.ScummEngine.AreBoxesNeighbors C# (CSharp) Метод

AreBoxesNeighbors() защищенный Метод

Check if two boxes are neighbors.
protected AreBoxesNeighbors ( byte box1nr, byte box2nr ) : bool
box1nr byte
box2nr byte
Результат bool
        protected virtual bool AreBoxesNeighbors(byte box1nr, byte box2nr)
        {
            Point tmp;

            if (GetBoxFlags(box1nr).HasFlag(BoxFlags.Invisible) || GetBoxFlags(box2nr).HasFlag(BoxFlags.Invisible))
                return false;

            //System.Diagnostics.Debug.Assert(_game.version >= 3);
            var box2 = GetBoxCoordinates(box1nr);
            var box = GetBoxCoordinates(box2nr);

            // Roughly, the idea of this algorithm is to search for sies of the given
            // boxes that touch each other.
            // In order to keep te code simple, we only match the upper sides;
            // then, we "rotate" the box coordinates four times each, for a total
            // of 16 comparisions.
            for (int j = 0; j < 4; j++)
            {
                for (int k = 0; k < 4; k++)
                {
                    // Are the "upper" sides of the boxes on a single vertical line
                    // (i.e. all share one x value) ?
                    if (box2.UpperRight.X == box2.UpperLeft.X && box.UpperLeft.X == box2.UpperLeft.X && box.UpperRight.X == box2.UpperLeft.X)
                    {
                        bool swappedBox2 = false, swappedBox1 = false;
                        if (box2.UpperRight.Y < box2.UpperLeft.Y)
                        {
                            swappedBox2 = true;
                            ScummHelper.Swap(ref box2.UpperRight.Y, ref box2.UpperLeft.Y);
                        }
                        if (box.UpperRight.Y < box.UpperLeft.Y)
                        {
                            swappedBox1 = true;
                            ScummHelper.Swap(ref box.UpperRight.Y, ref box.UpperLeft.Y);
                        }
                        if (box.UpperRight.Y < box2.UpperLeft.Y ||
                            box.UpperLeft.Y > box2.UpperRight.Y ||
                            ((box.UpperLeft.Y == box2.UpperRight.Y ||
                            box.UpperRight.Y == box2.UpperLeft.Y) && box2.UpperRight.Y != box2.UpperLeft.Y && box.UpperLeft.Y != box.UpperRight.Y))
                        {
                        }
                        else
                        {
                            return true;
                        }

                        // Swap back if necessary
                        if (swappedBox2)
                        {
                            ScummHelper.Swap(ref box2.UpperRight.Y, ref box2.UpperLeft.Y);
                        }
                        if (swappedBox1)
                        {
                            ScummHelper.Swap(ref box.UpperRight.Y, ref box.UpperLeft.Y);
                        }
                    }

                    // Are the "upper" sides of the boxes on a single horizontal line
                    // (i.e. all share one y value) ?
                    if (box2.UpperRight.Y == box2.UpperLeft.Y && box.UpperLeft.Y == box2.UpperLeft.Y && box.UpperRight.Y == box2.UpperLeft.Y)
                    {
                        var swappedBox2 = false;
                        var swappedBox1 = false;
                        if (box2.UpperRight.X < box2.UpperLeft.X)
                        {
                            swappedBox2 = true;
                            ScummHelper.Swap(ref box2.UpperRight.X, ref box2.UpperLeft.X);
                        }
                        if (box.UpperRight.X < box.UpperLeft.X)
                        {
                            swappedBox1 = true;
                            ScummHelper.Swap(ref box.UpperRight.X, ref box.UpperLeft.X);
                        }
                        if (box.UpperRight.X < box2.UpperLeft.X ||
                            box.UpperLeft.X > box2.UpperRight.X ||
                            ((box.UpperLeft.X == box2.UpperRight.X ||
                            box.UpperRight.X == box2.UpperLeft.X) && box2.UpperRight.X != box2.UpperLeft.X && box.UpperLeft.X != box.UpperRight.X))
                        {

                        }
                        else
                        {
                            return true;
                        }

                        // Swap back if necessary
                        if (swappedBox2)
                        {
                            ScummHelper.Swap(ref box2.UpperRight.X, ref box2.UpperLeft.X);
                        }
                        if (swappedBox1)
                        {
                            ScummHelper.Swap(ref box.UpperRight.X, ref box.UpperLeft.X);
                        }
                    }

                    // "Rotate" the box coordinates
                    tmp = box2.UpperLeft;
                    box2.UpperLeft = box2.UpperRight;
                    box2.UpperRight = box2.LowerRight;
                    box2.LowerRight = box2.LowerLeft;
                    box2.LowerLeft = tmp;
                }

                // "Rotate" the box coordinates
                tmp = box.UpperLeft;
                box.UpperLeft = box.UpperRight;
                box.UpperRight = box.LowerRight;
                box.LowerRight = box.LowerLeft;
                box.LowerLeft = tmp;
            }

            return false;
        }
ScummEngine