Exemplo n.º 1
0
        internal void PlaceChunkOnMapAtPosition(Map map, Point upperLeftCorner, Random random)
        {
            for (int i = 0; i < Width; ++i)
            {
                for (int j = 0; j < Height; ++j)
                {
                    Point mapPosition = upperLeftCorner + new Point(i, j);
                    map.SetTerrainAt(mapPosition, MapSegment[i, j].Terrain);
                }
            }

            MapObjectFactory mapItemFactory = MapObjectFactory.Instance;

            TreasureChests.ForEach(treasurePosition => map.AddMapItem(mapItemFactory.CreateMapObject("TreasureChest", upperLeftCorner + treasurePosition)));

            int chanceToPlaceDoor = this.Type == MapNodeType.TreasureRoom ? TreasureRoomChanceToPlaceDoorAtSpot : NormalChanceToPlaceDoorAtSpot;
            Doors.Where(x => m_random.Chance(chanceToPlaceDoor)).ToList().ForEach(doorPosition => map.AddMapItem(mapItemFactory.CreateMapObject("MapDoor", upperLeftCorner + doorPosition)));

            Cosmetics.ForEach(cosmeticPosition => map.AddMapItem(mapItemFactory.CreateMapObject("Cosmetic", upperLeftCorner + cosmeticPosition)));
        }
        private void GenerateMapFromGraph(MapNode current, Map map, Point seam, ParenthoodChain parentChain)
        {
            if (current.Generated)
                return;

            current.Generated = true;
            bool placed = false;

            switch (current.Type)
            {
                case MapNodeType.Entrance:
                {
                    placed = true;
                    MapChunk entranceChunk = GetRandomChunkFromList(m_entrances);

                    // We need to place entrace so it's at our expected location
                    Point randomCenter = new Point(m_random.getInt(100, 150), m_random.getInt(100, 150));
                    Point entraceUpperLeftCorner = randomCenter - entranceChunk.PlayerPosition;

                    parentChain.Push(entranceChunk, entraceUpperLeftCorner, Point.Invalid);

                    entranceChunk.PlaceChunkOnMapAtPosition(map, entraceUpperLeftCorner, m_random);
                    PossiblyUpdateLargestSmallestPoint(entraceUpperLeftCorner, entranceChunk);
                    map.AddMapItem(MapObjectFactory.Instance.CreateMapObject("StairsUp", entranceChunk.PlayerPosition + entraceUpperLeftCorner));

                    if (current.Neighbors.Count != entranceChunk.Seams.Count)
                        throw new InvalidOperationException("Number of neighbors should equal number of seams.");
                    WalkNeighbors(current, entranceChunk, map, entraceUpperLeftCorner, parentChain);

                    parentChain.Pop();

                    break;
                }
                case MapNodeType.Hall:
                {
                    for (int i = 0; i < 10; i++)
                    {
                        placed = PlaceMapNode(current, GetRandomChunkFromList(m_halls), map, seam, parentChain);
                        if (placed)
                            break;
                    }
                    break;
                }
                case MapNodeType.None:
                {
                    // If we have nothing, see if we have any orphan nodes to try to place
                    if (m_unplacedDueToSpace.Count > 0)
                    {
                        // Grab the first unplaced node, and try again.
                        MapNode treeToGraphOn = m_unplacedDueToSpace.Dequeue();
                        treeToGraphOn.Generated = false;
                        GenerateMapFromGraph(treeToGraphOn, map, seam, parentChain);
                    }
                    else
                    {
                        map.SetTerrainAt(seam, TerrainType.Wall);
                        if (current.Neighbors.Count != 0)
                            throw new InvalidOperationException("None Node types should only have no neighbors");
                    }
                    placed = true;
                    break;
                }
                case MapNodeType.MainRoom:
                {
                    placed = PlaceMapNode(current, GetRandomChunkFromList(m_mainRooms), map, seam, parentChain);
                    break;
                }
                case MapNodeType.TreasureRoom:
                {
                    placed = PlaceMapNode(current, GetRandomChunkFromList(m_treasureRooms), map, seam, parentChain);
                    break;
                }
                case MapNodeType.SideRoom:
                {
                    placed = PlaceMapNode(current, GetRandomChunkFromList(m_sideRooms), map, seam, parentChain);
                    break;
                }
                case MapNodeType.NoneGivenYet:
                default:
                    throw new InvalidOperationException("Trying to generate MapNode from invalid node.");
            }
            if (!placed)
            {
                UnplacePossibleHallwayToNowhere(map, parentChain);
                m_unplacedDueToSpace.Enqueue(current);
            }
        }
Exemplo n.º 3
0
        protected void GenerateUpDownStairs(Map map, Stairs incommingStairs)
        {
            const int DistanceToKeepDownStairsFromUpStairs = 15;

            Stairs upStairs = map.MapObjects.Where(x => x.Type == MapObjectType.StairsUp).OfType<Stairs>().FirstOrDefault();
            if (upStairs == null)
            {
                upStairs = (Stairs)MapObjectFactory.Instance.CreateMapObject("StairsUp", GetClearPoint(map));
                map.AddMapItem(upStairs);
            }

            Point stairsDownPosition = GetClearPoint(map, upStairs.Position, DistanceToKeepDownStairsFromUpStairs, 5);
            Stairs downStairs = (Stairs)MapObjectFactory.Instance.CreateMapObject("StairsDown", stairsDownPosition);
            map.AddMapItem(downStairs);

            if (incommingStairs != null)
            {
                StairsMapping.Instance.SetMapping(incommingStairs.UniqueID, upStairs.Position);
                StairsMapping.Instance.SetMapping(upStairs.UniqueID, incommingStairs.Position);
            }
        }
Exemplo n.º 4
0
        private void GenerateMonstersAndChests(Map map, Point pointToAvoid, int level)
        {
            int treasureToGenerate = m_random.getInt(2, 4);
            int treasuresGenerated = 0;

            Point segmentSizedPoint = new Point(SegmentSize, SegmentSize);

            foreach (Point segment in GenerateSegmentList(map, pointToAvoid))
            {
                Point upperLeft = new Point(SegmentSize * segment.X, SegmentSize * segment.Y);
                Point lowerRight = upperLeft + segmentSizedPoint;

                List<Point> clearSegments = GetClearPointListInRange(map, upperLeft, lowerRight).Randomize();

                if (treasuresGenerated < treasureToGenerate && m_random.Chance(40))
                {
                    Point position = PopOffClearSegementList(clearSegments);
                    if (position != Point.Invalid)
                    {
                        MapObject treasure = MapObjectFactory.Instance.CreateMapObject("TreasureChest", position);
                        map.AddMapItem(treasure);
                        treasuresGenerated++;
                    }
                }

                MonsterPlacer.PlaceMonster(map, upperLeft, lowerRight, null, m_random.getInt(2, 4), level);
            }
        }