Esempio n. 1
0
        public ComponentCollection Clone()
        {
            ComponentCollection newCollection = new ComponentCollection();

            foreach (RoomComponent component in this)
            {
                newCollection.Set(component.Clone());
            }
            return(newCollection);
        }
Esempio n. 2
0
        /// <summary>
        /// Sets the RoomGen found in the specified hall.
        /// </summary>
        /// <param name="locRay">The location of the room + the direction of the connecting hall relative to the room.</param>
        /// <param name="hallGen"></param>
        /// <param name="components">components to include in the hall</param>
        public void SetHall(LocRay4 locRay, IPermissiveRoomGen hallGen, ComponentCollection components)
        {
            if (locRay.Dir == Dir4.None)
            {
                throw new ArgumentException("Invalid direction.");
            }
            else if (!locRay.Dir.Validate())
            {
                throw new ArgumentOutOfRangeException("Invalid enum value.");
            }

            GridHallPlan plan = null;

            if (hallGen != null)
            {
                plan = new GridHallPlan((IPermissiveRoomGen)hallGen.Copy(), components);
            }

            switch (locRay.Dir)
            {
            case Dir4.Down:
                if (locRay.Loc.Y < this.GridHeight - 1)
                {
                    this.VHalls[locRay.Loc.X][locRay.Loc.Y].SetHall(plan);
                }
                break;

            case Dir4.Left:
                if (locRay.Loc.X > 0)
                {
                    this.HHalls[locRay.Loc.X - 1][locRay.Loc.Y].SetHall(plan);
                }
                break;

            case Dir4.Up:
                if (locRay.Loc.Y > 0)
                {
                    this.VHalls[locRay.Loc.X][locRay.Loc.Y - 1].SetHall(plan);
                }
                break;

            case Dir4.Right:
                if (locRay.Loc.X < this.GridWidth - 1)
                {
                    this.HHalls[locRay.Loc.X][locRay.Loc.Y].SetHall(plan);
                }
                break;

            case Dir4.None:
                throw new ArgumentException($"No hall for dir {nameof(Dir4.None)}");

            default:
                throw new ArgumentOutOfRangeException(nameof(locRay.Dir), "Invalid enum value.");
            }
        }
Esempio n. 3
0
        public static void SafeAddHall(LocRay4 locRay, GridPlan floorPlan, IPermissiveRoomGen hallGen, IRoomGen roomGen, ComponentCollection roomComponents, ComponentCollection hallComponents, bool preferHall = false)
        {
            floorPlan.SetHall(locRay, hallGen, hallComponents.Clone());
            ComponentCollection collection = preferHall ? hallComponents : roomComponents;

            if (floorPlan.GetRoomPlan(locRay.Loc) == null)
            {
                floorPlan.AddRoom(locRay.Loc, roomGen, collection.Clone(), preferHall);
            }
            Loc dest = locRay.Traverse(1);

            if (floorPlan.GetRoomPlan(dest) == null)
            {
                floorPlan.AddRoom(dest, roomGen, collection.Clone(), preferHall);
            }
        }
Esempio n. 4
0
        public void AddRoom(Rect rect, IRoomGen gen, ComponentCollection components, bool preferHall)
        {
            Rect floorRect = new Rect(0, 0, this.GridWidth, this.GridHeight);

            if (!floorRect.Contains(rect))
            {
                throw new ArgumentOutOfRangeException(nameof(rect), "Cannot add room out of bounds!");
            }

            for (int xx = rect.Start.X; xx < rect.End.X; xx++)
            {
                for (int yy = rect.Start.Y; yy < rect.End.Y; yy++)
                {
                    if (this.Rooms[xx][yy] != -1)
                    {
                        throw new InvalidOperationException("Tried to add on top of an existing room!");
                    }
                    if (xx > rect.Start.X && this.HHalls[xx - 1][yy].MainHall != null)
                    {
                        throw new InvalidOperationException("Tried to add on top of an existing hall!");
                    }
                    if (yy > rect.Start.Y && this.VHalls[xx][yy - 1].MainHall != null)
                    {
                        throw new InvalidOperationException("Tried to add on top of an existing hall!");
                    }
                }
            }

            if (preferHall && !(gen is IPermissiveRoomGen))
            {
                throw new InvalidOperationException("Cannot prefer hall for a non-permissive gen!");
            }

            var room = new GridRoomPlan(rect, gen.Copy(), components)
            {
                PreferHall = preferHall,
            };

            this.ArrayRooms.Add(room);
            for (int xx = rect.Start.X; xx < rect.End.X; xx++)
            {
                for (int yy = rect.Start.Y; yy < rect.End.Y; yy++)
                {
                    this.Rooms[xx][yy] = this.ArrayRooms.Count - 1;
                }
            }
        }
Esempio n. 5
0
        public void AddRoom(IRoomGen gen, ComponentCollection components, params RoomHallIndex[] attached)
        {
            // check against colliding on other rooms (and not halls)
            foreach (var room in this.Rooms)
            {
                if (Collision.Collides(room.RoomGen.Draw, gen.Draw))
                {
                    throw new InvalidOperationException("Tried to add on top of an existing room!");
                }
            }

            foreach (var hall in this.Halls)
            {
                if (Collision.Collides(hall.RoomGen.Draw, gen.Draw))
                {
                    throw new InvalidOperationException("Tried to add on top of an existing hall!");
                }
            }

            // check against rooms that go out of bounds
            if (!this.DrawRect.Contains(gen.Draw))
            {
                throw new InvalidOperationException("Tried to add out of range!");
            }

            // we expect that the room has already been given a size
            // and that its fulfillables match up with its adjacent's fulfillables.
            var plan = new FloorRoomPlan(gen, components);

            // attach everything
            plan.Adjacents.AddRange(attached);
            foreach (RoomHallIndex fromRoom in attached)
            {
                IFloorRoomPlan fromPlan = this.GetRoomHall(fromRoom);
                fromPlan.Adjacents.Add(new RoomHallIndex(this.Rooms.Count, false));
            }

            this.Rooms.Add(plan);
        }
