Ejemplo n.º 1
0
        public WorldGrid3DInfo(int x, int y, Vector3 worldPos, float size, GridDirection direction)
        {
            this.x         = x;
            this.y         = y;
            this.worldPos  = worldPos;
            this.size      = size;
            this.direction = direction;
            isBlocked      = false;

            switch (direction)
            {
            case GridDirection.XZ:
                _sides = new Vector3[]
                {
                    new Vector3(worldPos.x + size * 0.5f, worldPos.y, worldPos.z + size * 0.5f),
                    new Vector3(worldPos.x + size * 0.5f, worldPos.y, worldPos.z - size * 0.5f),
                    new Vector3(worldPos.x - size * 0.5f, worldPos.y, worldPos.z - size * 0.5f),
                    new Vector3(worldPos.x - size * 0.5f, worldPos.y, worldPos.z + size * 0.5f)
                };
                break;

            case GridDirection.XY:
                _sides = new Vector3[]
                {
                    new Vector3(worldPos.x + size * 0.5f, worldPos.y + size * 0.5f, worldPos.z),
                    new Vector3(worldPos.x + size * 0.5f, worldPos.y - size * 0.5f, worldPos.z),
                    new Vector3(worldPos.x - size * 0.5f, worldPos.y - size * 0.5f, worldPos.z),
                    new Vector3(worldPos.x - size * 0.5f, worldPos.y + size * 0.5f, worldPos.z)
                };
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(direction), direction, null);
            }
        }
Ejemplo n.º 2
0
    void SetTargetGrids(GridDirection direction)
    {
        if (targetGridList.ContainsKey(direction))
        {
            targetGrids = targetGridList[direction];
        }
        else
        {
            switch (skillCasting.RangeType)
            {
            case SkillRangeType.Line:
                targetGrids = BattleMapManager.Instance.LineTargets(direction, skillCasting.Range);
                break;

            case SkillRangeType.Fan:
                targetGrids = BattleMapManager.Instance.FanTargets(direction, skillCasting.Range);
                break;

            case SkillRangeType.Circle:
                targetGrids = BattleMapManager.Instance.CircleTargets(skillCasting.Range);
                break;

            default:
                break;
            }
            targetGridList.Add(direction, targetGrids);
        }

        BattleMapManager.Instance.MapView.ResetState();
        BattleMapManager.Instance.SelectingTarget(targetGrids);
    }
    public void SetAsDestination()
    {
        cost     = 0;
        bestCost = 0;

        bestDirection = GridDirection.None;
    }
Ejemplo n.º 4
0
        public InfiniteHexGrid(float radius, Vector3 basePos, GridDirection direction)
        {
            Size       = radius;
            _basePos   = basePos;
            _direction = direction;

            _dirs = new Vector2Int[]
            {
                //Even
                new Vector2Int(0, 1),
                new Vector2Int(0, -1),
                new Vector2Int(1, 0),
                new Vector2Int(-1, 0),
                new Vector2Int(-1, -1),
                new Vector2Int(-1, 1),

                //Odd
                new Vector2Int(0, 1),
                new Vector2Int(0, -1),
                new Vector2Int(1, 0),
                new Vector2Int(-1, 0),
                new Vector2Int(1, 1),
                new Vector2Int(1, -1),
            };
        }
Ejemplo n.º 5
0
    private Vector3 EdgePosition(MapEdge edge)
    {
        Vector3 nodePos = NodePosition(edge.From);

        GridDirection direction = edge.Direction;

        float edgeSpacing = _spacing / 8;
        float halfSpacing = _spacing / 2;

        Vector3 adjust = Vector3.zero;

        if (direction == GridDirection.N)
        {
            adjust = new Vector3(-edgeSpacing, halfSpacing, 0);
        }
        if (direction == GridDirection.E)
        {
            adjust = new Vector3(halfSpacing, edgeSpacing, 0);
        }
        if (direction == GridDirection.S)
        {
            adjust = new Vector3(edgeSpacing, -halfSpacing, 0);
        }
        if (direction == GridDirection.W)
        {
            adjust = new Vector3(-halfSpacing, -edgeSpacing, 0);
        }

        return(nodePos + adjust);
    }
        /// <summary>
        /// Creates at random.
        /// </summary>
        /// <returns>The randomly created instance.</returns>
        public static GeneticGridDirection CreateAtRandom()
        {
            int           randInt   = CommonHelperMethods.GetRandomPositiveInt0ToValue(3);
            GridDirection direction = (GridDirection)randInt;

            return(new GeneticGridDirection(direction));
        }
