Warcraft III resources & community, 2003–2006 · archived

GroupsHaveEqualContents

not rated
Submitted by PepparVariable Change0 downloads
Returns true if the two groups have the exact same units.

It parses though every unit in firstGroup, counts them, and adds them to bj_groupAddGroupDest (Enum1). Then it parses through every unit in secondGroup, counts them, and removes the corresponding units from bj_groupAddGroupDest (Enum2). If the two groups have a different amount of units, they are not equal. If bj_groupAddGroupDest contains any units (Enum3) after the two previous enums then the two groups are not equal.

Source

function GroupsHaveEqualContents_Enum1 takes nothing returns nothing
    call GroupAddUnit(bj_groupAddGroupDest, GetEnumUnit())
    set bj_groupCountUnits = bj_groupCountUnits + 1
endfunction
function GroupsHaveEqualContents_Enum2 takes nothing returns nothing
    call GroupRemoveUnit(bj_groupAddGroupDest, GetEnumUnit())
    set bj_forceCountPlayers = bj_forceCountPlayers + 1
endfunction
function GroupsHaveEqualContents_Enum3 takes nothing returns nothing
    set bj_isUnitGroupEmptyResult = false
endfunction

function GroupsHaveEqualContents takes group firstGroup, group secondGroup returns boolean
    set bj_groupAddGroupDest = CreateGroup()
    set bj_groupCountUnits = 0
    set bj_forceCountPlayers = 0
    call ForGroup(firstGroup, function GroupsHaveEqualContents_Enum1)
    call ForGroup(secondGroup, function GroupsHaveEqualContents_Enum2)
    if bj_groupCountUnits != bj_forceCountPlayers then
        call DestroyGroup(bj_groupAddGroupDest)
        return false
    endif
    set bj_isUnitGroupEmptyResult = true
    call ForGroup(bj_groupAddGroupDest, function GroupsHaveEqualContents_Enum3)
    call DestroyGroup(bj_groupAddGroupDest)
    return bj_isUnitGroupEmptyResult
endfunction

Comments

0

No comments.