UserFunction; SobGroup_SplitGroupReference - HWRM/KarosGraveyard Wiki

SobGroup_SplitGroupReference(<sSobGroupOut>, <sSobGroupToSplit>, <sReferenceSobGroup>, <iNumberToSplit>)

Description

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:

  1. they are in a squadron (i.e. a wing of fighters), or
  2. 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.

Example

Arguments

<sSobGroupOut>:
<sSobGroupToSplit>:
<sReferenceSobGroup>:
<iNumberToSplit>:

Declaration

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

Authors

Related Functions

Related Pages

UserFunctionReference

Comments

Page Status

Updated Formatting? Initial
Updated for HWRM? Initial