コード例 #1
0
        public IRoom Generate(Floor floor, Coord connectFrom, Coord connectTo, IGenerator rng)
        {
            _floor.Place(floor, connectFrom, rng);
            _floor.Place(floor, connectTo, rng);

            List <Coord> path = HorizontalVerticalPath(connectFrom, connectTo).ToList();

            MapArea area = new MapArea();

            for (int i = 1; i < path.Count - 1; i++)
            {
                Coord current = path[i];
                Coord next    = path[i + 1];
                Coord prev    = path[i - 1];

                area.Add(current);

                if (floor.MapInfo.Map.Terrain[current] != null && floor.MapInfo.Map.Terrain[current].IsWalkable)
                {
                    continue;
                }

                _floor.Place(floor, current, rng);


                HashSet <Coord> wallOptions = new HashSet <Coord> {
                    current + Direction.UP, current + Direction.RIGHT, current + Direction.DOWN, current + Direction.LEFT
                };
                wallOptions.Remove(prev);
                wallOptions.Remove(next);

                foreach (Coord pos in wallOptions)
                {
                    if (floor.MapInfo.Map.Terrain[pos] == null)
                    {
                        _wall.Place(floor, pos, rng);
                    }
                }
            }

            Direction      finalDirection  = Direction.GetCardinalDirection(path[path.Count - 2], path[path.Count - 1]);
            RoomConnection finalConnection = new RoomConnection(connectTo, finalDirection, _endPossibilities, false);


            return(new BasicRoom(area, new List <RoomConnection> {
                finalConnection
            }, null));
        }
コード例 #2
0
        public void Decorate(Floor floor, MapArea area, IGenerator rng)
        {
            IEnumerable <Coord> wallCoords = area.Perimeter();

            Coord roomTop = area.Bounds.MinExtent;
            Coord roomMax = area.Bounds.MaxExtent;

            int xSkip = 4;
            int ySkip = 4;

            foreach (Coord pos in wallCoords)
            {
                // only place on walls
                if (floor.MapInfo.Map.WalkabilityView[pos])
                {
                    continue;
                }

                Coord offset = pos - roomTop;

                if (offset.X % xSkip != 0 && pos.X != roomMax.X)
                {
                    continue;
                }

                if (offset.Y % ySkip != 0 && pos.Y != roomMax.Y)
                {
                    continue;
                }

                _placeable.Place(floor, pos, rng);
            }
            area.Bounds.PerimeterPositions();
        }
コード例 #3
0
 void IEndDragHandler.OnEndDrag(PointerEventData eventData)
 {
     dragging = false;
     if (placeable != null)
     {
         placeable.Place();
     }
 }
コード例 #4
0
ファイル: Spreader.cs プロジェクト: DrewCutch/SpellSword
        public bool Place(Floor floor, Coord pos, IGenerator rng)
        {
            int energy = StartingEnergy;

            Queue <Coord>   frontier = new Queue <Coord>();
            HashSet <Coord> explored = new HashSet <Coord>();

            frontier.Enqueue(pos);

            while (frontier.Count > 0 && energy > 0)
            {
                Coord next = frontier.Dequeue();

                if (rng.NextDouble() > SpreadChance)
                {
                    energy--;

                    if (rng.NextDouble() < DeadChance)
                    {
                        explored.Add(next);
                    }

                    continue;
                }

                if (!floor.MapInfo.Map.IsWalkable(next) || !_generator.CanPlace(floor, next, rng))
                {
                    continue;
                }

                _generator.Place(floor, next, rng);

                explored.Add(next);

                energy--;
                foreach (Coord neighbor in AdjacencyRule.CARDINALS.Neighbors(next))
                {
                    if (!explored.Contains(neighbor))
                    {
                        frontier.Enqueue(neighbor);
                    }
                }
            }

            return(true);
        }