Esempio n. 6
0
 public void AddRoom(Rect rect, IRoomGen gen, ComponentCollection components)
 {
     this.AddRoom(rect, gen, components, false);
 }
Esempio n. 7
0
 public void AddRoom(Loc loc, IRoomGen gen, ComponentCollection components, bool preferHall)
 {
     this.AddRoom(new Rect(loc, new Loc(1)), gen, components, preferHall);
 }
Esempio n. 8
0
 public void AddRoom(Loc loc, IRoomGen gen, ComponentCollection components)
 {
     this.AddRoom(new Rect(loc, new Loc(1)), gen, components, false);
 }
Esempio n. 9
0
 public FloorHallPlan(IPermissiveRoomGen roomGen, ComponentCollection components)
 {
     this.RoomGen    = roomGen;
     this.Components = components;
     this.Adjacents  = new List <RoomHallIndex>();
 }
Esempio n. 10
0
        public void PlaceRoom(IRandom rand, FloorPlan floorPlan, IRoomGen newGen, RoomHallIndex oldRoomHall)
        {
            // first get the adjacents of the removed room
            Dictionary <Dir4, List <RoomHallIndex> > adjacentsByDir = GetDirectionAdjacents(floorPlan, oldRoomHall);
            IRoomPlan oldPlan = floorPlan.GetRoomHall(oldRoomHall);

            // remove the room; update the adjacents too
            floorPlan.EraseRoomHall(oldRoomHall);
            foreach (Dir4 dir in DirExt.VALID_DIR4)
            {
                for (int jj = 0; jj < adjacentsByDir[dir].Count; jj++)
                {
                    RoomHallIndex adjRoomHall = adjacentsByDir[dir][jj];
                    if (adjRoomHall.IsHall == oldRoomHall.IsHall &&
                        adjRoomHall.Index > oldRoomHall.Index)
                    {
                        adjacentsByDir[dir][jj] = new RoomHallIndex(adjRoomHall.Index - 1, adjRoomHall.IsHall);
                    }
                }
            }

            var newAdjacents = new List <RoomHallIndex>();
            var supportHalls = new Dictionary <Dir4, IPermissiveRoomGen>();

            foreach (Dir4 dir in DirExt.VALID_DIR4)
            {
                if (newGen.Draw.GetScalar(dir) == oldPlan.RoomGen.Draw.GetScalar(dir))
                {
                    newAdjacents.AddRange(adjacentsByDir[dir]);
                }
                else if (adjacentsByDir[dir].Count > 0)
                {
                    Rect supportRect = GetSupportRect(floorPlan, oldPlan.RoomGen, newGen, dir, adjacentsByDir[dir]);
                    var  supportHall = (IPermissiveRoomGen)this.Halls.Pick(rand).Copy();
                    supportHall.PrepareSize(rand, supportRect.Size);
                    supportHall.SetLoc(supportRect.Start);
                    supportHalls[dir] = supportHall;
                }
            }

            // add the new room
            var newRoomInd = new RoomHallIndex(floorPlan.RoomCount, false);
            ComponentCollection newCollection = oldPlan.Components.Clone();

            foreach (RoomComponent component in this.RoomComponents)
            {
                newCollection.Set(component.Clone());
            }
            floorPlan.AddRoom(newGen, newCollection, newAdjacents.ToArray());

            // add supporting halls
            foreach (Dir4 dir in DirExt.VALID_DIR4)
            {
                if (supportHalls.ContainsKey(dir))
                {
                    // include an attachment to the newly added room
                    List <RoomHallIndex> adjToAdd = new List <RoomHallIndex> {
                        newRoomInd
                    };
                    adjToAdd.AddRange(adjacentsByDir[dir]);
                    ComponentCollection newHallCollection = oldPlan.Components.Clone();
                    foreach (RoomComponent component in this.HallComponents)
                    {
                        newHallCollection.Set(component.Clone());
                    }
                    floorPlan.AddHall(supportHalls[dir], newHallCollection.Clone(), adjToAdd.ToArray());
                }
            }
        }
Esempio n. 11
0
 public static void UnsafeAddHall(LocRay4 locRay, GridPlan floorPlan, IPermissiveRoomGen hallGen, ComponentCollection components)
 {
     floorPlan.SetHall(locRay, hallGen, components.Clone());
     GenContextDebug.DebugProgress("Hall");
     if (floorPlan.GetRoomPlan(locRay.Loc) == null || floorPlan.GetRoomPlan(locRay.Traverse(1)) == null)
     {
         floorPlan.Clear();
         throw new InvalidOperationException("Can't create a hall without rooms to connect!");
     }
 }
Esempio n. 12
0
 public GridHallPlan(IPermissiveRoomGen roomGen, ComponentCollection components)
 {
     this.RoomGen    = roomGen;
     this.Components = components;
 }
Esempio n. 13
0
 public GridRoomPlan(Rect bounds, IRoomGen roomGen, ComponentCollection components)
 {
     this.Bounds     = bounds;
     this.RoomGen    = roomGen;
     this.Components = components;
 }