scope BinocularVision initializer init
	import Cinematic
	import Players
	import Units

	native UnitAlive takes unit u returns boolean

	constant real CLOCK_PERIOD =   1. / 4.
	constant real OFFSET       = 500.
	constant real RADIUS       = 600.
	fogmodifier array lSight

	function act takes nothing returns nothing
		integer index = 0
		real face

		if not Cinematic.enabled then
			loop
				exitwhen index > Players.FIRST_BEAST

				FogModifierStop(lSight[index])
				DestroyFogModifier(lSight[index])

				if (GetUnitTypeId(Units.hero[index]) == Units.HUNTER_ID) and UnitAlive(Units.hero[index]) then
					face = GetUnitFacing(Units.hero[index]) * bj_DEGTORAD

					lSight[index] = CreateFogModifierRadius(Players.fromId[index], FOG_OF_WAR_VISIBLE, GetUnitX(Units.hero[index]) + OFFSET*Cos(face), GetUnitY(Units.hero[index]) + OFFSET*Sin(face), RADIUS, false, true)
					FogModifierStart(lSight[index])
				end

				index++
			end
		end
	end

	function init takes nothing returns nothing
		TimerStart(CreateTimer(), CLOCK_PERIOD, true, function act)
	end
endscope
