// So we don't have to walk the entire map to find the lower left and trim
        // as we generate the map, keep track
        private void PossiblyUpdateLargestSmallestPoint(Point upperLeft, MapChunk chunk)
        {
            m_placed++;
            Point lowerRight = upperLeft + new Point(chunk.Width, chunk.Height);
            m_smallestX = Math.Min(m_smallestX, upperLeft.X);
            m_smallestY = Math.Min(m_smallestY, upperLeft.Y);
            m_largestX = Math.Max(m_largestX, lowerRight.X);
            m_largestY = Math.Max(m_largestY, lowerRight.Y);

            if (m_smallestX < 0)
                throw new ArgumentException("Width too small");
            if (m_smallestY < 0)
                throw new ArgumentException("Height too small");
            if (m_largestX >= Width)
                throw new ArgumentException("Width too large");
            if (m_largestY >= Height)
                throw new ArgumentException("Height too large");
        }
Example #2
0
        internal MapChunk(MapChunk chunk)
        {
            Width = chunk.Width;
            Height = chunk.Height;
            Seams = new List<Point>(chunk.Seams);
            TreasureChests = new List<Point>(chunk.TreasureChests);
            Doors = new List<Point>(chunk.Doors);
            Cosmetics = new List<Point>(chunk.Cosmetics);
            PlayerPosition = chunk.PlayerPosition;
            Type = chunk.Type;

            MapSegment = new MapTile[Width, Height];
            for (int i = 0; i < Width; ++i)
            {
                for (int j = 0; j < Height; ++j)
                {
                    MapSegment[i, j] = new MapTile(chunk.MapSegment[i, j]);
                }
            }
        }
Example #3
0
 public void Push(MapChunk c, Point upperLeft, Point seam)
 {
     Chunks.Push(c);
     UpperLefts.Push(upperLeft);
     Seams.Push(seam);
 }
Example #4
0
 public ParenthoodElement(MapChunk chunk, Point upperLeft, Point seam)
 {
     Chunk = chunk;
     UpperLeft = upperLeft;
     Seam = seam;
 }
        private static void LoadChunksFromFile(string fileName)
        {
            if (!m_chunksLoaded)
            {
                m_chunksLoaded = true;

                m_entrances = new List<MapChunk>();
                m_halls = new List<MapChunk>();
                m_mainRooms = new List<MapChunk>();
                m_treasureRooms = new List<MapChunk>();
                m_sideRooms = new List<MapChunk>();

                using (StreamReader inputFile = XMLResourceReaderBase.GetFileStream(fileName))
                {
                    while (!inputFile.EndOfStream)
                    {
                        string definationLine = inputFile.ReadLine();
                        string[] definationParts = definationLine.Split(' ');
                        int width = int.Parse(definationParts[0], CultureInfo.InvariantCulture);
                        int height = int.Parse(definationParts[1], CultureInfo.InvariantCulture);

                        string chunkType = definationParts[2];
                        MapChunk newChunk = new MapChunk(width, height, chunkType);
                        newChunk.ReadSegmentFromFile(inputFile);

                        if (chunkType != "Hall")
                            newChunk.Doors.AddRange(newChunk.Seams);

                        switch (chunkType)
                        {
                            case "Entrance":
                                m_entrances.Add(newChunk);
                                break;
                            case "Hall":
                                m_halls.Add(newChunk);
                                break;
                            case "MainRoom":
                                m_mainRooms.Add(newChunk);
                                break;
                            case "TreasureRoom":
                                m_treasureRooms.Add(newChunk);
                                break;
                            case "SideRoom":
                                m_sideRooms.Add(newChunk);
                                break;
                            default:
                                throw new ArgumentOutOfRangeException("Unknown Chunk Type Read From File");
                        }

                        inputFile.ReadLine();
                    }
                }
            }
        }
 private void WalkNeighbors(MapNode currentNode, MapChunk currentChunk, Map map, Point upperLeft, ParenthoodChain parentChain)
 {
     while (currentNode.Neighbors.Count > 0)
     {
         MapNode nextNode = currentNode.Neighbors[0];
         nextNode.RemoveNeighbor(currentNode);
         currentNode.RemoveNeighbor(nextNode);
         Point seam = currentChunk.Seams[0];
         currentChunk.Seams.Remove(seam);
         GenerateMapFromGraph(nextNode, map, seam + upperLeft, parentChain);
     }
 }
 // Returns true if placed, false if we walled off seam
 private bool PlaceMapNode(MapNode current, MapChunk mapChunk, Map map, Point seam, ParenthoodChain parentChain)
 {
     Point placedUpperLeftCorner = mapChunk.PlaceChunkOnMap(map, seam, m_level);
     if (placedUpperLeftCorner == Point.Invalid)
     {
         map.SetTerrainAt(seam, TerrainType.Wall);
         return false;
     }
     else
     {
         PossiblyUpdateLargestSmallestPoint(placedUpperLeftCorner, mapChunk);
         map.SetTerrainAt(seam, TerrainType.Floor);
         parentChain.Push(mapChunk, placedUpperLeftCorner, seam);
         WalkNeighbors(current, mapChunk, map, placedUpperLeftCorner, parentChain);
         parentChain.Pop();
         return true;
     }
 }
 private MapChunk GetRandomChunkFromList(List<MapChunk> chunk)
 {
     MapChunk newChunk = new MapChunk(chunk[m_random.getInt(0, chunk.Count - 1)]);
     newChunk.Prepare();
     return newChunk;
 }