void RemoveMovementDirection(GridIndex Index, Enums.MoveDirections dir) { if (!Index.IsValid()) { return; } _GridMovements[Index.X, Index.Y, Index.Z] &= (byte)~dir; }
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); }
public GridIndex(GridIndex other) { if (other == null) { throw new ArgumentNullException("other"); } X = other.X; Y = other.Y; Z = other.Z; }
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); }
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); }
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>()); }
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); }
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); }
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); }
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; }
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); }
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); }
public GridIndex GetAbove() { GridIndex a = new GridIndex(0, 1, 0) + this; return(a); }
public GridIndex Subtract(GridIndex other) { return(this - other); }
public GridIndex Add(GridIndex other) { return(this + other); }
public void LinkTiles(GridIndex index1, GridIndex index2, Enums.MoveDirections dir) { AddMovementDirection(index2, GetOppositeMovementDirection(dir)); AddMovementDirection(index1, dir); }
void AddMovementDirection(GridIndex Index, Enums.MoveDirections dir) { _GridMovements[Index.X, Index.Y, Index.Z] |= (byte)dir; }
public GridIndex GetBack() { GridIndex b = new GridIndex(0, 0, 1) + this; return(b); }
public GridIndex GetFront() { GridIndex a = new GridIndex(0, 0, -1) + this; return(a); }
public GridIndex GetBelow() { GridIndex b = new GridIndex(0, -1, 0) + this; return(b); }
public GridIndex GetRight() { GridIndex r = new GridIndex(1, 0, 0) + this; return(r); }
public GridIndex GetLeft() { GridIndex l = new GridIndex(-1, 0, 0) + this; return(l); }