scope MinimapVisionHints initializer init
	import Cinematic
	import Players
	import Units

	native UnitAlive takes unit u returns boolean

	constant real CLOCK_PERIOD =    1. / 4.
	constant real RADIUS       =  350.
	constant real CHECK_RADIUS = 2500.

	fogmodifier array hints

	function update takes nothing returns nothing
		integer index = 0
		integer j

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

				j = 0
				loop
					exitwhen j >= Players.FIRST_BEAST
					if j != index then
						FogModifierStop(hints[index * (Players.FIRST_BEAST) + j])
						DestroyFogModifier(hints[index * (Players.FIRST_BEAST) + j])

						// display hint if (hint receiver is in range and both are alive) or (hint receiver is dead and target is alive)
						if (UnitAlive(Units.hero[index]) and UnitAlive(Units.hero[j]) and IsUnitInRange(Units.hero[index], Units.hero[j], CHECK_RADIUS)) or (not UnitAlive(Units.hero[index]) and UnitAlive(Units.hero[j])) then
							hints[index * Players.FIRST_BEAST + j] = CreateFogModifierRadius(Players.fromId[index], FOG_OF_WAR_VISIBLE, GetUnitX(Units.hero[j]), GetUnitY(Units.hero[j]), RADIUS, false, true)
							FogModifierStart(hints[index * Players.FIRST_BEAST + j])
						end
					end
					j++
				end

				index++
			end
		end
	end

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