예제 #1
0
 void RemoveMovementDirection(GridIndex Index, Enums.MoveDirections dir)
 {
     if (!Index.IsValid())
     {
         return;
     }
     _GridMovements[Index.X, Index.Y, Index.Z] &= (byte)~dir;
 }
예제 #2
0
 public GridIndex[] GetRight(int count)
 {
     GridIndex[] indexArray = new GridIndex[count];
     for (int i = 0; i < count; i++)
     {
         indexArray[i] = new GridIndex(1 + i, 0, 0) + this;
     }
     return(indexArray);
 }
예제 #3
0
 public GridIndex(GridIndex other)
 {
     if (other == null)
     {
         throw new ArgumentNullException("other");
     }
     X = other.X;
     Y = other.Y;
     Z = other.Z;
 }
예제 #4
0
 public GridIndex[] GetLeft(int count)
 {
     GridIndex[] indexArray = new GridIndex[count];
     for (int i = 0; i < count; i++)
     {
         indexArray[i] = new GridIndex(-1 - i, 0, 0) + this;
     }
     Array.Reverse(indexArray); // Reverse, so we always count from left to right
     return(indexArray);
 }
예제 #5
0
        public bool OtherIndexIsInDirection(GridIndex otherIndex, Enums.MoveDirections dir)
        {
            if (otherIndex == null)
            {
                return(false);
            }

            switch (dir)
            {
            case Enums.MoveDirections.Top:
                if ((otherIndex.Y - Y) > 0)
                {
                    return(true);
                }
                break;

            case Enums.MoveDirections.Bottom:
                if ((Y - otherIndex.Y) > 0)
                {
                    return(true);
                }
                break;

            case Enums.MoveDirections.Left:
                if ((X - otherIndex.X) > 0)
                {
                    return(true);
                }
                break;

            case Enums.MoveDirections.Right:
                if ((otherIndex.X - X) > 0)
                {
                    return(true);
                }
                break;

            case Enums.MoveDirections.Front:
                if ((Z - otherIndex.Z) > 0)
                {
                    return(true);
                }
                break;

            case Enums.MoveDirections.Back:
                if ((otherIndex.Z - Z) > 0)
                {
                    return(true);
                }
                break;
            }

            return(false);
        }
예제 #6
0
        public static List <GridIndex> FindPath(GridIndex startIndex, GridIndex endIndex, TileMap gridMovements)
        {
            if (gridMovements == null)
            {
                return(new List <GridIndex>());
            }

            List <List <GridIndex> > allPaths  = new List <List <GridIndex> >();
            List <GridIndex>         firstPath = new List <GridIndex>();

            firstPath.Add(startIndex);
            allPaths.Add(firstPath);

            bool Working      = true;
            int  CycleCounter = 0;

            while (Working)
            {
                Working = false;
                CycleCounter++;

                List <List <GridIndex> > allPathsTmp = new List <List <GridIndex> >();

                foreach (List <GridIndex> onePath in allPaths)
                {
                    GridIndex lastIndex = onePath[onePath.Count - 1];

                    foreach (Enums.MoveDirections Dir in Enum.GetValues(typeof(Enums.MoveDirections)))
                    {
                        if (gridMovements.GridTileHasDirection(lastIndex, Dir))
                        {
                            GridIndex nextIndex = lastIndex.GetAdjacent(Dir);
                            if (onePath.Contains(nextIndex) == false)
                            {
                                List <GridIndex> newPath = new List <GridIndex>(onePath);
                                newPath.Add(nextIndex);
                                if (nextIndex == endIndex)
                                {
                                    CleanUpPath(ref newPath);
                                    return(newPath);
                                }
                                Working = true;
                                allPathsTmp.Add(newPath);
                            }
                        }
                    }
                }

                allPaths = allPathsTmp;
            }

            return(new List <GridIndex>());
        }