Ejemplo n.º 7
0
    public void SetOutgoingRiver(GridDirection direction)
    {
        if (hasOutgoingRivers[(int)direction] || HasRoads)
        {
            Debug.Log("Could not add river");
            return;
        }
        SquareCell neighbor = GetNeighbor(direction);

        if (!neighbor || CentreElevation < neighbor.CentreElevation)
        {
            Debug.Log("Could not add river uphill");
            return;
        }
        if (hasIncomingRivers[(int)direction])
        {
            RemoveIncomingRiver(direction);
        }
        hasOutgoingRivers[(int)direction] = true;
        RefreshChunkOnly();

        neighbor.RemoveOutgoingRiver(direction.Opposite());
        neighbor.hasIncomingRivers[(int)direction.Opposite()] = true;
        neighbor.RefreshChunkOnly();
    }
Ejemplo n.º 8
0
 public void RemoveRoad(GridDirection direction)
 {
     if (roads[(int)direction] == true)
     {
         SetRoad((int)direction, false);
     }
 }
Ejemplo n.º 9
0
        // get position next to this one
        public GridPosition GetAdjacentPosition(GridDirection direction)
        {
            GridPosition position = new GridPosition(column, row);

            // top
            if (direction == GridDirection.North)
            {
                position.row++;
            }
            // right
            if (direction == GridDirection.East)
            {
                position.column++;
            }
            // bottom
            if (direction == GridDirection.South)
            {
                position.row--;
            }
            // left
            if (direction == GridDirection.West)
            {
                position.column--;
            }

            return(position);
        }
Ejemplo n.º 10
0
 public static DrawAction <T> Dir <T>(GridDirection dir, DrawAction <T> call)
 {
     return((arr, x, y) =>
     {
         return arr.DrawDir(x, y, dir, call);
     });
 }
    public void ResetCell()
    {
        cost     = 1;
        bestCost = ushort.MaxValue;

        bestDirection = GridDirection.None;
    }
    protected void DoNextGenerationStep(DiggingAgent agent)
    {
        //First we move the agent.
        //We change direction by chance or if the next position in the current direction is not in the level.
        if (Random.value < changeDirectionProb || !ContainsCoordinates(agent.pos + agent.direction.ToIntVector2()))
        {
            //Randomly move the agent to a new valid position in the level.
            GridDirection newDir = ChangeDirection(agent.pos, agent.direction);
            agent.direction = newDir;
            agent.turnProb  = changeDirectionProb;
        }
        else
        if (dynamicProbabilities)
        {
            agent.turnProb += changeDirDelta;
        }
        //Now we now the next position!
        agent.pos += agent.direction.ToIntVector2();

        //Make a room?
        if (Random.value < agent.roomProb)
        {
            rooms.Add(CreateRoom(agent.pos, RandomRoomSize));
            agent.roomProb = makeRoomProb;
        }
        else
        {
            //else just open current cell
            agent.OpenCurrentCell();
            if (dynamicProbabilities)
            {
                agent.roomProb += makeRoomDelta;
            }
        }
    }
Ejemplo n.º 13
0
    public int?this[GridDirection i]
    {
        get
        {
            switch (i)
            {
            case GridDirection.SW: return(y0);

            case GridDirection.NW: return(y1);

            case GridDirection.NE: return(y2);

            case GridDirection.SE: return(y3);

            default: return(null);
            }
        }
        set
        {
            switch (i)
            {
            case GridDirection.SW: y0 = (int)value; break;

            case GridDirection.NW: y1 = (int)value; break;

            case GridDirection.NE: y2 = (int)value; break;

            case GridDirection.SE: y3 = (int)value; break;

            default: break;
            }
        }
    }
