Ejemplo n.º 1
0
 public LevelLayout Generate()
 {
     #region DEBUG
     float startTime = 0;
     if (BigBoss.Debug.logging(Logs.LevelGenMain))
     {
         BigBoss.Debug.printHeader(Logs.LevelGenMain, "Generating Level: " + Depth);
         startTime = Time.realtimeSinceStartup;
     }
     #endregion
     Layout = new LevelLayout()
     {
         Random = Rand
     };
     Container = new LayoutObjectContainer();
     Log("Mod Rooms", false, GenerateRoomShells, ModRooms);
     Log("Cluster", true, ClusterRooms);
     Log("Place Rooms", true, PlaceRooms);
     Log("Confirm Connection", true, ConfirmConnection);
     Log("Place Stairs", true, PlaceStairs);
     Log("Confirm Edges", true, ConfirmEdges);
     #region DEBUG
     if (BigBoss.Debug.logging())
     {
         BigBoss.Debug.w(Logs.LevelGenMain, "Generate Level took: " + (Time.realtimeSinceStartup - startTime));
         Container.ToLog(Logs.LevelGenMain);
         BigBoss.Debug.printFooter(Logs.LevelGenMain, "Generating Level: " + Depth);
     }
     #endregion
     Layout.Grids.PutAll(Container.GetGrid());
     return(Layout);
 }
Ejemplo n.º 2
0
 protected void PlaceRooms()
 {
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         BigBoss.Debug.printHeader(Logs.LevelGen, "Place Rooms");
     }
     #endregion
     List <ILayoutObject> unplacedRooms = new List <ILayoutObject>(Objects);
     List <ILayoutObject> placedRooms   = new List <ILayoutObject>();
     if (unplacedRooms.Count > 0)
     { // Add seed
         ILayoutObject seed = unplacedRooms.Take();
         Container.Objects.Add(seed);
         placedRooms.Add(seed);
     }
     foreach (ILayoutObject room in unplacedRooms)
     {
         // Find room it will start from
         int           roomNum   = Rand.Next(placedRooms.Count);
         ILayoutObject startRoom = placedRooms[roomNum];
         room.CenterOn(startRoom);
         // Find where it will shift away
         Point shiftMagn = GenerateShiftMagnitude(shiftRange, Rand);
         #region DEBUG
         if (BigBoss.Debug.logging(Logs.LevelGen))
         {
             BigBoss.Debug.w(Logs.LevelGen, "Placing room: " + room);
             BigBoss.Debug.w(Logs.LevelGen, "Picked starting room number: " + roomNum);
             BigBoss.Debug.w(Logs.LevelGen, "Shift: " + shiftMagn);
         }
         #endregion
         room.ShiftOutside(placedRooms, shiftMagn);
         placedRooms.Add(room);
         Container.Objects.Add(room);
         #region DEBUG
         if (BigBoss.Debug.logging(Logs.LevelGen))
         {
             Container.ToLog(Logs.LevelGen, "Layout after placing room at: " + room.Bounding);
             BigBoss.Debug.printBreakers(Logs.LevelGen, 4);
         }
         #endregion
     }
     #region DEBUG
     BigBoss.Debug.printFooter(Logs.LevelGen, "Place Rooms");
     #endregion
 }
Ejemplo n.º 3
0
 protected void ClusterRooms()
 {
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         BigBoss.Debug.printHeader(Logs.LevelGen, "Cluster Rooms");
     }
     #endregion
     List <LayoutObject> ret = new List <LayoutObject>();
     int numClusters         = Rand.Next(maxRoomClusters - minRoomClusters) + minRoomClusters;
     // Num clusters cannot be more than half num rooms
     if (numClusters > Objects.Count / 2)
     {
         numClusters = Objects.Count / 2;
     }
     List <LayoutObjectContainer> clusters = new List <LayoutObjectContainer>();
     for (int i = 0; i < numClusters; i++)
     {
         clusters.Add(new LayoutObjectContainer());
     }
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         BigBoss.Debug.w(Logs.LevelGen, "Number of clusters: " + numClusters);
     }
     #endregion
     // Add two rooms to each
     foreach (LayoutObjectContainer cluster in clusters)
     {
         LayoutObject obj1 = (LayoutObject)Objects.Take();
         LayoutObject obj2 = (LayoutObject)Objects.Take();
         cluster.Objects.Add(obj1);
         ClusterAround(cluster, obj2);
         cluster.Objects.Add(obj2);
         #region DEBUG
         if (BigBoss.Debug.logging(Logs.LevelGen))
         {
             cluster.ToLog(Logs.LevelGen);
         }
         #endregion
     }
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         BigBoss.Debug.w(Logs.LevelGen, "Rooms left: " + Objects.Count);
     }
     #endregion
     // For remaining rooms, put into random clusters
     foreach (LayoutObject r in new List <ILayoutObject>(Objects))
     {
         if (Rand.Percent(clusterProbability))
         {
             LayoutObjectContainer cluster = clusters.Random(Rand);
             ClusterAround(cluster, r);
             cluster.Objects.Add(r);
             Objects.Remove(r);
             #region DEBUG
             if (BigBoss.Debug.logging(Logs.LevelGen))
             {
                 cluster.ToLog(Logs.LevelGen);
             }
             #endregion
         }
     }
     // Add Clusters to rooms list
     foreach (ILayoutObject cluster in clusters)
     {
         Objects.Add(cluster);
     }
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         foreach (LayoutObjectContainer cluster in clusters)
         {
             cluster.ToLog(Logs.LevelGen);
         }
         BigBoss.Debug.printFooter(Logs.LevelGen, "Cluster Rooms");
     }
     #endregion
 }