コード例 #1
0
ファイル: Draw.cs プロジェクト: NerdDev/Hackmobile
 public static DrawAction <T> Set <T>(Value2D <T> val)
 {
     return((arr, x, y) =>
     {
         val.val = arr[x, y];
         val.x = x;
         val.y = y;
         return true;
     });
 }
コード例 #2
0
 public override IEnumerator <Value2D <T> > GetEnumerator()
 {
     foreach (KeyValuePair <int, Dictionary <int, T> > row in multimap)
     {
         foreach (KeyValuePair <int, T> val in row.Value)
         {
             var ret = new Value2D <T>(val.Key, row.Key, val.Value);
             yield return(ret);
         }
     }
 }
コード例 #3
0
    public bool FindAndConnect(LayoutObject obj1, Point connectPt)
    {
        Point        pt = new Value2D <GridType>(connectPt.x + obj1.ShiftP.x, connectPt.y + obj1.ShiftP.y);
        LayoutObject obj;

        if (GetObjAt(pt, out obj))
        {
            obj1.Connect(obj);
            return(true);
        }
        return(false);
    }
コード例 #4
0
    public bool Pick(System.Random rand, out Value2D <T> ret, bool take = false)
    {
        List <Value2D <T> > list = Pick(rand, 1, 0, take);

        if (list.Count == 0)
        {
            ret = null;
            return(false);
        }
        ret = list[0];
        return(true);
    }
コード例 #5
0
 public override IEnumerator <Value2D <T> > GetEnumerator()
 {
     for (int y = 0; y < arr.GetLength(0); y++)
     {
         for (int x = 0; x < arr.GetLength(1); x++)
         {
             if (present[y, x])
             {
                 var val = new Value2D <T>(x + shift.x, y + shift.y, arr[y, x]);
                 yield return(val);
             }
         }
     }
 }
コード例 #6
0
    public override List <Value2D <T> > GetRandom(System.Random random, int amount, int distance = 0, bool take = false)
    {
        MultiMap <T>        removed = new MultiMap <T>();
        List <Value2D <T> > list    = new List <Value2D <T> >();

        if (distance < 0)
        {
            distance = 0;
        }
        for (int i = 0; i < amount; i++)
        {
            Value2D <T> g = RandomValue(random);
            if (g == null)
            {
                return(list);
            }
            if (distance > 0)
            {
                for (int yCur = g.y - distance; yCur <= g.y + distance; yCur++)
                {
                    for (int xCur = g.x - distance; xCur <= g.x + distance; xCur++)
                    {
                        removed[g] = g.val;
                        Remove(xCur, yCur);
                    }
                }
            }
            Remove(g.x, g.y, distance - 1);
            list.Add(g);
        }
        if (take)
        {
            foreach (Value2D <T> val in list)
            {
                removed.Remove(val);
            }
        }
        this.PutAll(removed);
        return(list);
    }
コード例 #7
0
ファイル: Value2D.cs プロジェクト: NerdDev/Hackmobile
    public override bool Equals(object obj)
    {
        Value2D <T> rhs = obj as Value2D <T>;

        if (rhs == null)
        {
            return(false);
        }
        if (x != rhs.x || y != rhs.y)
        {
            return(false);
        }
        if (val == null)
        {
            return(rhs.val == null);
        }
        if (rhs.val == null)
        {
            return(false);
        }
        return(val.Equals(rhs.val));
    }
コード例 #8
0
    protected bool FindNextPathPoints(Container2D <GenSpace> map,
                                      Container2D <GenSpace> runningConnected,
                                      out LayoutObject hit,
                                      DrawAction <GenSpace> pass,
                                      Queue <Value2D <GenSpace> > curQueue,
                                      Container2D <bool> curVisited,
                                      out Value2D <GenSpace> startPoint,
                                      out Value2D <GenSpace> endPoint)
    {
        if (!map.DrawBreadthFirstSearch(
                curQueue, curVisited, false,
                Draw.IsType <GenSpace>(GridType.NULL),
                pass,
                out endPoint))
        {
            hit        = null;
            startPoint = null;
            return(false);
        }
        if (!Container.GetObjAt(endPoint, out hit))
        {
            startPoint = null;
            return(false);
        }
        Container2D <bool>          hitVisited;
        Queue <Value2D <GenSpace> > hitQueue;

        ConstructBFS(hit, out hitQueue, out hitVisited);
        curQueue.Enqueue(hitQueue);
        curVisited.PutAll(hitVisited);
        return(map.DrawBreadthFirstSearch(
                   hitQueue, hitVisited, false,
                   Draw.IsType <GenSpace>(GridType.NULL),
                   pass.And(Draw.ContainedIn(runningConnected)),
                   out startPoint));
    }
