Пример #1
0
 public static DrawAction <GenSpace> Walkable()
 {
     return(new DrawAction <GenSpace>((arr, x, y) =>
     {
         GenSpace space;
         if (arr.TryGetValue(x, y, out space))
         {
             if (space == null)
             {
                 return false;
             }
             if (!GridTypeEnum.Walkable(space.Type))
             {
                 return false;
             }
             if (space.Deploys == null)
             {
                 return true;
             }
             foreach (GenDeploy deploy in space.Deploys)
             {
                 if (!deploy.Element.Walkable)
                 {
                     return false;
                 }
             }
             return true;
         }
         return false;
     }));
 }
Пример #2
0
 public static DrawAction <T> WallType <T>()
     where T : IGridSpace
 {
     return(new DrawAction <T>((arr, x, y) =>
     {
         return GridTypeEnum.WallType(arr[x, y].GetGridType());
     }));
 }
Пример #3
0
 public void Initialize()
 {
     _levels = new Level[_maxLevels];
     ArrayExt.Converters[typeof(GridType)]  = (b) => { return(GridTypeEnum.Convert((GridType)b)); };
     ArrayExt.Converters[typeof(GridSpace)] = (b) =>
     {
         GridSpace s = b as GridSpace;
         if (s == null)
         {
             return(GridTypeEnum.Convert(GridType.NULL));
         }
         return(GridTypeEnum.Convert(s.Type));
     };
     ArrayExt.Converters[typeof(GenSpace)] = (b) =>
     {
         GenSpace s = b as GenSpace;
         if (s == null)
         {
             return(GridTypeEnum.Convert(GridType.NULL));
         }
         return(s.GetChar());
     };
     ArrayExt.Converters[typeof(IGridSpace)] = (b) =>
     {
         IGridSpace s = b as IGridSpace;
         if (s == null)
         {
             return(GridTypeEnum.Convert(GridType.NULL));
         }
         if (s is GenSpace)
         {
             return(((GenSpace)s).GetChar());
         }
         return(GridTypeEnum.Convert(s.Type));
     };
     if (Seed == -1)
     {
         Seed = Probability.Rand.Next();
     }
     System.Random rand = new System.Random(Seed);
     for (int i = 0; i < _maxLevels; i++)
     {
         _levelSeeds[i] = rand.Next();
     }
     LevelBuilder.Initialize();
     foreach (IInitializable init in this.FindAllDerivedObjects <IInitializable>())
     {
         init.Init();
     }
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGenMain))
     {
         BigBoss.Debug.w(Logs.LevelGenMain, "Random seed int: " + Seed);
     }
     #endregion
 }
Пример #4
0
 public char GetChar()
 {
     if (Deploys != null)
     {
         foreach (GenDeploy d in Deploys)
         {
             if (!string.IsNullOrEmpty(d.Element.PrintChar))
             {
                 return(d.Element.PrintChar[0]);
             }
         }
     }
     return(GridTypeEnum.Convert(Type));
 }
Пример #5
0
    protected bool UpdateCurrentTileVectors()
    {
        Vector2   currentLoc   = new Vector2(GO.transform.position.x.Round(), GO.transform.position.z.Round());
        GridSpace newGridSpace = BigBoss.Levels.Level[currentLoc.x.ToInt(), currentLoc.y.ToInt()];

        if (!newGridSpace.IsBlocked() && GridTypeEnum.Walkable(newGridSpace.Type))
        {
            GridSpace = newGridSpace;
            BigBoss.Gooey.CheckChestDistance();
            return(true);
        }
        else
        {
            return(false);
        }
    }
Пример #6
0
 public bool isValidSpace(GridSpace p)
 {
     if (p != null)
     {
         try
         {
             if (p.X == dest.X && p.Y == dest.Y)
             {
                 return(true);
             }
             if (GridTypeEnum.Walkable(p.Type))
             {
                 return(true);
             }
         }
         catch (NullReferenceException)
         {
             //the array location doesn't exist
         }
     }
     return(false);
 }
