public override Map GenerateMap(Stairs incommingStairs, int level)
        {
            for (int i = 0; i < 5; ++i)
            {
                m_level = level;
                Map map = new Map(Width, Height);

                MapNode graphHead = m_graphGenerator.GenerateMapGraph();

                ParenthoodChain parentChain = new ParenthoodChain();

                GenerateMapFromGraph(graphHead, map, Point.Invalid, parentChain);

                Point upperLeft = new Point(m_smallestX, m_smallestY);
                Point lowerRight = new Point(m_largestX, m_largestY);

                map.TrimToSubset(upperLeft, lowerRight);

                if (!CheckConnectivity(map))
                    continue;

                if (m_placed < 30)
                    continue;

                GenerateUpDownStairs(map, incommingStairs);

                StripImpossibleDoors(map);

                return map;
            }
            throw new MapGenerationFailureException("Unable to generate Stitch map with multiple attempts.");
        }
Example #2
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);
            }
        }
Example #3
0
 abstract public Map GenerateMap(Stairs incommingStairs, int level);
Example #4
0
        public override Map GenerateMap(Stairs incommingStairs, int level)
        {
            Map map;

            int width = m_random.getInt(40, 60);
            int height = m_random.getInt(40, 60);
            map = new Map(width, height);
            Map duplicateMap = new Map(width, height);

            // Fill non-sides with random bits
            for (int i = 1; i < width - 1; ++i)
            {
                for (int j = 1; j < height - 1; ++j)
                {
                    Point p = new Point(i, j);
                    if (m_random.Chance(40))
                        map.SetTerrainAt(p, TerrainType.Wall);
                    else
                        map.SetTerrainAt(p, TerrainType.Floor);
                }
            }

            FillEdgesWithWalls(map);

            // For 4 iterators, apply 1stset 1 rules...
            // If we're near(1 tile) 5 or more walls
            // or close to (2 tiles) 2 or less walls
            // we're now a wall
            for (int z = 0; z < 4; ++z)
            {
                // Create a local copy to modify. We need both the old and new values for this calculation
                duplicateMap.CopyMap(map);

                // Walk tiles, applying rule to local copy
                for (int i = 1; i < width - 1; ++i)
                {
                    for (int j = 1; j < height - 1; ++j)
                    {
                        Point p = new Point(i, j);
                        int closeWalls = CountNumberOfSurroundingWallTilesOneStepAway(map, i, j);
                        int farWalls = CountNumberOfSurroundingWallTilesTwoStepAway(map, i, j);
                        bool conditionOne = closeWalls >= 5;
                        bool conditionTwo = farWalls <= 2;
                        if (conditionOne || conditionTwo)
                            duplicateMap.SetTerrainAt(p, TerrainType.Wall);
                        else
                            duplicateMap.SetTerrainAt(p, TerrainType.Floor);
                    }
                }

                // Push our changes out
                map.CopyMap(duplicateMap);
            }

            // For 4 iterators, apply 2nd set of rules...
            // If we're near(1 tile) 5 or more walls we're now a wall
            for (int z = 0; z < 4; ++z)
            {
                // Create a local copy to modify. We need both the old and new values for this calculation
                duplicateMap.CopyMap(map);

                // Walk tiles, applying rule to local copy
                for (int i = 1; i < width - 1; ++i)
                {
                    for (int j = 1; j < height - 1; ++j)
                    {
                        int closeWalls = CountNumberOfSurroundingWallTilesOneStepAway(map, i, j);
                        Point p = new Point(i, j);

                        if (closeWalls >= 5)
                            duplicateMap.SetTerrainAt(p, TerrainType.Wall);
                        else
                            duplicateMap.SetTerrainAt(p, TerrainType.Floor);
                    }
                }

                // Push our changes out
                map.CopyMap(duplicateMap);
            }

            FillAllSmallerUnconnectedRooms(map);

            GenerateUpDownStairs(map, incommingStairs);

            Point stairsUpPosition = map.MapObjects.Where(x => x.Type == MapObjectType.StairsUp).First().Position;

            GenerateMonstersAndChests(map, stairsUpPosition, level);

            return map;
        }