예제 #7
0
 public bool GridTileHasDirection(GridIndex index, Enums.MoveDirections dir)
 {
     if (index == null)
     {
         return(false);
     }
     if ((_GridMovements[index.X, index.Y, index.Z] & (byte)dir) != 0)
     {
         return(true);
     }
     return(false);
 }
예제 #8
0
        public int CountLinksFromGridTile(GridIndex index)
        {
            int Count = 0;

            foreach (Enums.MoveDirections Dir in Enum.GetValues(typeof(Enums.MoveDirections)))
            {
                if (GridTileHasDirection(index, Dir))
                {
                    Count++;
                }
            }
            return(Count);
        }
예제 #9
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            GridIndex p = obj as GridIndex;

            if ((object)p == null)
            {
                return(false);
            }
            return(this == p);
        }
예제 #10
0
        public void ClearMovements(GridIndex index)
        {
            if (index == null)
            {
                return;
            }

            // Also considering linked surrounding tiles. Just removing all possible
            RemoveMovementDirection(index.GetBelow(), Enums.MoveDirections.Top);
            RemoveMovementDirection(index.GetAbove(), Enums.MoveDirections.Bottom);
            RemoveMovementDirection(index.GetLeft(), Enums.MoveDirections.Right);
            RemoveMovementDirection(index.GetRight(), Enums.MoveDirections.Left);
            RemoveMovementDirection(index.GetFront(), Enums.MoveDirections.Back);
            RemoveMovementDirection(index.GetBack(), Enums.MoveDirections.Front);
            _GridMovements[index.X, index.Y, index.Z] = 0;
        }
예제 #11
0
        public static GridIndex operator -(GridIndex c1, GridIndex c2)
        {
            if (c1 == null)
            {
                throw new ArgumentNullException("c1");
            }
            if (c2 == null)
            {
                throw new ArgumentNullException("c2");
            }

            GridIndex r = new GridIndex();

            r.X = c1.X - c2.X;
            r.Y = c1.Y - c2.Y;
            r.Z = c1.Z - c2.Z;
            return(r);
        }
예제 #12
0
        public bool IsAdjacentTo(GridIndex otherIndex)
        {
            if (otherIndex == null)
            {
                return(false);
            }

            if (Math.Abs(X - otherIndex.X) > 1)
            {
                return(false);
            }
            if (Math.Abs(Y - otherIndex.Y) > 1)
            {
                return(false);
            }
            if (Math.Abs(Z - otherIndex.Z) > 1)
            {
                return(false);
            }
            return(true);
        }
예제 #13
0
        public GridIndex GetAbove()
        {
            GridIndex a = new GridIndex(0, 1, 0) + this;

            return(a);
        }
예제 #14
0
 public GridIndex Subtract(GridIndex other)
 {
     return(this - other);
 }
예제 #15
0
 public GridIndex Add(GridIndex other)
 {
     return(this + other);
 }
예제 #16
0
 public void LinkTiles(GridIndex index1, GridIndex index2, Enums.MoveDirections dir)
 {
     AddMovementDirection(index2, GetOppositeMovementDirection(dir));
     AddMovementDirection(index1, dir);
 }
예제 #17
0
 void AddMovementDirection(GridIndex Index, Enums.MoveDirections dir)
 {
     _GridMovements[Index.X, Index.Y, Index.Z] |= (byte)dir;
 }
예제 #18
0
        public GridIndex GetBack()
        {
            GridIndex b = new GridIndex(0, 0, 1) + this;

            return(b);
        }
예제 #19
0
        public GridIndex GetFront()
        {
            GridIndex a = new GridIndex(0, 0, -1) + this;

            return(a);
        }
예제 #20
0
        public GridIndex GetBelow()
        {
            GridIndex b = new GridIndex(0, -1, 0) + this;

            return(b);
        }
예제 #21
0
        public GridIndex GetRight()
        {
            GridIndex r = new GridIndex(1, 0, 0) + this;

            return(r);
        }
예제 #22
0
        public GridIndex GetLeft()
        {
            GridIndex l = new GridIndex(-1, 0, 0) + this;

            return(l);
        }