Ejemplo n.º 14
0
 public NavigationTestCase(GridDirection direction, MapCoordinate origin)
 {
     Direction = direction;
     Origin    = origin;
     Result    = true;
     Steps     = 1;
 }
Ejemplo n.º 15
0
 public GridManager(Grid a, Grid b, Vector3Int c)
 {
     none     = new GridDirection("", "");
     grid     = a;
     tileGrid = b;
     gridPos  = getGridCoords(c);
 }
Ejemplo n.º 16
0
        public static Ship?TryCreate(Coordinates initialPosition, GridDirection direction, int shipLength, List <Ship> otherShips, int shipIdsCounter)
        {
            var segments = new List <SingleSegmentSingleSegment>();

            var lastCoords = initialPosition;

            segments.Add(new SingleSegmentSingleSegment(lastCoords));

            for (int i = 0; i < shipLength - 1; i++)
            {
                var newCoords = lastCoords.TryCreateNext(direction);
                if (newCoords == null)
                {
                    return(null);
                }
                lastCoords = newCoords;
                segments.Add(new SingleSegmentSingleSegment(lastCoords));
            }

            var isColliding = segments
                              .Select(x => x.Coordinates)
                              .Any(s => otherShips
                                   .Any(x => x.Segments
                                        .Any(y => y.Coordinates.Equals(s))));

            return(isColliding
                ? null
                : new Ship(segments, shipIdsCounter));
        }
Ejemplo n.º 17
0
    public T GetFrom(T start, GridDirection direction, int distance = 1)
    {
        var index = IndexOf(start);

        if (direction == GridDirection.Left)
        {
            index -= distance;
        }
        else if (direction == GridDirection.Right)
        {
            index += distance;
        }
        else if (direction == GridDirection.Down)
        {
            index += columns * distance;
        }
        else if (direction == GridDirection.Up)
        {
            index -= columns * distance;
        }

        if (index < 0)
        {
            return(this.First());
        }
        else if (index >= Count)
        {
            return(this.Last());
        }

        return(this [index]);
    }
Ejemplo n.º 18
0
    public int GetElevationDifference(GridDirection direction)
    {
        int differencePrev = (int)this[direction.Previous()] - (int)this[direction.Opposite().Next()];
        int differenceNext = (int)this[direction.Next()] - (int)this[direction.Opposite().Previous()];
        int result         = Mathf.Max(differencePrev, differenceNext);

        return(result);
    }
Ejemplo n.º 19
0
    public Vector3 getNeighbour(Cell cellBelow, GridDirection dir)
    {
        Vector2Int index = cellBelow.gridIndex;

        Cell bestNeighbour = GetCellAtRelativePos(index, dir);

        return(bestNeighbour.worldPos);
    }
Ejemplo n.º 20
0
        public InfiniteQuadGrid(float size, Vector3 basePos, GridDirection direction)
        {
            Size       = size;
            _basePos   = basePos;
            _direction = direction;

            CreateDir();
        }
        public void RotateDirection_ShouldReturnCorrectResult(GridDirection before, GridDirection expected)
        {
            // Arrange/ Act
            var result = new CoordinateHelper().Rotate(before);

            // Assert
            Assert.Equal(expected, result);
        }
Ejemplo n.º 22
0
 private static IObservable <GridDirection> MapToDirection(PlayerAction action, GridDirection direction)
 {
     return(Observable.EveryUpdate()
            .Select(_ => !!action)
            .DistinctUntilChanged()
            .Where(activated => activated)
            .Select(_ => direction));
 }
Ejemplo n.º 23
0
 public static MapCoordinate NavigateUnconditionally(this IMapNavigator <GridDirection> nav,
                                                     GridDirection d,
                                                     MapCoordinate coord,
                                                     int steps = 1)
 {
     nav.NavigateTo(d, coord, out MapCoordinate results, steps);
     return(results);
 }
Ejemplo n.º 24
0
 public bool IsNeighborRoad(GridDirection direction)
 {
     if (GetNeighbor(direction) == null)
     {
         return(true);
     }
     return(GetNeighbor(direction).data.HasRoad);
 }
