UserFunction; SobGroup_SplitGroup - HWRM/KarosGraveyard GitHub Wiki

SobGroup_SplitGroup(<sSobGroupOut>, <sSobGroupToSplit>, <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.

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:

  1. they are in a squadron (i.e. a wing of fighters), or
  2. they happen to be the same distance (within 1 meter) from the sobgroup's average position.
  3. 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

  • Apollyon470

Related Pages

UserFunctionReference

Comments

I don't understand the description.

--Mikali (2004-02-22 16:45:32)

Why not return the names of the created groups too? Lua supports multiple return values from a function.

--Thought (2004-02-25 16:54:35)

"Why not return the names of the created groups too?"<br />
I assume because he used it in "while loops" to control individual ships.<br />
<br />
"I don't understand the description."<br />
It splits a SobGroup into individual SobGroups. So 5 ships in SobGroupA become SobGroupB0 to SobGroupB4. Thus allowing you to do ..whatever.. to the ships individually, instead of as a group. The function also returns the number of the split SobGroups it created to whatever process called it.

--GreyGhost (2006-06-08 14:12:12)

Thanks for the info!

--Mikali (2006-07-03 01:26:17)

Page Status

Updated Formatting? Initial
Updated for HWRM? Initial

⚠️ **GitHub.com Fallback** ⚠️