globals
constant integer CLOSE_RANGE_BONUS = 15
constant integer MEDIUM_RANGE_BONUS = 10
constant integer LONG_RANGE_BONUS = 5
//it will also be useful to have the ranges that are associated with
//the bonus values defined above
constant real CLOSE_RANGE = 50
constant real MEDIUM_RANGE = 75
constant real LONG_RANGE = 100
//we will also need the coordinates of the x/y that are used for the
//group enumeration so that we can reference them in the enum func.
real globX
real globY
endglobals
function ForGroupFunc takes nothing returns nothing
local unit picked=GetEnumUnit() //each enumerated unit will be passed through this function
local real x=GetUnitX(picked)
local real y=GetUnitY(picked)
local real range
//say we wanted to add strength to enumerated units, only if they are heroes
if(IsUnitType(picked, UNIT_TYPE_HERO)) then
//depending on the distance to the global coordinates the unit will
//recieve a different bonus
set range=SquareRoot((x-globX)*(x-globX) + (y-globY)*(y-globY))
if(range<=CLOSE_RANGE) then
call SetHeroStr(picked, GetHeroStr(picked)+CLOSE_RANGE_BONUS)
elseif(range<=MEDIUM_RANGE) then
call SetHeroStr(picked, GetHeroStr(picked)+MEDIUM_RANGE_BONUS)
else
//the unit is automatically included in LONG_RANGE because that is the range parameter
//of the group enumeration
call SetHeroStr(picked, GetHeroStr(picked)+LONG_RANGE_BONUS)
endif
endif
//remember that before the function ends the handle variable must be set to null
set picked=null
endfunction
function EnumerateUnits takes nothing returns nothing
local group g=CreateGroup()
local real x=0 //this is the x-coordinate of the "in-range" point
local real y=0 //this is the y-coordinate of the "in-range" point
local real r=100 //this is the range that enumerates are enumerated from point x, y
//instead of setting r to 100 we're going to use the constant values defined in globals
set r=LONG_RANGE //units in CLOSE_RANGE and MEDIUM_RANGE will also be enumerated
//setup the global x/y variables so they can be used in ForGroupFunc
set globX=x
set globY=y
call GroupEnumUnitsInRange(g, x, y, r, null) //the null is a filter function that can filter out units
//now that you have enumerated the units with the function, you can direct actions
//towards those units by using ForGroup, such as:
call ForGroup(g, function ForGroupFunc)
//the ForGroupFunc is defined above, and each enumerated unit is referenced as GetEnumUnit()
//because a group is a handle, it must be destroyed/nulled
call DestroyGroup(g)
set g=null
endfunction