function SetAlliances takes nothing returns nothing
local integer i = 0
local integer j
local player p1
local player p2
loop
set p1 = Player(i)
if GetPlayerSlotState(p1) == PLAYER_SLOT_STATE_PLAYING then
set j = 0
loop
set p2 = Player(j)
if j != i and GetPlayerSlotState(p2) == PLAYER_SLOT_STATE_PLAYING then
if udg_IsEvil[i-1] and udg_IsEvil[j-1] then // if both are evil
call SetPlayerAllianceStateBJ(p1,p2,bj_ALLIANCE_ALLIED)
call SetPlayerAllianceStateBJ(p2,p1,bj_ALLIANCE_ALLIED)
elseif not (udg_IsEvil[i-1] or udg_IsEvil[j-1]) then // if both are not evil
call SetPlayerAllianceStateBJ(p1,p2,bj_ALLIANCE_ALLIED)
call SetPlayerAllianceStateBJ(p2,p1,bj_ALLIANCE_ALLIED)
else // if they are in different teams
call SetPlayerAllianceStateBJ(p1,p2,bj_ALLIANCE_UNALLIED)
call SetPlayerAllianceStateBJ(p2,p1,bj_ALLIANCE_UNALLIED)
endif
endif
exitwhen j == 11
set j = j + 1
endloop
endif
exitwhen i == 11
set i = i + 1
endloop
set p1 = null
set p2 = null
endfunction