Don't like ads? PRO users don't see any ads ;-)
Guest

coldboot

By: a guest on May 17th, 2008  |  syntax: None  |  size: 6.01 KB  |  hits: 41  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. diff -u TieredGroupsFAv2/README.txt TieredGroupsFAv3/README.txt
  2. --- TieredGroupsFAv2/README.txt 2008-05-17 12:58:02.000000000 -0400
  3. +++ TieredGroupsFAv3/README.txt 2008-05-17 12:58:20.000000000 -0400
  4.  -82,11 +82,11 @@
  5.  
  6.  [Ctrl + 6-0]
  7.  - Makes selected units be the desired Battalion.  Each type of unit
  8. -will go into a seperate Squad, from 1 to 4.  If there are more than 4
  9. -types of units in the selection, it will loop around and start adding
  10. -them to Squad 1, 2 etc.  (Units will be removed from their old squads.
  11. -Squads 1-4 in the desired Battalion will be cleared. Squad 5 will be
  12. -unaffected.)
  13. +will go into a seperate Squad, from 1 to 4.  Units will be grouped by
  14. +tech level and unit ID.  So lower tech units will be in the lower
  15. +squad numbers, and higher tech units will be in the higher squad
  16. +numbers.  (Units will be removed from their old squads. Squads 1-4 in
  17. +the desired Battalion will be cleared. Squad 5 will be unaffected.)
  18.  
  19.  
  20.  [Shift + Y]
  21. diff -u TieredGroupsFAv2/groupinterface.lua TieredGroupsFAv3/groupinterface.lua
  22. --- TieredGroupsFAv2/groupinterface.lua 2008-05-17 12:58:02.000000000 -0400
  23. +++ TieredGroupsFAv3/groupinterface.lua 2008-05-17 12:58:20.000000000 -0400
  24.  -11,7 +11,11 @@
  25.  local selectionSets = GPGSelection.selectionSets
  26.  local Keymapper = import('/lua/keymap/keymapper.lua')
  27.  
  28. -CurrBattalion = 0
  29. +-- The maximum number of non-special squads (keys 1-4)
  30. +MinRegSquadIdx = 1
  31. +MaxRegSquadIdx = 4
  32. +
  33. +CurrBattalion = -1
  34.  CurrSquad = false
  35.  local panel = false
  36.  local mouseover = false
  37.  -27,10 +31,20 @@
  38.         RefreshDisplay()
  39.  end
  40.  
  41. +-- mod and div functions because SupCom doesn't recognize '%'
  42. +-- and the '/' operator doesn't truncate
  43. +function mod(a, b)
  44. +  return a - math.floor(a/b)*b
  45. +end
  46. +
  47. +function div(a, b)
  48. +  return math.floor(a/b)
  49. +end
  50. +
  51.  function RefreshDisplay()
  52.         local batt = "X"
  53.         local squad = "X"
  54. -       if CurrBattalion then
  55. +       if CurrBattalion >= 0 then
  56.                 batt = CurrBattalion
  57.         end
  58.         if CurrSquad then
  59.  -200,33 +214,75 @@
  60.  
  61.     if sel then
  62.        -- If we have units, then sort them into types
  63. +      -- Chop the alpha part of the ID so they sort nicely
  64.        table.sort(sel,
  65.                   function(unit1, unit2)
  66. -                    bpid1 = unit1:GetBlueprint().BlueprintId
  67. -                    bpid2 = unit2:GetBlueprint().BlueprintId
  68. -                    return (bpid1 > bpid2) -- Greater than because it tends to put tanks first
  69. +                    id1 = unit1:GetBlueprint().BlueprintId
  70. +                    id2 = unit2:GetBlueprint().BlueprintId
  71. +                    sub1 = string.sub(id1, 4)
  72. +                    sub2 = string.sub(id2, 4)
  73. +                    if sub1 ~= sub2 then
  74. +                        return (sub1 < sub2)
  75. +                    else
  76. +                        return (id1 < id2)
  77. +                    end
  78.                   end)
  79.  
  80. -      -- Split them into squads
  81. -      local index = 1
  82. -      bpid1 = sel[1]:GetBlueprint().BlueprintId
  83. +      -- Used to group squads by sequential type, not round-robin
  84. +      local uniqueIdMap = {}
  85. +      local uniqueIdList = {}
  86. +      local uniqueTypes = 0
  87. +
  88. +      -- Count the amount of unique types
  89. +      for i, unit in sel do
  90. +          id = unit:GetBlueprint().BlueprintId
  91. +          if uniqueIdMap[id] ~= true then
  92. +              uniqueIdMap[id] = true
  93. +              table.insert(uniqueIdList, id)
  94. +              uniqueTypes = uniqueTypes + 1
  95. +              LOG("uniqueID: ", id)
  96. +          end
  97. +      end
  98.  
  99. -      for i, unit in sel do        
  100. -         bpid2 = unit:GetBlueprint().BlueprintId
  101. -         if bpid1 ~= bpid2 then
  102. -            bpid1 = bpid2
  103. -            if index < 4 then
  104. -               index = index + 1
  105. -            else
  106. -               index = 1
  107. -            end
  108. -         end    
  109. +      -- Split units into squads by type, ordered by type per squad
  110. +      local extraTypes = mod(uniqueTypes, MaxRegSquadIdx)
  111.  
  112. -         table.insert(sortTables[index], unit)
  113. +      -- Base case where there are less unique types than squads
  114. +      local typesPerSquad = div(uniqueTypes, MaxRegSquadIdx)
  115. +      if typesPerSquad <= 0 then
  116. +          typesPerSquad = 1
  117. +          extraTypes = 0
  118. +      end
  119. +
  120. +      local squadIdx = MinRegSquadIdx
  121. +      local typesLeft = typesPerSquad
  122. +      -- Spread out the remainder in the first few squads
  123. +      if extraTypes > 0 then typesLeft = typesLeft + 1 end
  124. +
  125. +      for i, unit in sel do
  126. +         currId = unit:GetBlueprint().BlueprintId
  127. +
  128. +         -- If we've filled this squad
  129. +         if typesLeft <= 0 then
  130. +             squadIdx = squadIdx + 1
  131. +             extraTypes = extraTypes - 1
  132. +             typesLeft = typesPerSquad
  133. +             if extraTypes > 0 then typesLeft = typesLeft + 1 end
  134. +         end
  135. +
  136. +         table.insert(sortTables[squadIdx], unit)
  137. +
  138. +         local nextId = currId
  139. +         if sel[i+1] ~= nil then
  140. +             nextId = sel[i+1]:GetBlueprint().BlueprintId
  141. +         end
  142. +         if currId ~= nextId then
  143. +             typesLeft = typesLeft - 1
  144. +         end
  145.        end
  146.        
  147.        -- Add them to squads
  148. -      for i=1, 4 do
  149. +      for i = MinRegSquadIdx, MaxRegSquadIdx do
  150.           SelectUnits(sortTables[i])
  151.           MakeSquad(i)
  152.        end
  153. Only in TieredGroupsFAv3: groupinterface.original.lua
  154. Common subdirectories: TieredGroupsFAv2/hook and TieredGroupsFAv3/hook
  155. diff -u TieredGroupsFAv2/mod_info.lua TieredGroupsFAv3/mod_info.lua
  156. --- TieredGroupsFAv2/mod_info.lua       2008-05-17 12:58:02.000000000 -0400
  157. +++ TieredGroupsFAv3/mod_info.lua       2008-05-17 12:58:20.000000000 -0400
  158.  -1,8 +1,8 @@
  159.  name = "Tiered Groups FA"
  160.  uid = "0E01CC5A-9867-11DC-BAAA-949256D89593"
  161. -version = 2
  162. +version = 3
  163.  copyright = ""
  164.  author = "AdmiralZeech"
  165.  url = "http://forums.gaspowered.com/viewtopic.php?p=319158#319158"
  166. Common subdirectories: TieredGroupsFAv2/textures and TieredGroupsFAv3/textures
  167. Common subdirectories: TieredGroupsFAv2/v0001 and TieredGroupsFAv3/v0001
  168. Common subdirectories: TieredGroupsFAv2/v0002 and TieredGroupsFAv3/v0002
  169. Only in TieredGroupsFAv3: v0003