Beispiel #1
0
        public static bool TryGetRoom(
            int width, int height, FloorGenData genData,
            out PrefabRoom room, TagSetCheck setCheck)
        {
            if (_sizeTable.ContainsKey(new Vector2Int(width, height)))
            {
                // there is a room of that size
                foreach (var r in _sizeTable[new Vector2Int(width, height)].AsArray().EnumerateRandom())
                {
                    if (genData.PlacedRooms.Contains(r))
                    {
                        continue;
                    }

                    bool valid = true;

                    foreach (var myTag in r.Tags)
                    {
                        if (genData.ExcludedTags.ContainsKey(myTag))
                        {
                            valid = false;
                            break;
                        }
                    }
                    if (!valid)
                    {
                        continue;
                    }
                    foreach (var exTag in r.ExcludeTags)
                    {
                        if (genData.ExistingTags.ContainsKey(exTag))
                        {
                            valid = false;
                            break;
                        }
                    }
                    if (!valid)
                    {
                        continue;
                    }
                    var hash = r.HashTags;
                    foreach (var check in genData.RequiredChecks)
                    {
                        if (!check[hash])
                        {
                            valid = false;
                            break;
                        }
                    }
                    if (valid && setCheck[hash])
                    {
                        room = r;
                        return(true);
                    }
                }
            }

            room = null;
            return(false);
        }
Beispiel #2
0
        public static bool TryGetRoom(int width, int height, FloorGenData genData, TagCheck requiredTag, out PrefabRoom room)
        {
            if (_indexTable.ContainsKey(new Vector2Int(width, height)))
            {
                // there is a room of that size
                foreach (var r in _indexTable[new Vector2Int(width, height)])
                {
                    if (requiredTag[r.Key])
                    {
                        // we found the right tag
                        foreach (var opt in r.Value.AsArray().EnumerateRandom())
                        {
                            if (genData.PlacedRooms.Contains(opt))
                            {
                                continue;
                            }
                            bool valid = true;
                            foreach (var myTag in opt.Tags)
                            {
                                if (genData.ExcludedTags.ContainsKey(myTag))
                                {
                                    valid = false;
                                    break;
                                }
                            }
                            if (!valid)
                            {
                                continue;
                            }
                            foreach (var exTag in opt.ExcludeTags)
                            {
                                if (genData.ExistingTags.ContainsKey(exTag))
                                {
                                    valid = false;
                                    break;
                                }
                            }
                            if (valid)
                            {
                                room = opt;
                                return(true);
                            }
                        }
                    }
                }
            }



            room = null;
            return(false);
        }