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

ompo = 0
n = 0
doSetFlag = false

function spawnOnNaija(me)
	ompo = createEntity("Ompo", "", entity_x(n)+10, entity_y(n)-16)
end

function spawnOnNode(me)
	debugLog("spawning on nodeee")
	ompo = createEntity("Ompo", "", node_x(me), node_y(me))
end

function init(me)
	n = getNaija()
	
	if isMapName("TRAININGCAVE") then
		if isFlag(FLAG_OMPO, 0) then
			doSetFlag = true
			spawnOnNode(me)
		elseif isFlag(FLAG_OMPO, 1) or isFlag(FLAG_OMPO, 3) then
			spawnOnNaija(me)
		end
	elseif isMapName("MAINAREA") then
		if isFlag(FLAG_OMPO, 1) or isFlag(FLAG_OMPO, 3) then
			spawnOnNaija(me)
		end
	elseif isMapName("SONGCAVE") or isMapName("NAIJACAVE") then
		if isFlag(FLAG_OMPO, 1) or isFlag(FLAG_OMPO, 3) then
			spawnOnNaija(me)
		end
	elseif isMapName("SONGCAVE02") then
		if isFlag(FLAG_OMPO, 2) then
			spawnOnNode(me)
		elseif isFlag(FLAG_OMPO, 3) then
			spawnOnNaija(me)
		end
	elseif isMapName("VEDHACAVE") then
		if isFlag(FLAG_OMPO, 1) or isFlag(FLAG_OMPO, 3) then
			spawnOnNaija(me)
		end
	elseif isMapName("ENERGYTEMPLE01") then
		if isFlag(FLAG_OMPO, 3) then
			spawnOnNaija(me)
		end
	end
end

function update(me, dt)
	if doSetFlag and node_isEntityIn(me, n) then
		if isFlag(FLAG_OMPO, 0) then
			setFlag(FLAG_OMPO, 1)
		end
	end
end
