#include "script/common.lua"

REQUIRED = 5
OPTIONAL = 0
NOTIFICATION_DELAY = 2

function init()
	done = false
	doneTimer = 0
end

function tick(dt)
	if done then
        SetBool("level.alarm", false)
        SetFloat("level.timelimit", -1)
		if doneTimer < NOTIFICATION_DELAY then
			doneTimer = doneTimer + dt
			if doneTimer >= NOTIFICATION_DELAY then
				SetString("hud.notification", "Âõé çòöòåò! Éèìöé î õåòéí ðãþìñé ì òöóôãåï¿íöéõ¼ èòðòí.")
			end
		end
		return
	end

	local hackedBodies = FindBodies("cleared", true)
	local requiredHacked = 0
	for i=1,#hackedBodies do
		if not HasTag(hackedBodies[i],"optional") then
			requiredHacked = requiredHacked + 1
		end
	end
	--Check if required number of panels are hacked
	local hacked = #hackedBodies
	if hacked > 0 then
		if requiredHacked >= REQUIRED then
			SetBool("level.alarm", false)
			SetBool("level.alarmdisabled", true)
            SetBool("level.delivering",false)            
	        SetBool("level.deliveryComplete", true)
			done = true
		end
	end
end