Пример #7
0
    protected void ClusterAround(LayoutObjectContainer cluster, LayoutObject obj)
    {
        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.printHeader("Cluster Around");
        }
        #endregion
        obj.ShiftOutside(cluster, new Point(1, 0), null, false, false);
        obj.Shift(-1, 0); // Shift to overlapping slightly
        MultiMap <bool> visited = new MultiMap <bool>();
        visited[0, 0] = true;
        ProbabilityList <ClusterInfo> shiftOptions = new ProbabilityList <ClusterInfo>();
        Queue <Point> shiftQueue = new Queue <Point>();
        shiftQueue.Enqueue(new Point());
        Container2D <GenSpace> clusterGrid = cluster.GetGrid();
        Container2D <GenSpace> objGrid     = obj.GetGrid();
        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            var tmp = new MultiMap <GenSpace>();
            tmp.PutAll(obj.GetGrid());
            tmp.PutAll(cluster.GetGrid());
            tmp.ToLog(Logs.LevelGen, "Starting placement");
        }
        #endregion
        while (shiftQueue.Count > 0)
        {
            Point curShift = shiftQueue.Dequeue();
            #region Debug
            if (BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps) && BigBoss.Debug.logging(Logs.LevelGen))
            {
                var tmpMap = new MultiMap <GenSpace>();
                tmpMap.PutAll(clusterGrid);
                tmpMap.PutAll(objGrid, curShift);
                tmpMap.ToLog(Logs.LevelGen, "Analyzing at shift " + curShift);
            }
            #endregion
            // Test if pass
            List <Point> intersectPoints = new List <Point>();
            if (objGrid.DrawAll((arr, x, y) =>
            {
                if (GridTypeEnum.EdgeType(arr[x, y].GetGridType()))
                {
                    GridType clusterType = clusterGrid[x + curShift.x, y + curShift.y].GetGridType();
                    if (clusterType == GridType.NULL)
                    {
                        return(true);
                    }
                    intersectPoints.Add(new Point(x, y));
                    return(GridTypeEnum.EdgeType(clusterType));
                }
                else
                {
                    return(!clusterGrid.Contains(x + curShift.x, y + curShift.y));
                }
            }) &&
                intersectPoints.Count > 0)
            { // Passed test
                // queue surrounding points
                visited.DrawAround(curShift.x, curShift.y, true, Draw.Not(Draw.EqualTo(true)).IfThen(Draw.AddTo <bool>(shiftQueue).And(Draw.SetTo(true))));

                #region Debug
                if (BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps) && BigBoss.Debug.logging(Logs.LevelGen))
                {
                    BigBoss.Debug.w(Logs.LevelGen, "passed with " + intersectPoints.Count);
                }
                #endregion
                shiftOptions.Add(new ClusterInfo()
                {
                    Shift = curShift, Intersects = intersectPoints
                }, Math.Pow(intersectPoints.Count, 3));
            }
        }
        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            shiftOptions.ToLog(Logs.LevelGen, "Shift options");
        }
        #endregion
        List <Point> clusterDoorOptions = new List <Point>();
        ClusterInfo  info;
        var          placed = new List <Value2D <GenSpace> >(0);
        while (shiftOptions.Take(Rand, out info))
        {
            clusterGrid.DrawPoints(info.Intersects, Draw.CanDrawDoor().IfThen(Draw.AddTo <GenSpace>(clusterDoorOptions)).Shift(info.Shift));
            #region Debug
            if (BigBoss.Debug.logging(Logs.LevelGen))
            {
                BigBoss.Debug.w(Logs.LevelGen, "selected " + info.Shift);
                var tmpMap = new MultiMap <GenSpace>();
                clusterGrid.DrawAll(Draw.CopyTo(tmpMap));
                objGrid.DrawAll(Draw.CopyTo(tmpMap, info.Shift));
                tmpMap.DrawPoints(info.Intersects, Draw.SetTo(GridType.INTERNAL_RESERVED_CUR, Theme).Shift(info.Shift));
                tmpMap.ToLog(Logs.LevelGen, "Intersect Points");
                tmpMap = new MultiMap <GenSpace>();
                clusterGrid.DrawAll(Draw.CopyTo(tmpMap));
                objGrid.DrawAll(Draw.CopyTo(tmpMap, info.Shift));
                tmpMap.DrawPoints(clusterDoorOptions, Draw.SetTo(GridType.Door, Theme));
                tmpMap.ToLog(Logs.LevelGen, "Cluster door options");
            }
            #endregion
            if (clusterDoorOptions.Count > 0)
            { // Cluster side has door options
                obj.Shift(info.Shift.x, info.Shift.y);
                placed = obj.PlaceSomeDoors(clusterDoorOptions, Theme, Rand);
                if (placed.Count != 0)
                { // Placed a door
                    foreach (Point p in placed)
                    {
                        LayoutObject clusterObj;
                        cluster.GetObjAt(p, out clusterObj);
                        obj.Connect(clusterObj);
                    }
                    break;
                }
                else
                {
                    #region Debug
                    if (BigBoss.Debug.logging(Logs.LevelGen))
                    {
                        BigBoss.Debug.w(Logs.LevelGen, "selected point failed to match " + info.Shift + ". Backing up");
                    }
                    #endregion
                    obj.Shift(-info.Shift.x, -info.Shift.y);
                }
            }
        }
        if (placed.Count == 0)
        {
            throw new ArgumentException("Could not cluster rooms");
        }
        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            var tmpMap = new MultiMap <GenSpace>();
            tmpMap.PutAll(clusterGrid);
            tmpMap.PutAll(obj.GetGrid());
            tmpMap.ToLog(Logs.LevelGen, "Final setup " + info.Shift);
            BigBoss.Debug.printFooter("Cluster Around");
        }
        #endregion
    }