Пример #1
0
            public static LinkedRoom LinkRoomAnywhere(RandoLogic logic, LinkedRoom start, StaticRoom room, bool isBacktrack = false)
            {
                float      jumpScale = 8 * 150;
                int        jumpDir   = 0;
                LinkedRoom toRoom    = null;
                Vector2    newPosition;

                while (true)
                {
                    newPosition = start.Position + Vector2.UnitX * jumpScale * (jumpDir == 0 ? 1 : jumpDir == 1 ? -1 : 0)
                                  + Vector2.UnitY * jumpScale * (jumpDir == 2 ? 1 : jumpDir == 3 ? -1 : 0);
                    toRoom             = new LinkedRoom(room, newPosition);
                    toRoom.IsBacktrack = isBacktrack;

                    if (logic.Map.AreaFree(toRoom))
                    {
                        break;
                    }

                    if (++jumpDir == 4)
                    {
                        jumpDir    = 0;
                        jumpScale *= 2f;
                    }
                }

                logic.Map.AddRoom(toRoom);
                return(toRoom);
            }
Пример #2
0
 public void RemoveRoom(LinkedRoom room)
 {
     this.Rooms.Remove(room);
     if (room == this.CachedHit)
     {
         this.CachedHit = null;
     }
 }
Пример #3
0
 public void RemoveRoom(LinkedRoom room)
 {
     this.Rooms.Remove(room);
     this.Worth -= room.Static.Worth;
     if (room == this.CachedHit)
     {
         this.CachedHit = null;
     }
 }
Пример #4
0
 public void AddRoom(LinkedRoom room)
 {
     this.Rooms.Add(room);
     this.Worth += room.Static.Worth;
     if (room.IsBacktrack)
     {
         this.Worth += room.Static.Worth;
     }
 }
Пример #5
0
            public static ConnectAndMapReceipt Do(RandoLogic logic, UnlinkedEdge fromEdge, StaticEdge toEdge)
            {
                var toRoomStatic = toEdge.FromNode.ParentRoom;
                var fromRoom     = fromEdge.Node.Room;

                if (fromEdge.Static.HoleTarget == null || toEdge.HoleTarget == null)
                {
                    return(null);
                }

                var newOffset = fromEdge.Static.HoleTarget.Compatible(toEdge.HoleTarget);

                if (newOffset == Hole.INCOMPATIBLE)
                {
                    return(null);
                }

                var newPosition = toRoomStatic.AdjacentPosition(fromRoom.Bounds, fromEdge.Static.HoleTarget.Side, newOffset);
                var toRoom      = new LinkedRoom(toRoomStatic, newPosition);

                if (!logic.Map.AreaFree(toRoom))
                {
                    return(null);
                }

                logic.Map.AddRoom(toRoom);
                var newEdge = new LinkedEdge {
                    NodeA   = fromEdge.Node,
                    NodeB   = toRoom.Nodes[toEdge.FromNode.Name],
                    StaticA = fromEdge.Static,
                    StaticB = toEdge,
                };

                newEdge.NodeA.Edges.Add(newEdge);
                newEdge.NodeB.Edges.Add(newEdge);

                if (!logic.Settings.RepeatRooms)
                {
                    logic.RemainingRooms.Remove(toRoomStatic);
                }

                Logger.Log("randomizer", $"Adding room {toRoomStatic.Name} at {newPosition} ({logic.Map.Count})");
                return(new ConnectAndMapReceipt {
                    NewRoom = toRoom,
                    Logic = logic,
                    Edge = newEdge,
                    EntryNode = toRoom.Nodes[toEdge.FromNode.Name],
                });
            }
Пример #6
0
 public bool AreaFree(LinkedRoom room)
 {
     if (!this.AreaFree(room.Bounds))
     {
         return(false);
     }
     foreach (var r in room.ExtraBounds)
     {
         if (!this.AreaFree(r))
         {
             return(false);
         }
     }
     return(true);
 }
