Warcraft III resources & community, 2003–2006 · archived

ForcesHaveEqualContents

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

It uses bj_FORCE_ALL_PLAYERS as a placeholder, and it shouldn't pose any problems since it is reset at the end of the function. The only problem would be if the function is interrupted due to thread timeout.

See GroupsHaveEqualContents for a description on how the function works.

Source

function ForcesHaveEqualContents_Enum1 takes nothing returns nothing
    call ForceAddPlayer(bj_FORCE_ALL_PLAYERS, GetEnumPlayer())
    set bj_groupCountUnits = bj_groupCountUnits + 1
endfunction
function ForcesHaveEqualContents_Enum2 takes nothing returns nothing
    call ForceRemovePlayer(bj_FORCE_ALL_PLAYERS, GetEnumPlayer())
    set bj_forceCountPlayers = bj_forceCountPlayers + 1
endfunction
function ForcesHaveEqualContents_Enum3 takes nothing returns nothing
    set bj_isUnitGroupEmptyResult = false
endfunction

function ForcesHaveEqualContents takes force firstForce, force secondForce returns boolean
    local force f = bj_FORCE_ALL_PLAYERS
    set bj_FORCE_ALL_PLAYERS = CreateForce()
    set bj_groupCountUnits = 0
    set bj_forceCountPlayers = 0
    call ForForce(firstForce, function ForcesHaveEqualContents_Enum1)
    call ForForce(secondForce, function ForcesHaveEqualContents_Enum2)
    if bj_groupCountUnits != bj_forceCountPlayers then
        call DestroyForce(bj_FORCE_ALL_PLAYERS)
        set bj_FORCE_ALL_PLAYERS = f
        return false
    endif
    set bj_isUnitGroupEmptyResult = true
    call ForForce(bj_FORCE_ALL_PLAYERS, function ForcesHaveEqualContents_Enum3)
    call DestroyForce(bj_FORCE_ALL_PLAYERS)
    set bj_FORCE_ALL_PLAYERS = f
    return bj_isUnitGroupEmptyResult
endfunction

Comments

0

No comments.