//
// Extrafunctions
//
// This library provides functions that extend
// the editor functionality and/or make things
// more efficient.
//
//
globals
integer ExtraInt
real ExtraReal
real ExtraX
real ExtraY
unit ExtraUnit
endglobals
library ExtraFunctions
//System stuff that shouldn't be used outside
function UnitTypeIsInteger takes nothing returns boolean
return GetUnitTypeId(GetFilterUnit()) == ExtraInt
endfunction
function ClosestUnitLoop takes nothing returns nothing
local unit u = GetEnumUnit()
local real x = GetUnitX(u) - ExtraX
local real y = GetUnitY(u) - ExtraY
local real r = SquareRoot(x * x + y * y)
if r < ExtraReal then
set ExtraReal = r
set ExtraUnit = u
endif
set u = null
endfunction
//Actual functions
function Debug takes string s returns nothing
call DisplayTextToPlayer(GetLocalPlayer(),0,0,s)
endfunction
function GetClosestUnitOfGroup takes group g,real x,real y returns unit
set ExtraReal = 100000
set ExtraX = x
set ExtraY = y
call ForGroup(g, function ClosestUnitLoop)
return ExtraUnit
endfunction
function FindClosestUnitOfType takes integer UnitType,real x,real y returns unit
local group g = CreateGroup()
local unit u
set ExtraInt = UnitType
call GroupEnumUnitsInRange(g,0,0,100000,function UnitTypeIsInteger)
set u = GetClosestUnitOfGroup(g,x,y)
//Clearing up
call DestroyGroup(g)
set g = null
return u
endfunction
function IntPower takes integer number,integer power returns integer
local integer i = 1
local integer resultnumber = number
if power == 0 then
return 1
endif
loop
exitwhen i == power
set resultnumber = resultnumber*number
set i = i + 1
endloop
return resultnumber
endfunction
function AddUnitState takes unit u, unitstate us, real amount returns nothing
call SetUnitState(u,us,GetUnitState(u,us)+amount)
endfunction
endlibrary
function InitTrig_ExtraFunctions takes nothing returns nothing
endfunction