function Filter_AlwaysTrue takes nothing returns boolean
return true
endfunction
function DistanceBetweenPointsXY takes real x, real y, real targ_x, real targ_y returns real
local real dx = targ_x - x
local real dy = targ_y - y
return SquareRoot(dx * dx + dy * dy)
endfunction
function DamageArea takes unit attacker, real x, real y, real radius, real damage, real self, real friend, attacktype a_type, damagetype d_type returns nothing
local group ug = CreateGroup()
local unit u
local player player_owner = GetOwningPlayer(attacker)
local real damage_percent
local real dist
local real targ_x
local real targ_y
call GroupEnumUnitsInRange(ug, x, y, radius, Condition(function Filter_AlwaysTrue))
loop
set u = FirstOfGroup(ug)
exitwhen u == null
if (attacker == u) then
if (self > 0) then
// Reaction to Self
set targ_x = GetUnitX(u)
set targ_y = GetUnitY(u)
set dist = DistanceBetweenPointsXY(x,y,targ_x,targ_y)
if (dist < 1) then
set damage_percent = damage
else
set damage_percent = (dist / radius) * damage
endif
call UnitDamageTarget(attacker, u, damage_percent * self, true, true, a_type, d_type, WEAPON_TYPE_WHOKNOWS)
endif
elseif (IsUnitEnemy(u, player_owner)) then
// Reaction to Enemies
set targ_x = GetUnitX(u)
set targ_y = GetUnitY(u)
set dist = DistanceBetweenPointsXY(x,y,targ_x,targ_y)
if (dist < 1) then
set damage_percent = damage
else
set damage_percent = (dist / radius) * damage
endif
call UnitDamageTarget(attacker, u, damage_percent, true, true, a_type, d_type, WEAPON_TYPE_WHOKNOWS)
elseif (friend > 0) then
// Reaction to Friendlies
set targ_x = GetUnitX(u)
set targ_y = GetUnitY(u)
set dist = DistanceBetweenPointsXY(x,y,targ_x,targ_y)
if (dist < 1) then
set damage_percent = damage
else
set damage_percent = (dist / radius) * damage
endif
call UnitDamageTarget(attacker, u, damage_percent * friend, true, true, a_type, d_type, WEAPON_TYPE_WHOKNOWS)
endif
call GroupRemoveUnit(ug, u)
set u = null
endloop
set player_owner = null
call DestroyGroup(ug)
set ug = null
endfunction