Warcraft III resources & community, 2003–2006 · archived

GroupToUnitpool

not rated
Submitted by KaTTaNaConversion0 downloads
Returns a unitpool containing all the unit-types existant in the group. All the unittypes will have equal weight.

Source

function GroupToUnitpool takes group whichGroup returns unitpool
    local unitpool result = CreateUnitPool()
    local unit u
    local group g = CreateGroup()
    local integer array id
    local integer n
    local integer num = 0
    local boolean add
    call GroupAddGroup(whichGroup, g)
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        set add = true
        set n = 0
        loop
            exitwhen id[n] <= 0
            if ( id[n] == GetUnitTypeId(u) ) then
                set add = false
                exitwhen true
            endif
            set n = n + 1
        endloop
        if ( add ) then
            set id[n] = GetUnitTypeId(u)
            set num = num + 1
        endif
        call GroupRemoveUnit(g,u)
    endloop
    call DestroyGroup(g)
    set g = null
    set n = 0
    loop
        exitwhen id[n] <= 0
        call UnitPoolAddUnitType(result, id[n], 1.00/num)
        set n = n + 1
    endloop
    return result
endfunction

Comments

0

No comments.