コード例 #5
0
        public IRoom Generate(Floor floor, RoomConnection connectAt, IGenerator rng)
        {
            MapArea area = GenerateArea(floor.MapInfo, connectAt, rng);

            HashSet <Coord> perimeter = new HashSet <Coord>(area.Perimeter());

            foreach (Coord pos in area.Positions)
            {
                if (perimeter.Contains(pos))
                {
                    _wall.Place(floor, pos, rng);
                }
                else
                {
                    _floor.Place(floor, pos, rng);
                }
            }

            List <Coord>          perimeterList  = new List <Coord>(perimeter);
            List <RoomConnection> connections    = new List <RoomConnection>();
            HashSet <Direction>   usedDirections = new HashSet <Direction>();

            for (int n = 0; n < 20 && connections.Count < 4; n++)
            {
                Coord connectionPos = perimeterList[rng.Next(perimeterList.Count)];

                if (IsCorner(connectionPos, area))
                {
                    continue;
                }

                Direction dir = GetDirection(connectionPos, area);

                if (usedDirections.Contains(dir))
                {
                    continue;
                }

                connections.Add(new RoomConnection(connectionPos, dir, NeighborPossibilities, true));
                usedDirections.Add(dir);
            }

            return(new BasicRoom(area, connections, this));
        }
コード例 #6
0
        public bool Place(IPlaceable placeable, Position position)
        {
            Position2D position2D = position.AsPosition2D();

            if (!CanPlace(placeable, position, position2D))
            {
                return(false);
            }

            List <IPlaceable> contents = _content [position2D.GetX(), position2D.GetY()];

            if (contents == null)
            {
                contents = new List <IPlaceable>();
                _content [position2D.GetX(), position2D.GetY()] = contents;
            }
            contents.Add(placeable);
            placeable.Place(position);
            return(true);
        }
コード例 #7
0
        public IRoom Generate(Floor floor, RoomConnection connectAt, IGenerator rng)
        {
            Rectangle roomBounds = new Rectangle(0, 0, rng.Next(_minBounds.Width, _maxBounds.Width), rng.Next(_minBounds.Height, _maxBounds.Height));

            Coord offset = connectAt.Direction.Type switch
            {
                Direction.Types.LEFT => new Coord(-roomBounds.Width + 1, -roomBounds.Height / 2),
                Direction.Types.RIGHT => new Coord(0, -roomBounds.Height / 2),
                Direction.Types.UP => new Coord(-roomBounds.Width / 2, -roomBounds.Height + 1),
                Direction.Types.DOWN => new Coord(-roomBounds.Width / 2, 0),
                Direction.Types.NONE => new Coord(-roomBounds.Height / 2, -roomBounds.Width / 2),
                _ => throw new ArgumentOutOfRangeException()
            };

            roomBounds = roomBounds.WithPosition(offset + connectAt.Position);


            foreach (Coord pos in roomBounds.PerimeterPositions())
            {
                _wall.Place(floor, pos, rng);
            }

            foreach (Coord pos in roomBounds.ChangeSize(-2, -2).WithCenter(roomBounds.Center).Positions())
            {
                _floor.Place(floor, pos, rng);
            }

            MapArea area = new MapArea();

            area.Add(roomBounds);

            List <RoomConnection> connections = new List <RoomConnection>();

            foreach (Direction dir in AdjacencyRule.CARDINALS.DirectionsOfNeighbors())
            {
                if (dir.DeltaX == -connectAt.Direction.DeltaX && dir.DeltaY == -connectAt.Direction.DeltaY)
                {
                    continue;
                }

                int xOffset = dir.DeltaX * (roomBounds.Width - 1) / 2;
                int yOffset = dir.DeltaY * (roomBounds.Height - 1) / 2;

                if (dir.DeltaX == 0)
                {
                    xOffset += rng.Next(-roomBounds.Width / 2 + 1, roomBounds.Width / 2 - 1);
                }

                if (dir.DeltaY == 0)
                {
                    yOffset += rng.Next(-roomBounds.Height / 2 + 1, roomBounds.Height / 2 - 1);
                }

                Coord door = roomBounds.Center + new Coord(xOffset, yOffset);
                connections.Add(new RoomConnection(door, dir, NeighborPossibilities, true));
                //_floor.Place(mapInfo, door, rng);
            }

            if (connectAt.Position != Coord.NONE)
            {
                _floor.Place(floor, connectAt.Position, rng);
            }

            return(new BasicRoom(area, connections, this));
        }