function SetForceAllianceStateBJ takes force sourceForce, force targetForce, integer allianceState returns nothing
local integer sourceIndex
local integer targetIndex
set sourceIndex = 0
loop
if (sourceForce==bj_FORCE_ALL_PLAYERS or IsPlayerInForce(Player(sourceIndex), sourceForce)) then
set targetIndex = 0
loop
if (targetForce==bj_FORCE_ALL_PLAYERS or IsPlayerInForce(Player(targetIndex), targetForce)) then
call SetPlayerAllianceStateBJ(Player(sourceIndex), Player(targetIndex), allianceState)
endif
set targetIndex = targetIndex + 1
exitwhen targetIndex == bj_MAX_PLAYER_SLOTS
endloop
endif
set sourceIndex = sourceIndex + 1
exitwhen sourceIndex == bj_MAX_PLAYER_SLOTS
endloop
endfunction
function SetPlayerAllianceStateBJ takes player sourcePlayer, player otherPlayer, integer allianceState returns nothing
// Prevent players from attempting to ally with themselves.
if (sourcePlayer == otherPlayer) then
return
endif
if allianceState == bj_ALLIANCE_UNALLIED then
call SetPlayerAllianceStateAllyBJ( sourcePlayer, otherPlayer, false )
call SetPlayerAllianceStateVisionBJ( sourcePlayer, otherPlayer, false )
call SetPlayerAllianceStateControlBJ( sourcePlayer, otherPlayer, false )
call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
elseif allianceState == bj_ALLIANCE_UNALLIED_VISION then
call SetPlayerAllianceStateAllyBJ( sourcePlayer, otherPlayer, false )
call SetPlayerAllianceStateVisionBJ( sourcePlayer, otherPlayer, true )
call SetPlayerAllianceStateControlBJ( sourcePlayer, otherPlayer, false )
call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
elseif allianceState == bj_ALLIANCE_ALLIED then
call SetPlayerAllianceStateAllyBJ( sourcePlayer, otherPlayer, true )
call SetPlayerAllianceStateVisionBJ( sourcePlayer, otherPlayer, false )
call SetPlayerAllianceStateControlBJ( sourcePlayer, otherPlayer, false )
call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
elseif allianceState == bj_ALLIANCE_ALLIED_VISION then
call SetPlayerAllianceStateAllyBJ( sourcePlayer, otherPlayer, true )
call SetPlayerAllianceStateVisionBJ( sourcePlayer, otherPlayer, true )
call SetPlayerAllianceStateControlBJ( sourcePlayer, otherPlayer, false )
call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
elseif allianceState == bj_ALLIANCE_ALLIED_UNITS then
call SetPlayerAllianceStateAllyBJ( sourcePlayer, otherPlayer, true )
call SetPlayerAllianceStateVisionBJ( sourcePlayer, otherPlayer, true )
call SetPlayerAllianceStateControlBJ( sourcePlayer, otherPlayer, true )
call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
elseif allianceState == bj_ALLIANCE_ALLIED_ADVUNITS then
call SetPlayerAllianceStateAllyBJ( sourcePlayer, otherPlayer, true )
call SetPlayerAllianceStateVisionBJ( sourcePlayer, otherPlayer, true )
call SetPlayerAllianceStateControlBJ( sourcePlayer, otherPlayer, true )
call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, true )
elseif allianceState == bj_ALLIANCE_NEUTRAL then
call SetPlayerAllianceStateAllyBJ( sourcePlayer, otherPlayer, false )
call SetPlayerAllianceStateVisionBJ( sourcePlayer, otherPlayer, false )
call SetPlayerAllianceStateControlBJ( sourcePlayer, otherPlayer, false )
call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
call SetPlayerAlliance( sourcePlayer, otherPlayer, ALLIANCE_PASSIVE, true )
elseif allianceState == bj_ALLIANCE_NEUTRAL_VISION then
call SetPlayerAllianceStateAllyBJ( sourcePlayer, otherPlayer, false )
call SetPlayerAllianceStateVisionBJ( sourcePlayer, otherPlayer, true )
call SetPlayerAllianceStateControlBJ( sourcePlayer, otherPlayer, false )
call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
call SetPlayerAlliance( sourcePlayer, otherPlayer, ALLIANCE_PASSIVE, true )
else
// Unrecognized alliance state - ignore the request.
endif
endfunction