dofile("scripts/entities/entityinclude.lua")

orb = 0

function init(me)
	if isFlag(FLAG_DEEPWHALE, 2) then
		orb = createEntity("EnergyOrb", "", node_x(me), node_y(me))
	end
	
	if isFlag(FLAG_DEEPWHALE, 3) then
		nd = getNode("OPENENERGYDOOR")
		orb = createEntity("EnergyOrb", "", node_x(nd), node_y(nd))
		entity_setState(orb, STATE_CHARGED, -1, 1)
	end
end

function update(me, dt)
	if orb ~= 0 then
		if isFlag(FLAG_DEEPWHALE, 2) then
			if entity_isState(orb, STATE_CHARGED) and node_isEntityIn(getNode("OPENENERGYDOOR"), orb) then
				setFlag(FLAG_DEEPWHALE, 3)
			end
		end
	end
end
