local Time 	= Game.Time;
local Delay 	= 1; -- game seconds
local Ready	= Time();

local PeopleAmount = {};
local Cameras = {};
local PooAmount = {};


function Create()
	Ready = Time()
	Delay = 1
	this.BeginJob = false
	this.Cleaned = false
end

function getRandomEntityFromTable(tbl)
    local size = tableSize(tbl);
    if tbl ~= nil and size > 0 then
        local curCnt = 1;
        local rndEle = math.random(1, size);
        for ent, _ in pairs(tbl) do
            if curCnt == rndEle then return ent;
            else curCnt = curCnt + 1;
            end
        end
    else
        return nil;
    end
end


function tableSize(T)
    if T == nil then
        return 0;
    end

    local count = 0;
    for _ in pairs(T) do
        count = count + 1;
    end
    return count;
end

function SpawnObject(ObjectType, x, y)
    return Object.Spawn(tostring(ObjectType), x, y);
end

function CheckForPoopSCP()
	local scp = this.GetNearbyObjects("Prisoner", 6)
		for scps, dist in pairs(scp) do
				Object.NavigateTo(scps, this.Pos.x, this.Pos.y )
	end
end

function CheckForClean()
	local dee = this.GetNearbyObjects("Prisoner", 1)
		for dees, dist in pairs(dee) do
			Object.Delete()
	end
end

function Update()
	if Time() > Ready then
		PerformUpdate( Delay )
		Ready = Ready + Delay
	end
end

function PerformUpdate( elapsedTime )
 	CheckForPoopSCP()
	CheckForClean()
end

function roll(chance)
    local randomPercent = math.random(0, 50);
    if randomPercent <= chance then return true; end
    return false;
end
