local I=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local x=require((I:WaitForChild("\080\114\111\106\101\099\116")):WaitForChild("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101"))local u=x:GetResource("\069\120\116\101\114\110\097\108\085\116\105\108\046\078\101\120\117\115\073\110\115\116\097\110\099\101\046\078\101\120\117\115\079\098\106\101\099\116")local U=u:Extend()U:SetClassName("\068\117\110\103\101\111\110\065\108\108\111\099\097\116\105\111\110")function U.__new(I)I:InitializeSuper()I.AllocatedDungeons={}end function U.Allocate(u,I,x)local U=1 while true do local k=false for I=I-1,I+1,1 do for x=x-1,x+1,1 do if u.AllocatedDungeons[tostring(I)..("\095"..(tostring(x)..("\095"..tostring(U))))]then k=true break end end end if not k then local k=tostring(I)..("\095"..(tostring(x)..("\095"..tostring(U))))u.AllocatedDungeons[k]=true return U,k end U=U+1 end end function U.Deallocate(x,I)x.AllocatedDungeons[I]=nil end return U
--[[
TheNexusAvenger

Manages the allocation of dungeons since they overlap houses.
--]]

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ReplicatedStorageProject = require(ReplicatedStorage:WaitForChild("Project"):WaitForChild("ReplicatedStorage"))

local NexusObject = ReplicatedStorageProject:GetResource("ExternalUtil.NexusInstance.NexusObject")

local DungeonAllocation = NexusObject:Extend()
DungeonAllocation:SetClassName("DungeonAllocation")



--[[
Creates a bool grid.
--]]
function DungeonAllocation:__new()
    self:InitializeSuper()

    --Store the state.
    self.AllocatedDungeons = {}
end

--[[
Allocates a slot and returns the height as a
number and a string with the id.
--]]
function DungeonAllocation:Allocate(X,Y)
    local Depth = 1
    while true do
        --Determine if the slot has not been allocated to the current or selected slot.
        local SlotTaken = false
        for SubX = X - 1,X + 1 do
            for SubY = Y - 1,Y + 1 do
                if self.AllocatedDungeons[tostring(SubX).."_"..tostring(SubY).."_"..tostring(Depth)] then
                    SlotTaken = true
                    break
                end
            end
        end

        --Allocate the id and return the id and height if the slot is not allocated.
        if not SlotTaken then
            local Id = tostring(X).."_"..tostring(Y).."_"..tostring(Depth)
            self.AllocatedDungeons[Id] = true
            return Depth,Id
        end

        --Increase the depth and continue if it can't be allocated.
        Depth = Depth + 1
    end
end

--[[
Deallocates a slot.
--]]
function DungeonAllocation:Deallocate(Id)
    self.AllocatedDungeons[Id] = nil
end



return DungeonAllocation