Ejemplo n.º 25
0
 public Cell(Vector3 _worldPos, Vector2Int _gridIndex)
 {
     worldPos      = _worldPos;
     gridIndex     = _gridIndex;
     cost          = 1;
     bestCost      = 60000;
     bestDirection = GridDirection.None;
 }
Ejemplo n.º 26
0
 public Cell(Vector3 _worldPos, Vector2Int _gridIndex)
 {
     worldPos      = _worldPos;
     gridIndex     = _gridIndex;
     cost          = 1;
     bestCost      = ushort.MaxValue;
     bestDirection = GridDirection.None;
 }
Ejemplo n.º 27
0
            public void GivenCoordinatesAndDirection_WhenNextCoordinateInvalid_ShouldReturnNull(
                int beforeRow, int beforeColumn, GridDirection direction)
            {
                var coordinateBefore = Coordinates.CreateOrThrow(beforeRow, beforeColumn);

                var result = coordinateBefore.TryCreateNext(direction);

                result.Should().BeNull();
            }
Ejemplo n.º 28
0
        public static GridDirection GetRotatedDirection(GridDirection direction, GridDirection orientation)
        {
            switch (orientation)
            {
            case GridDirection.Right:
                switch (direction)
                {
                case GridDirection.Up:
                    return(GridDirection.Right);

                case GridDirection.Right:
                    return(GridDirection.Down);

                case GridDirection.Down:
                    return(GridDirection.Left);

                case GridDirection.Left:
                    return(GridDirection.Up);
                }
                break;

            case GridDirection.Down:
                switch (direction)
                {
                case GridDirection.Up:
                    return(GridDirection.Down);

                case GridDirection.Right:
                    return(GridDirection.Left);

                case GridDirection.Down:
                    return(GridDirection.Up);

                case GridDirection.Left:
                    return(GridDirection.Right);
                }
                break;

            case GridDirection.Left:
                switch (direction)
                {
                case GridDirection.Up:
                    return(GridDirection.Left);

                case GridDirection.Right:
                    return(GridDirection.Up);

                case GridDirection.Down:
                    return(GridDirection.Right);

                case GridDirection.Left:
                    return(GridDirection.Down);
                }
                break;
            }
            return(direction);
        }
    //Material indicatorColor;

    public DiggingAgent(LevelDigger _level, IntVector2 position, GridDirection init_direction, float init_changeProb, float init_roomProb)
    {
        level           = _level;
        pos             = position;
        direction       = init_direction;
        base_changeProb = turnProb = init_changeProb;
        base_roomprob   = roomProb = init_roomProb;
        stepsDone       = 0;
    }
Ejemplo n.º 30
0
            public void GivenCoordinatesAndDirection_WhenNextCoordinateValid_NewCoordinateValuesShouldRespectDirection(
                int beforeRow, int beforeColumn, GridDirection direction, int afterRow, int afterColumn)
            {
                var coordinateBefore   = Coordinates.CreateOrThrow(beforeRow, beforeColumn);
                var expectedCoordinate = Coordinates.CreateOrThrow(afterRow, afterColumn);

                var result = coordinateBefore.TryCreateNext(direction);

                result.Should().Be(expectedCoordinate);
            }
        public void FromRotatorTest()
        {
            Angle a = new Angle(1, 270, 0, 0);
            Tester = GridDirectionExtentions.GetDirectionFromRotation(0, 0, 0);
            Tester.Should().Be(GridDirection.East);

            Tester = GridDirectionExtentions.GetDirectionFromRotation(45, 45, 90);
            Tester.Should().Be(GridDirection.NorthLower);
            //GridDirection.Offsets[(int) Tester.FromRotator(0, 0, 270)].X.Should().BeApproximately(0, IntegerPrec);
            //GridDirection.Offsets[(int) Tester.FromRotator(0, 0, 270)].Y.Should().BeApproximately(1, IntegerPrec);
            //GridDirection.Offsets[(int)Tester.FromRotator(0, 0, 270)].Z.Should().BeApproximately(0, IntegerPrec);
        }
