UserFunction; SobGroup_SplitGroupReference - HWRM/KarosGraveyard GitHub Wiki
SobGroup_SplitGroupReference(<sSobGroupOut>, <sSobGroupToSplit>, <sReferenceSobGroup>, <iNumberToSplit>)
❌ This function should perhaps be considered deprecated; see SobGroup_Split
, which uses a new function introduced in HWRM, removing the chance for groups containing irregular amounts of ships entirely.
Splits the sobgroup <sSobGroupToSplit> into max(<iNumberToSplit>, SobGroup_Count(<sSobGroupToSplit>)) individual * sobgroups, beginning at the center of <sReferenceSobGroup>. Used in conjunction with SobGroup_SplitGroup() this virtually guarantees sobgroups consisting of individual ships/squadrons.
Returns the number of sobgroups created.
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 .2 meters) from the sobgroup's average position.
Try running SobGroup_SplitGroup() on the returned sobgroup if higher accuracy is desired.
<sSobGroupOut>:
<sSobGroupToSplit>:
<sReferenceSobGroup>:
<iNumberToSplit>:
function SobGroup_SplitGroupReference(SobGroupOut, SobGroupToSplit, ReferenceSobGroup, 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", ReferenceSobGroup, 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 <= .2) 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
- Apollyon470
Updated Formatting? Initial
Updated for HWRM? Initial