SobGroup_SplitGroup(<sSobGroupOut>, <sSobGroupToSplit>, <iNumberToSplit>)
Description
Splits <sSobGroupToSplit> into max(<iNumberToSplit>, SobGroup_Count(<sSobGroupToSplit>)) individual sobgroups.
Returns the number of sobgroups created, which can then be accessed via "sSobGroupOut"..0, "sSobGroupOut"..1, ... "sSobGroupOut"..
ReturnedValue
Sobgroups are numbered in order of increasing distance from the center of the group, i.e. Sobgroup 0 is the closest to the center, etc.
Example
SobGroup_SplitGroup("AttackerSob", "allEnemySob", SobGroup_Count("allEnemySob"))
Arguments
<sSobGroupOut>:
<sSobGroupToSplit>:
<iNumberToSplit>:
Notes
Individual sobgroups are accessed by
"SobGroupOut"..<iIndex>, where <iIndex> is the index number of the sobgroup, starting with 0.
Will return multiple ships in a single sobgroup if:
- they are in a squadron (i.e. a wing of fighters), or
- they happen to be the same distance (within 1 meter) from the sobgroup's average position.
- there are only two ships in sSobGroupToSplit
Try rerunning
SobGroup_SplitGroup() on the returned sobgroup if higher accuracy is desired.
Declaration
function SobGroup_SplitGroup(SobGroupOut, SobGroupToSplit, NumberToSplit)
-- function created by Apollyon470
local index = 0
local distance = 0
local bool = 0
local SobNum = 0
SobGroup_Create("TempSobGroup")
SobGroup_Clear ("TempSobGroup")
SobGroup_Create("TempSobGroup1")
SobGroup_Clear ("TempSobGroup1")
SobGroup_SobGroupAdd ("TempSobGroup", SobGroupToSplit)
if ( SobGroup_Empty (SobGroupToSplit) == 1 ) then
return 0
end
if ( NumberToSplit > SobGroup_Count(SobGroupToSplit) ) then
NumberToSplit = SobGroup_Count(SobGroupToSplit)
end
while (index < NumberToSplit ) do
bool = 0
-- in the interests of resource saving, we start with a search band of 625
interval = 625
while (bool == 0) do
distance = distance + interval
-- something went wrong. Please tell me, or have a go at fixing it yourself.
if (interval > 3000000) then
bool =1
return SobNum
end
SobGroup_FillProximitySobGroup ("TempSobGroup1", "TempSobGroup", SobGroupToSplit, distance)
if (SobGroup_Empty("TempSobGroup1") == 1)then
-- get the next interval
else
if (SobGroup_Count("TempSobGroup1") > 1) then
-- too many ships, reduce interval
if (interval == 1) then
-- Screw it! chunk 'em all in the same sobgroup
SobGroup_Create(SobGroupOut .. tostring(SobNum))
SobGroup_Clear (SobGroupOut .. tostring(SobNum))
SobGroup_SobGroupAdd (SobGroupOut .. tostring(SobNum), "TempSobGroup1")
SobGroup_Create("tempsob")
SobGroup_FillSubstract("tempsob", "TempSobGroup", SobGroupOut .. tostring(SobNum))
SobGroup_Clear ("TempSobGroup")
SobGroup_SobGroupAdd ("TempSobGroup", "tempsob")
bool = 1
else
distance = distance - interval
interval = interval / 5
end
else
-- we got one! add it to the list!
SobGroup_Create(SobGroupOut .. tostring(SobNum))
SobGroup_Clear (SobGroupOut .. tostring(SobNum))
SobGroup_SobGroupAdd (SobGroupOut .. tostring(SobNum), "TempSobGroup1")
SobGroup_Create("tempsob")
SobGroup_FillSubstract("tempsob", "TempSobGroup", SobGroupOut .. tostring(SobNum))
SobGroup_Clear ("TempSobGroup")
SobGroup_SobGroupAdd ("TempSobGroup", "tempsob")
bool = 1
end
end
end
index = index + SobGroup_Count(SobGroupOut .. tostring(SobNum))
SobNum = SobNum + 1
end
return SobNum
end
Authors
Related Pages:
There are 4 comments on this page. [Display comments]