Ejemplo n.º 32
0
        public void Destroy(GridDirection direction)
        {
            switch (direction)
            {
                case GridDirection.LEFT:
                    left = null;
                    break;

                case GridDirection.RIGHT:
                    right = null;
                    break;

                case GridDirection.UP:
                    up = null;
                    break;
            }
        }
Ejemplo n.º 33
0
        public void Add(GridDirection direction, Building building)
        {
            switch (direction)
            {
                case GridDirection.LEFT:
                    left = building;
                    break;

                case GridDirection.RIGHT:
                    right = building;
                    break;

                case GridDirection.UP:
                    up = building;
                    break;
            }
        }
Ejemplo n.º 34
0
        public void BreakWall(int cellLocationX, int cellLocationZ, GridDirection direction)
        {
            if (cellLocationX < 0 || cellLocationX >= _sizeX)
            {
                return;
            }

            if (cellLocationZ < 0 || cellLocationZ >= _sizeZ)
            {
                return;
            }

            switch (direction)
            {
                case GridDirection.North:
                    if (!(cellLocationZ + 1 > _sizeZ - 1))
                    {
                        Matrix[cellLocationX, cellLocationZ].HasNorthWall = false;
                        Matrix[cellLocationX, cellLocationZ + 1].HasSouthWall = false;
                    }
                    break;
                case GridDirection.South:
                    if (!(cellLocationZ - 1 < 0))
                    {
                        Matrix[cellLocationX, cellLocationZ].HasSouthWall = false;
                        Matrix[cellLocationX, cellLocationZ - 1].HasNorthWall = false;
                    }
                    break;
                case GridDirection.East:
                    if (!(cellLocationX + 1 >_sizeX - 1))
                    {
                        Matrix[cellLocationX, cellLocationZ].HasEastWall = false;
                        Matrix[cellLocationX + 1, cellLocationZ].HasWestWall = false;
                    }
                    break;
                case GridDirection.West:
                    if (!(cellLocationX - 1 < 0))
                    {
                        Matrix[cellLocationX, cellLocationZ].HasWestWall = false;
                        Matrix[cellLocationX - 1, cellLocationZ].HasEastWall = false;
                    }
                    break;
                default:
                    break;
            }
        }
Ejemplo n.º 35
0
        public void Add(GridDirection direction, Building building)
        {
            switch (direction)
            {
                case GridDirection.LEFT:
                    left = left == null ? building : left;
                    break;

                case GridDirection.RIGHT:
                    right = right == null ? building : right;
                    break;

                case GridDirection.DOWN:
                    down = down == null ? building : down;
                    break;
            }
        }
