#include "script/common.lua"

REQUIRED = 2
OPTIONAL = 2
NOTIFICATION_DELAY = 2

function init()
	done = false
	doneTimer = 0
end

function tick(dt)
	if done then
		if doneTimer < NOTIFICATION_DELAY then
			doneTimer = doneTimer + dt
			if doneTimer >= NOTIFICATION_DELAY then
				SetString("hud.notification", "Òìçñãïìëãüì¿ òöîï¾ýéñã. Áéçìöé î õåòéðù öôãñõóòôöù.")
			end
		end
		return
	end

	local hackedBodies = FindBodies("hacked", 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 hacked >= REQUIRED+OPTIONAL and requiredHacked >= REQUIRED then
			SetBool("level.alarm", false)
			SetBool("level.alarmdisabled", true)
			done = true
		else
			SetBool("level.alarm", true)
		end
	end
end

