//
// GroupOrder
// by Xonok
//
// This system provides the functionality to give orders to groups,
// through simple functions.
// This system requires GroupControl,
// in order to access udg_OwnedUnits[]
//
// GroupOrderTarget(group,order,target) -> nothing
// |
// Issues an order to all units in the group.
// The order can target any widget(unit,tree,etc).
//
// GroupOrderPoint(group,order,x,y) -> nothing
// |
// Issues an order to all units in the group.
// The provided coordinates are treated as absolute.
//
// GroupOrderOffset(group,order,x,y) -> nothing
// |
// Issues an order to all units in the group.
// The provided coordinates are treated as relative to the unit.
//
// GroupOrder(group,order) -> nothing
// |
// Issues an untargeted order to all units in the group
//
// Invalid orders don't do anything (courtesy of blizzard)
//
library GroupOrder initializer InitTri_GroupOrder requires GroupControl
globals
private integer ID
private integer ID2
private real x
private real y
private real x2
private real y2
private real x3
private real y3
private real RefX
private real RefY
private unit caster
private unit u
private integer order
private widget target
endglobals
//+ System functions. Not for using elsewhere
private function TargetGroupOrder takes nothing returns nothing
call IssueTargetOrderById(GetEnumUnit(),order,target)
endfunction
private function PointGroupOrder takes nothing returns nothing
set u = GetEnumUnit()
call IssuePointOrderById(u,order,x,y)
endfunction
private function OffsetGroupOrder takes nothing returns nothing
set u = GetEnumUnit()
call IssuePointOrderById(u,order,GetUnitX(u)+x,GetUnitY(u)+y)
endfunction
private function FormationGroupOrder takes nothing returns nothing
set u = GetEnumUnit()
set ID2 = GetUnitUserData(u)
call IssuePointOrderById(u,order,x+FormationX[ID2],y+FormationY[ID2])
endfunction
private function OrderGroup takes nothing returns nothing
call IssueImmediateOrderById(GetEnumUnit(),order)
endfunction
//-
//+ Public functions. Use however you wish
function GroupOrderTarget takes group g,integer order2,widget target2 returns nothing
set order = order2
set target = target2
call ForGroup(g,function TargetGroupOrder)
endfunction
function GroupOrderPoint takes group g,integer order2,real x1,real y1 returns nothing
set order = order2
set x = x1
set y = y1
call ForGroup(g,function PointGroupOrder)
endfunction
function GroupOrderOffset takes group g, integer order2,real x1,real y1 returns nothing
set order = order2
set x = x1
set y = y1
call ForGroup(g,function OffsetGroupOrder)
endfunction
function GroupOrderFormation takes group g,integer order2,real x1,real y1 returns nothing
set order = order2
set x = x1
set y = y1
call ForGroup(g,function FormationGroupOrder)
endfunction
function GroupOrder takes group g, integer order2 returns nothing
set order = order2
call ForGroup(g,function OrderGroup)
endfunction
//-
//+ System function. Must stay down here, as it references public functions.
private function Order takes nothing returns boolean
if GetUnitAbilityLevel(GetTriggerUnit(),udg_OrderONAbil) > 0 then
set caster = GetTriggerUnit()
set order = GetIssuedOrderId()
set ID = GetUnitUserData(caster)
if GetOrderTarget() != null then
set target = GetOrderTarget()
call GroupOrderTarget(udg_OwnedUnits[ID],order,target)
elseif GetOrderPointX() != null then
set x2 = GetUnitX(caster)
set y2 = GetUnitY(caster)
set x3 = GetOrderPointX()
set y3 = GetOrderPointY()
if GetUnitAbilityLevel(caster,udg_FormationONAbil) > 0 then
call GroupOrderFormation(udg_OwnedUnits[ID],order,x3,y3)
else
call GroupOrderOffset(udg_OwnedUnits[ID],order,x3-x2,y3-y2)
endif
else
call GroupOrder(udg_OwnedUnits[ID],order)
endif
endif
return false
endfunction
//++
function InitTri_GroupOrder takes nothing returns nothing
local integer i = 0
set gg_trg_GroupOrder = CreateTrigger( )
loop
exitwhen i > 15
call TriggerRegisterPlayerUnitEvent(gg_trg_GroupOrder,Player(i),EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER,null)
call TriggerRegisterPlayerUnitEvent(gg_trg_GroupOrder,Player(i),EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER,null)
call TriggerRegisterPlayerUnitEvent(gg_trg_GroupOrder,Player(i),EVENT_PLAYER_UNIT_ISSUED_ORDER,null)
set i = i + 1
endloop
call TriggerAddCondition( gg_trg_GroupOrder, function Order )
endfunction
endlibrary