- diff -u TieredGroupsFAv2/README.txt TieredGroupsFAv3/README.txt
- --- TieredGroupsFAv2/README.txt 2008-05-17 12:58:02.000000000 -0400
- +++ TieredGroupsFAv3/README.txt 2008-05-17 12:58:20.000000000 -0400
- -82,11 +82,11 @@
- [Ctrl + 6-0]
- - Makes selected units be the desired Battalion. Each type of unit
- -will go into a seperate Squad, from 1 to 4. If there are more than 4
- -types of units in the selection, it will loop around and start adding
- -them to Squad 1, 2 etc. (Units will be removed from their old squads.
- -Squads 1-4 in the desired Battalion will be cleared. Squad 5 will be
- -unaffected.)
- +will go into a seperate Squad, from 1 to 4. Units will be grouped by
- +tech level and unit ID. So lower tech units will be in the lower
- +squad numbers, and higher tech units will be in the higher squad
- +numbers. (Units will be removed from their old squads. Squads 1-4 in
- +the desired Battalion will be cleared. Squad 5 will be unaffected.)
- [Shift + Y]
- diff -u TieredGroupsFAv2/groupinterface.lua TieredGroupsFAv3/groupinterface.lua
- --- TieredGroupsFAv2/groupinterface.lua 2008-05-17 12:58:02.000000000 -0400
- +++ TieredGroupsFAv3/groupinterface.lua 2008-05-17 12:58:20.000000000 -0400
- -11,7 +11,11 @@
- local selectionSets = GPGSelection.selectionSets
- local Keymapper = import('/lua/keymap/keymapper.lua')
- -CurrBattalion = 0
- +-- The maximum number of non-special squads (keys 1-4)
- +MinRegSquadIdx = 1
- +MaxRegSquadIdx = 4
- +
- +CurrBattalion = -1
- CurrSquad = false
- local panel = false
- local mouseover = false
- -27,10 +31,20 @@
- RefreshDisplay()
- end
- +-- mod and div functions because SupCom doesn't recognize '%'
- +-- and the '/' operator doesn't truncate
- +function mod(a, b)
- + return a - math.floor(a/b)*b
- +end
- +
- +function div(a, b)
- + return math.floor(a/b)
- +end
- +
- function RefreshDisplay()
- local batt = "X"
- local squad = "X"
- - if CurrBattalion then
- + if CurrBattalion >= 0 then
- batt = CurrBattalion
- end
- if CurrSquad then
- -200,33 +214,75 @@
- if sel then
- -- If we have units, then sort them into types
- + -- Chop the alpha part of the ID so they sort nicely
- table.sort(sel,
- function(unit1, unit2)
- - bpid1 = unit1:GetBlueprint().BlueprintId
- - bpid2 = unit2:GetBlueprint().BlueprintId
- - return (bpid1 > bpid2) -- Greater than because it tends to put tanks first
- + id1 = unit1:GetBlueprint().BlueprintId
- + id2 = unit2:GetBlueprint().BlueprintId
- + sub1 = string.sub(id1, 4)
- + sub2 = string.sub(id2, 4)
- + if sub1 ~= sub2 then
- + return (sub1 < sub2)
- + else
- + return (id1 < id2)
- + end
- end)
- - -- Split them into squads
- - local index = 1
- - bpid1 = sel[1]:GetBlueprint().BlueprintId
- + -- Used to group squads by sequential type, not round-robin
- + local uniqueIdMap = {}
- + local uniqueIdList = {}
- + local uniqueTypes = 0
- +
- + -- Count the amount of unique types
- + for i, unit in sel do
- + id = unit:GetBlueprint().BlueprintId
- + if uniqueIdMap[id] ~= true then
- + uniqueIdMap[id] = true
- + table.insert(uniqueIdList, id)
- + uniqueTypes = uniqueTypes + 1
- + LOG("uniqueID: ", id)
- + end
- + end
- - for i, unit in sel do
- - bpid2 = unit:GetBlueprint().BlueprintId
- - if bpid1 ~= bpid2 then
- - bpid1 = bpid2
- - if index < 4 then
- - index = index + 1
- - else
- - index = 1
- - end
- - end
- + -- Split units into squads by type, ordered by type per squad
- + local extraTypes = mod(uniqueTypes, MaxRegSquadIdx)
- - table.insert(sortTables[index], unit)
- + -- Base case where there are less unique types than squads
- + local typesPerSquad = div(uniqueTypes, MaxRegSquadIdx)
- + if typesPerSquad <= 0 then
- + typesPerSquad = 1
- + extraTypes = 0
- + end
- +
- + local squadIdx = MinRegSquadIdx
- + local typesLeft = typesPerSquad
- + -- Spread out the remainder in the first few squads
- + if extraTypes > 0 then typesLeft = typesLeft + 1 end
- +
- + for i, unit in sel do
- + currId = unit:GetBlueprint().BlueprintId
- +
- + -- If we've filled this squad
- + if typesLeft <= 0 then
- + squadIdx = squadIdx + 1
- + extraTypes = extraTypes - 1
- + typesLeft = typesPerSquad
- + if extraTypes > 0 then typesLeft = typesLeft + 1 end
- + end
- +
- + table.insert(sortTables[squadIdx], unit)
- +
- + local nextId = currId
- + if sel[i+1] ~= nil then
- + nextId = sel[i+1]:GetBlueprint().BlueprintId
- + end
- + if currId ~= nextId then
- + typesLeft = typesLeft - 1
- + end
- end
- -- Add them to squads
- - for i=1, 4 do
- + for i = MinRegSquadIdx, MaxRegSquadIdx do
- SelectUnits(sortTables[i])
- MakeSquad(i)
- end
- Only in TieredGroupsFAv3: groupinterface.original.lua
- Common subdirectories: TieredGroupsFAv2/hook and TieredGroupsFAv3/hook
- diff -u TieredGroupsFAv2/mod_info.lua TieredGroupsFAv3/mod_info.lua
- --- TieredGroupsFAv2/mod_info.lua 2008-05-17 12:58:02.000000000 -0400
- +++ TieredGroupsFAv3/mod_info.lua 2008-05-17 12:58:20.000000000 -0400
- -1,8 +1,8 @@
- name = "Tiered Groups FA"
- uid = "0E01CC5A-9867-11DC-BAAA-949256D89593"
- -version = 2
- +version = 3
- copyright = ""
- author = "AdmiralZeech"
- url = "http://forums.gaspowered.com/viewtopic.php?p=319158#319158"
- Common subdirectories: TieredGroupsFAv2/textures and TieredGroupsFAv3/textures
- Common subdirectories: TieredGroupsFAv2/v0001 and TieredGroupsFAv3/v0001
- Common subdirectories: TieredGroupsFAv2/v0002 and TieredGroupsFAv3/v0002
- Only in TieredGroupsFAv3: v0003