Ejemplo n.º 36
0
        public void DestroySuspension(GridDirection direction)
        {
            switch (direction)
            {
                case GridDirection.LEFT:
                    left = null;
                    break;

                case GridDirection.RIGHT:
                    right = null;
                    break;

                case GridDirection.DOWN:
                    down = null;
                    break;
            }
        }
 ///<summary>
 ///    Return the count of unused neighbors in the given
 ///    GridDirection, to a maximum of distance.  This is used
 ///    by the polygon synthesis routines.
 ///</summary>
 internal int CountUnusedNeighbors(GridCell cell, GridDirection direction, int distance)
 {
     int count = 0;
     GridCell temp = cell;
     if (temp == null)
         return 0;
     for (int i=0; i<distance; i++) {
         if (temp.neighbors == null)
             break;
         temp = temp.neighbors[(int)direction];
         if (temp == null || temp.used)
             break;
         count++;
     }
     return count;
 }
 internal Vector3 CoordinatesOfCell(GridCell cell, GridDirection outside, bool start)
 {
     Vector3 loc = GridLocation(cell.loc);
     if (start) {
         loc.x += .5f * cellWidth * fromOutsideToStart[(int)outside, 0];
         loc.z += .5f * cellWidth * fromOutsideToStart[(int)outside, 1];
     }
     else {
         loc.x += .5f * cellWidth * fromOutsideToEnd[(int)outside, 0];
         loc.z += .5f * cellWidth * fromOutsideToEnd[(int)outside, 1];
     }
     return modelTransform * loc;
 }
 internal GridEdge(GridCell start, GridCell end, GridDirection forward, GridDirection outside)
 {
     this.start = start;
     this.end = end;
     this.forward = forward;
     this.outside = outside;
 }
 ///<summary>
 ///    Return the nth neighbor in the given direction.
 ///</summary>
 internal GridCell NthNeighborOrNull(GridCell cell, GridDirection direction, int n)
 {
     GridCell temp = cell;
     for (int i=0; i<n; i++) {
         if (temp == null) {
             return null;
         }
         temp = temp.neighbors[(int)direction];
     }
     return temp;
 }
 ///<summary>
 ///    Return the nth neighbor in the given direction.  We've 
 ///    already counted the neighbors, so there should be no 
 ///    case of a null neighbor.
 ///</summary>
 internal GridCell NthNeighbor(GridCell cell, GridDirection direction, int n)
 {
     GridCell temp = NthNeighborOrNull(cell, direction, n);
     if (temp == null)
         throw new Exception(string.Format("Null neighbor in PathGenerator.NthNeighbor({0}, {1}, {2})",
                                           cell.ToString(), (int)direction, n));
     return temp;
 }
 internal GridCell NextCellAtHeight(GridCell cell, GridDirection direction)
 {
     int i = cell.loc.xCell + incrByDirection[(int)direction, 0];
     int j = cell.loc.zCell + incrByDirection[(int)direction, 1];
     if (i < 0 || i >= xCount || j < 0 || j >= zCount)
         return null;
     GridCell other = FindCellAtHeight(i, j, cell.loc.height);
     if (other != null)
         return other;
     else
         return null;
 }
 internal void MarkNeighborsInaccessible(GridCell cell, GridDirection direction, int count)
 {
     cell.used = true;
     GridCell temp = cell;
     for (int i=0; i<count; i++) {
         temp = NextCellAtHeight(temp, direction);
         if (temp == null)
             return;
         temp.used = true;
         temp.status = CellStatus.Inaccessible;
     }
 }
 ///<summary>
 ///    Create a grid edge, given the starting and ending cell,
 ///    and the outside direction.
 ///</summary>
 internal GridEdge MakeGridEdge(GridCell start, GridCell end, GridDirection forward, GridDirection outside)
 {
     // Canonicalize the directions
     if (forward == GridDirection.MinusX) {
         forward = GridDirection.PlusX;
         GridCell temp = start;
         start = end;
         end = temp;
     }
     else if (forward == GridDirection.MinusZ) {
         forward = GridDirection.PlusZ;
         GridCell temp = start;
         start = end;
         end = temp;
     }
     return new GridEdge(start, end, forward, outside);
 }
Ejemplo n.º 45
0
 public Ladder(GridDirection dir)
 {
     Direction = dir;
 }
Ejemplo n.º 46
0
        public bool HasSuspension(GridDirection direction)
        {
            switch (direction)
            {
                case GridDirection.LEFT:
                    return left != null;

                case GridDirection.RIGHT:
                    return right != null;

                case GridDirection.DOWN:
                    return down != null;
            }

            return false;
        }
Ejemplo n.º 47
0
 public CellEdge GetEdge(GridDirection direction)
 {
     Cell neighbor = Grid[this + direction.AsOffset()];
     return Grid.Edges[this, neighbor];
 }
 public static bool IsColinear(this GridDirection dir, GridDirection other)
 {
     if (dir == other || dir == other.Opposite())
         return true;
     else
         return false;
 }
Ejemplo n.º 49
0
		// get position next to this one
		public GridPosition GetAdjacentPosition(GridDirection direction)
		{
			GridPosition position = new GridPosition(column, row);

			// top
			if (direction == GridDirection.North)
			{
				position.row++;
			}
			// right
			if (direction == GridDirection.East)
			{
				position.column++;
			}
			// bottom
			if (direction == GridDirection.South)
			{
				position.row--;
			}
			// left
			if (direction == GridDirection.West)
			{
				position.column--;
			}

			return position;
		}
 public void Setup()
 {
     Tester = GridDirection.NorthWest;
 }
 public void IsDiagonalTest()
 {
     Tester.IsDiagonal().Should().BeTrue();
     Tester = GridDirection.West;
     Tester.IsDiagonal().Should().BeFalse();
 }