コード例 #9
0
ファイル: DungeonMaster.cs プロジェクト: NerdDev/Hackmobile
 public bool PickSpawnableLocation(out Value2D <GridSpace> pick)
 {
     return(PickSpawnableLocation(BigBoss.Levels.Level, out pick));
 }
コード例 #10
0
ファイル: DungeonMaster.cs プロジェクト: NerdDev/Hackmobile
    public bool PickSpawnableLocation(Level l, out Value2D <GridSpace> pick)
    {
        MultiMap <GridSpace> room = Spawnable(l, l.RoomMaps.Random(Probability.SpawnRand));

        return(room.GetRandom(Probability.SpawnRand, out pick));
    }
コード例 #11
0
ファイル: Value2D.cs プロジェクト: NerdDev/Hackmobile
 public Value2D(Value2D <T> rhs)
     : base(rhs)
 {
     val = rhs.val;
 }
コード例 #12
0
ファイル: Path.cs プロジェクト: NerdDev/Hackmobile
 void Prune()
 {
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.LevelGen_Path_Simplify_Prune))
     {
         BigBoss.Debug.printHeader(Logs.LevelGen, "Prune");
     }
     #endregion
     Bounding bounds = new Bounding();
     foreach (Value2D <GenSpace> g in List)
     {
         bounds.Absorb(g);
     }
     Array2D <int> indexes          = new Array2D <int>(bounds);
     List <Value2D <GenSpace> > tmp = new List <Value2D <GenSpace> >(List);
     int index = 0;
     foreach (Value2D <GenSpace> val in tmp)
     { // For each point on the path
         int           lastDiff = 0;
         Value2D <int> neighbor = null;
         indexes.DrawAround(val.x, val.y, false, (arr2, x, y) =>
         { // Find neighboring point on path with the largest distance from current
             if (arr2[x, y] == 0)
             {
                 return(true);
             }
             int valDiff = Mathf.Abs(index - arr2[x, y]);
             if (valDiff > 1 && // Diff meets requirements
                 (neighbor == null || lastDiff < valDiff))    // Larger than last found diff
             {
                 lastDiff = valDiff;
                 neighbor = new Value2D <int>(x, y, arr2[x, y]);
             }
             return(true);
         });
         #region DEBUG
         if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.LevelGen_Path_Simplify_Prune))
         {
             BigBoss.Debug.w(Logs.LevelGen, "Evaluating " + val);
             if (neighbor != null)
             {
                 BigBoss.Debug.w(Logs.LevelGen, "Found Neighbor " + neighbor);
             }
         }
         #endregion
         if (neighbor != null)
         { // If point of interest exists, prune
             int fromIndex = neighbor.val + 1;
             int count     = index - neighbor.val - 1;
             // Set indices to 0
             List <Value2D <GenSpace> > toRemove = List.GetRange(fromIndex, count);
             foreach (Value2D <GenSpace> r in toRemove)
             {
                 indexes[r.x, r.y] = 0;
             }
             // Remove
             List.RemoveRange(fromIndex, count);
             // Set next index to proper number
             index = neighbor.val + 1;
             #region DEBUG
             if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.LevelGen_Path_Simplify_Prune))
             {
                 BigBoss.Debug.w(Logs.LevelGen, "Removed index: " + fromIndex + " count: " + count);
                 MultiMap <GridType> map = new MultiMap <GridType>();
                 foreach (var v in List)
                 {
                     map[v] = v.val.Type;
                 }
                 map.ToLog(Logs.LevelGen);
             }
             #endregion
         }
         indexes[val.x, val.y] = index;
         index++;
     }
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.LevelGen_Path_Simplify_Prune))
     {
         BigBoss.Debug.printFooter(Logs.LevelGen, "Prune");
     }
     #endregion
 }