예제 #1
0
        /// <summary>
        /// Draws a hall in a straight cardinal direction, starting with one point and ending with another (inclusive).
        /// </summary>
        /// <param name="map"></param>
        /// <param name="point1"></param>
        /// <param name="point2"></param>
        /// <param name="terrain"></param>
        private static void DrawHall(ITiledGenContext map, Loc point1, Loc point2, ITile terrain)
        {
            if (point1 == point2)
            {
                map.SetTile(point1, terrain.Copy());
            }
            else if (point1.X == point2.X)
            {
                if (point2.Y > point1.Y)
                {
                    for (int ii = point1.Y; ii <= point2.Y; ii++)
                    {
                        map.SetTile(new Loc(point1.X, ii), terrain.Copy());
                    }
                }
                else if (point2.Y < point1.Y)
                {
                    for (int ii = point1.Y; ii >= point2.Y; ii--)
                    {
                        map.SetTile(new Loc(point1.X, ii), terrain.Copy());
                    }
                }
            }
            else if (point1.Y == point2.Y)
            {
                if (point2.X > point1.X)
                {
                    for (int ii = point1.X; ii <= point2.X; ii++)
                    {
                        map.SetTile(new Loc(ii, point1.Y), terrain.Copy());
                    }
                }
                else if (point2.X < point1.X)
                {
                    for (int ii = point1.X; ii >= point2.X; ii--)
                    {
                        map.SetTile(new Loc(ii, point1.Y), terrain.Copy());
                    }
                }
            }

            GenContextDebug.DebugProgress("Hall Line");
        }
예제 #2
0
        public override void DrawOnMap(T map)
        {
            Loc isleSize = new Loc(1);

            while (isleSize.X * isleSize.Y < ItemAmount)
            {
                if (isleSize.X > isleSize.Y)
                {
                    isleSize.Y++;
                }
                else
                {
                    isleSize.X++;
                }
            }

            //require at least a rectangle that can contain a ring of land around the ring of water
            if (isleSize.X + 4 > Draw.Size.X || isleSize.Y + 4 > Draw.Size.Y)
            {
                DrawMapDefault(map);
                return;
            }

            Loc ringSize = isleSize + new Loc(2);

            //size of room should be between size of cave + 2 and max
            for (int x = 0; x < Draw.Size.X; x++)
            {
                for (int y = 0; y < Draw.Size.Y; y++)
                {
                    map.SetTile(new Loc(Draw.X + x, Draw.Y + y), map.RoomTerrain.Copy());
                }
            }

            List <Loc> freeTiles  = new List <Loc>();
            Loc        blockStart = new Loc(Draw.X + 1 + map.Rand.Next(Draw.Size.X - ringSize.X - 1), Draw.Y + 1 + map.Rand.Next(Draw.Size.Y - ringSize.Y - 1));

            for (int x = 0; x < ringSize.X; x++)
            {
                for (int y = 0; y < ringSize.Y; y++)
                {
                    if (x == 0 || x == ringSize.X - 1 || y == 0 || y == ringSize.Y - 1)
                    {
                        map.SetTile(new Loc(blockStart.X + x, blockStart.Y + y), WaterTerrain.Copy());
                    }
                    else
                    {
                        freeTiles.Add(new Loc(blockStart.X + x, blockStart.Y + y));
                    }
                }
            }
            if (Treasures.Count > 0)
            {
                for (int ii = 0; ii < ItemAmount; ii++)
                {
                    MapItem item      = new MapItem(Treasures.Pick(map.Rand));
                    int     randIndex = map.Rand.Next(freeTiles.Count);
                    map.PlaceItem(freeTiles[randIndex], item);
                    freeTiles.RemoveAt(randIndex);
                }
            }

            //hall restrictions
            SetRoomBorders(map);
        }