Пример #7
0
            public static StartRoomReceipt Do(RandoLogic logic, StaticRoom newRoomStatic)
            {
                Logger.Log("randomizer", $"Adding room {newRoomStatic.Name} at start");
                var newRoom = new LinkedRoom(newRoomStatic, Vector2.Zero);

                logic.Map.AddRoom(newRoom);

                if (!logic.Settings.RepeatRooms)
                {
                    logic.RemainingRooms.Remove(newRoomStatic);
                }

                return(new StartRoomReceipt {
                    Logic = logic,
                    NewRoom = newRoom,
                });
            }
Пример #8
0
            public static StartRoomReceipt Do(RandoLogic logic, StaticRoom newRoomStatic)
            {
                Logger.Log("randomizer", $"Adding room {newRoomStatic.Name} at start");
                var newRoom = new LinkedRoom(newRoomStatic, Vector2.Zero);
                var extras  = ConnectAndMapReceipt.WarpClosure(logic, newRoom.Nodes["main"]);

                logic.Map.AddRoom(newRoom);

                if (!logic.Settings.RepeatRooms)
                {
                    logic.RemainingRooms.Remove(newRoomStatic);
                    foreach (var extra in extras)
                    {
                        logic.RemainingRooms.Remove(extra.Static);
                    }
                }

                return(new StartRoomReceipt {
                    Logic = logic,
                    NewRoom = newRoom,
                    ExtraRooms = extras,
                });
            }
Пример #9
0
        public bool HoleFree(LinkedRoom level, Hole hole)
        {
            Vector2 outward = hole.Side.Unit() * (hole.Side == ScreenDirection.Up || hole.Side == ScreenDirection.Down ? 180 : 320);
            Vector2 pt1v    = hole.LowCoord(level.Bounds) + outward;
            Vector2 pt2v    = hole.HighCoord(level.Bounds) + outward;
            Point   pt1     = new Point((int)pt1v.X, (int)pt1v.Y);
            Point   pt2     = new Point((int)pt2v.X, (int)pt2v.Y);

            foreach (var room in this.Rooms)
            {
                if (room.Bounds.Contains(pt1))
                {
                    return(false);
                }
            }
            foreach (var room in this.Rooms)
            {
                if (room.Bounds.Contains(pt2))
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #10
0
        public bool AreaFree(Rectangle rect)
        {
            if (this.CachedHit != null)
            {
                if (CachedHit.Bounds.Intersects(rect))
                {
                    return(false);
                }
                foreach (var r in CachedHit.ExtraBounds)
                {
                    if (r.Intersects(rect))
                    {
                        return(false);
                    }
                }
            }

            foreach (var room in this.Rooms)
            {
                if (room.Bounds.Intersects(rect))
                {
                    this.CachedHit = room;
                    return(false);
                }
                foreach (var r in room.ExtraBounds)
                {
                    if (r.Intersects(rect))
                    {
                        this.CachedHit = room;
                        return(false);
                    }
                }
            }

            return(true);
        }
Пример #11
0
 public void AddRoom(LinkedRoom room)
 {
     this.Rooms.Add(room);
     this.Worth += room.Static.Worth;
 }
Пример #12
0
 public void Clear()
 {
     this.Rooms.Clear();
     this.CachedHit = null;
     this.nonce     = 0;
 }
Пример #13
0
            public static PlaceCollectableReceipt Do(LinkedNode node, StaticCollectable place, LinkedCollectable item, bool autoBubble, int keyholeID, LinkedRoom keyholeRoom)
            {
                var result = Do(node, place, item, autoBubble);

                keyholeRoom.UsedKeyholes.Add(keyholeID);
                result.KeyholeID   = keyholeID;
                result.KeyholeRoom = keyholeRoom;
                return(result);
            }
Пример #14
0
 public void AddRoom(LinkedRoom room)
 {
     this.Rooms.Add(room);
 }