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

unit_shapes4.lua

By: a guest on Mar 25th, 2012  |  syntax: None  |  size: 20.77 KB  |  hits: 38  |  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. function widget:GetInfo()
  2.    return {
  3.       name      = "UnitShapes4",
  4.       desc      = "0.5.8.zk.02 Draws blended shapes around units and buildings",
  5.       author    = "Lelousius and aegis, modded Licho, CarRepairer, Antero",
  6.       date      = "30.07.2010",
  7.       license   = "GNU GPL, v2 or later",
  8.       layer     = 2,
  9.       enabled   = true,
  10.           detailsDefault = 1
  11.    }
  12. end
  13.  
  14. --------------------------------------------------------------------------------
  15. --------------------------------------------------------------------------------
  16.  
  17. local function SetupCommandColors(state)
  18.   local alpha = state and 1 or 0
  19.   local f = io.open('cmdcolors.tmp', 'w+')
  20.   if (f) then
  21.     f:write('unitBox  0 1 0 ' .. alpha)
  22.     f:close()
  23.     Spring.SendCommands({'cmdcolors cmdcolors.tmp'})
  24.   end
  25.   os.remove('cmdcolors.tmp')
  26. end
  27.  
  28. --------------------------------------------------------------------------------
  29. --------------------------------------------------------------------------------
  30. local math_acos                         = math.acos
  31. local math_pi                           = math.pi
  32. local math_cos                          = math.cos
  33. local math_sin                          = math.sin
  34. local math_abs                          = math.abs
  35. local rad_con                           = 180 / math_pi
  36.  
  37. local GL_ONE_MINUS_SRC_ALPHA = GL.ONE_MINUS_SRC_ALPHA
  38. local GL_ONE_MINUS_DST_ALPHA = GL.ONE_MINUS_DST_ALPHA
  39. local GL_SRC_ALPHA = GL.SRC_ALPHA
  40. local GL_DST_ALPHA = GL.DST_ALPHA
  41. local GL_DST_COLOR = GL.DST_COLOR
  42. local GL_SRC_COLOR = GL.SRC_COLOR
  43. local GL_ZERO = GL.ZERO
  44. local GL_ONE = GL.ONE
  45.  
  46. local GL_QUADS = GL.QUADS
  47. local GL_QUAD_STRIP = GL.QUAD_STRIP
  48. local GL_TRIANGLE_FAN = GL.TRIANGLE_FAN
  49. local GL_TRIANGLE_STRIP = GL.TRIANGLE_STRIP
  50. local GL_LINE_LOOP = GL.LINE_LOOP
  51. local GL_TRIANGLES = GL.TRIANGLES
  52. local GL_POLYGON = GL.POLYGON
  53.  
  54. local GL_COLOR_BUFFER_BIT = GL.COLOR_BUFFER_BIT
  55. local glPushAttrib = gl.PushAttrib
  56. local glPopAttrib = gl.PopAttrib
  57.  
  58. local gl_DepthTest =                    gl.DepthTest
  59. local gl_BlendFunc =                    gl.BlendFunc
  60. local gl_ColorMask =                    gl.ColorMask
  61. local gl_DrawList =                             gl.CallList
  62.  
  63. local spGetUnitHeading       = Spring.GetUnitHeading
  64. local spGetUnitDirection         = Spring.GetUnitDirection
  65. local spGetHeadingFromVector = Spring.GetHeadingFromVector
  66. local spIsUnitIcon           = Spring.IsUnitIcon
  67.  
  68. local UnitDs                             = UnitDefs
  69.  
  70. -- Automatically generated local definitions
  71.  
  72. local glBeginEnd             = gl.BeginEnd
  73. local glColor                = gl.Color
  74. local glCreateList           = gl.CreateList
  75. local glDeleteList           = gl.DeleteList
  76. local glDepthTest            = gl.DepthTest
  77. local glDrawListAtUnit       = gl.DrawListAtUnit
  78. local glLineWidth            = gl.LineWidth
  79. local glPolygonOffset        = gl.PolygonOffset
  80. local glVertex               = gl.Vertex
  81. local spDiffTimers           = Spring.DiffTimers
  82. local spGetVisibleUnits          = Spring.GetVisibleUnits
  83. local spGetGroundNormal      = Spring.GetGroundNormal
  84. local spGetSelectedUnits     = Spring.GetSelectedUnits
  85. local spGetTeamColor         = Spring.GetTeamColor
  86. local spGetTimer             = Spring.GetTimer
  87. local spGetUnitBasePosition  = Spring.GetUnitBasePosition
  88. local spGetUnitDefDimensions = Spring.GetUnitDefDimensions
  89. local spGetUnitDefID         = Spring.GetUnitDefID
  90. local spGetUnitRadius        = Spring.GetUnitRadius
  91. local spGetUnitTeam          = Spring.GetUnitTeam
  92. local spGetUnitViewPosition  = Spring.GetUnitViewPosition
  93. local spIsUnitSelected       = Spring.IsUnitSelected
  94. local spIsUnitVisible        = Spring.IsUnitVisible
  95. local spSendCommands         = Spring.SendCommands
  96.  
  97. local spGetCameraPosition        = Spring.GetCameraPosition
  98. local spGetGameFrame             = Spring.GetGameFrame
  99. local spTraceScreenRay           = Spring.TraceScreenRay
  100. local spGetMouseState            = Spring.GetMouseState
  101.  
  102. --------------------------------------------------------------------------------
  103. --------------------------------------------------------------------------------
  104.  
  105. local clearquad
  106. local shapes = {}
  107.  
  108. local myTeamID = Spring.GetLocalTeamID()
  109.  
  110. local circleDivs = 32 -- how precise circle? octagon by default
  111. local innersize = 0.9 -- circle scale compared to unit radius
  112. local selectinner = 1.5
  113. local outersize = 1.9 -- outer fade size compared to circle scale (1 = no outer fade)
  114. local scalefaktor = 2.8
  115. local rectangleFactor = 3.5
  116. local CAlpha = 0.5
  117.  
  118. local colorout = {   1,   1,   1,   0 } -- outer color
  119. local colorin  = {   1,   1,   1,   1 } -- inner color
  120.  
  121. local teamColors = {}
  122. local unitConf = {}
  123. ------------------------------------------------------------------------------------
  124. ------------------------------------------------------------------------------------
  125.  
  126. local visibleAllySelUnits = {}
  127.  
  128. ------------------------------------------------------------------------------------
  129. ------------------------------------------------------------------------------------
  130. options_path = 'Settings/Interface'
  131. options = {
  132.         showally = {
  133.                 name = 'Show Ally Selections',
  134.                 type = 'bool',
  135.                 value = false,
  136.                 OnChange = function(self)
  137.                         visibleAllySelUnits = {}
  138.                 end,
  139.         },
  140. }
  141.  
  142. ------------------------------------------------------------------------------------
  143. ------------------------------------------------------------------------------------
  144.  
  145. local lastCamX, lastCamY, lastCamZ
  146. local lastGameFrame = 0
  147.  
  148. local lastVisibleUnits, lastVisibleSelected, lastvisibleAllySelUnits, lastvisibleCloaked
  149. local forceUpdate = false
  150.  
  151. local function HasVisibilityChanged()
  152.         local camX, camY, camZ = spGetCameraPosition()
  153.         local gameFrame = spGetGameFrame()
  154.         if (camX ~= lastCamX) or (camY ~= lastCamY) or (camZ ~= lastCamZ) or
  155.                 ((gameFrame - lastGameFrame) >= 15) or (#lastVisibleSelected > 0) or
  156.                 (#spGetSelectedUnits() > 0) or (#lastVisibleCloaked > 0) then
  157.                
  158.                 lastGameFrame = gameFrame
  159.                 lastCamX, lastCamY, lastCamZ = camX, camY, camZ
  160.                 return true
  161.         end
  162.         return false
  163. end
  164.  
  165. local function GetVisibleUnits()
  166.         if (HasVisibilityChanged()) then
  167.                
  168.                 local units = spGetVisibleUnits(-1, 30, true)
  169.                 --local visibleUnits = {}
  170.                 local visibleAllySelUnits = {}
  171.                 local visibleSelected = {}
  172.                 local visibleCloaked = {}
  173.                
  174.                 for i=1, #units do
  175.                         local unitID = units[i]
  176.                         if (spIsUnitSelected(unitID)) then
  177.                                 visibleSelected[#visibleSelected+1] = unitID
  178.                         --else
  179.                                 --visibleUnits[#visibleUnits+1] = unitID
  180.                         elseif options.showally.value and WG.allySelUnits[unitID] then
  181.                                 visibleAllySelUnits[#visibleAllySelUnits+1] = unitID
  182.                         else
  183.                                 if (Spring.GetUnitIsCloaked(unitID)) then
  184.                                         visibleCloaked[#visibleCloaked+1] = unitID
  185.                                 end
  186.                         end
  187.                 end
  188.                
  189.                 --lastVisibleUnits = visibleUnits
  190.                 lastvisibleAllySelUnits = visibleAllySelUnits
  191.                 lastVisibleSelected = visibleSelected
  192.                 lastVisibleCloaked = visibleCloaked
  193.                 --return visibleUnits, visibleSelected
  194.                 return visibleAllySelUnits, visibleSelected, visibleCloaked
  195.         else
  196.                 --return lastVisibleUnits, lastVisibleSelected
  197.                 return lastvisibleAllySelUnits, lastVisibleSelected, lastVisibleCloaked
  198.         end
  199. end
  200.  
  201.  
  202. local function GetTeamColorSet(teamID)
  203.   local colors = teamColors[teamID]
  204.   if (colors) then
  205.     return colors
  206.   end
  207.   local r,g,b = spGetTeamColor(teamID)
  208.  
  209.   colors = { r, g, b, 0 }
  210.         -- Alpha = 0 as it is drawn with DST_ALPHA and should Clear it afterwards
  211.  
  212.   teamColors[teamID] = colors
  213.   return colors
  214. end
  215.  
  216.  
  217. --------------------------------------------------------------------------------
  218. --------------------------------------------------------------------------------
  219.  
  220. -- Creating polygons:
  221. local function CreateDisplayLists(callback)
  222.         local displayLists = {}
  223.        
  224.         local zeroColor = {0, 0, 0, 0}
  225.         local CAlphaColor = {0, 0, 0, CAlpha}
  226.        
  227.         displayLists.select = callback.fading(colorin, colorout, outersize, selectinner)
  228.         displayLists.invertedSelect = callback.fading(colorout, colorin, outersize, selectinner)
  229.         displayLists.inner = callback.solid(zeroColor, innersize)
  230.         displayLists.large = callback.solid(nil, selectinner)
  231.         displayLists.kill = callback.solid(nil, outersize)
  232.         displayLists.shape = callback.fading(zeroColor, CAlphaColor, innersize, selectinner)
  233.        
  234.         return displayLists
  235. end
  236.  
  237. local function CreateCircleLists()
  238.         local callback = {}
  239.        
  240.         function callback.fading(colorin, colorout, innersize, outersize)
  241.                 return glCreateList(function()
  242.                         glBeginEnd(GL.QUAD_STRIP, function()
  243.                                 local radstep = (2.0 * math_pi) / circleDivs
  244.                                 for i = 0, circleDivs do
  245.                                         local a1 = (i * radstep)
  246.                                         if (colorin) then
  247.                                                 glColor(colorin)
  248.                                         end
  249.                                         glVertex(math_sin(a1)*innersize, 0, math_cos(a1)*innersize)
  250.                                         if (colorout) then
  251.                                                 glColor(colorout)
  252.                                         end
  253.                                         glVertex(math_sin(a1)*outersize, 0, math_cos(a1)*outersize)
  254.                                 end
  255.                         end)
  256.                 end)
  257.         end
  258.        
  259.         function callback.solid(color, size)
  260.                 return glCreateList(function()
  261.                         glBeginEnd(GL.TRIANGLE_FAN, function()
  262.                                 local radstep = (2.0 * math_pi) / circleDivs
  263.                                 if (color) then
  264.                                         glColor(color)
  265.                                 end
  266.                                 glVertex(0, 0, 0)
  267.                                 for i = 0, circleDivs do
  268.                                         local a1 = (i * radstep)
  269.                                         glVertex(math_sin(a1)*size, 0, math_cos(a1)*size)
  270.                                 end
  271.                         end)
  272.                 end)
  273.         end
  274.        
  275.         shapes.circle = CreateDisplayLists(callback)
  276. end
  277.  
  278. local function CreatePolygonCallback(points, immediate)
  279.         immediate = immediate or GL_POLYGON
  280.         local callback = {}
  281.        
  282.         function callback.fading(colorin, colorout, innersize, outersize)
  283.                 local diff = outersize - innersize
  284.                 local steps = {}
  285.                
  286.                 for i=1, #points do
  287.                         local p = points[i]
  288.                         local x, z = p[1]*outersize, p[2]*outersize
  289.                         local xs, zs = (math_abs(x)/x and x or 1), (math_abs(z)/z and z or 1)
  290.                         steps[i] = {x, z, xs, zs}
  291.                 end
  292.                
  293.                 return glCreateList(function()
  294.                         glBeginEnd(GL_TRIANGLE_STRIP, function()
  295.                                 for i=1, #steps do
  296.                                         local step = steps[i] or steps[i-#steps]
  297.                                         local nexts = steps[i+1] or steps[i-#steps+1]
  298.                                        
  299.                                         glColor(colorout)
  300.                                         glVertex(step[1], 0, step[2])
  301.                                        
  302.                                         glColor(colorin)
  303.                                         glVertex(step[1] - diff*step[3], 0, step[2] - diff*step[4])
  304.                                        
  305.                                         glColor(colorout)
  306.                                         glVertex(step[1] + (nexts[1]-step[1]), 0, step[2] + (nexts[2]-step[2]))
  307.                                        
  308.                                         glColor(colorin)
  309.                                         glVertex(nexts[1] - diff*nexts[3], 0, nexts[2] - diff*nexts[4])
  310.                                 end
  311.                         end)
  312.                 end)
  313.         end
  314.        
  315.         function callback.solid(color, size)
  316.                 return glCreateList(function()
  317.                         glBeginEnd(immediate, function()
  318.                                 if (color) then
  319.                                         glColor(color)
  320.                                 end
  321.                                 for i=1, #points do
  322.                                         local p = points[i]
  323.                                         glVertex(size*p[1], 0, size*p[2])
  324.                                 end
  325.                         end)
  326.                 end)
  327.         end
  328.        
  329.         return callback
  330. end
  331.  
  332. local function CreateSquareLists()
  333.         local points = {
  334.                         {-1, 1},
  335.                         {1, 1},
  336.                         {1, -1},
  337.                         {-1, -1}
  338.                 }
  339.  
  340.         local callback = CreatePolygonCallback(points, GL_QUADS)
  341.         shapes.square = CreateDisplayLists(callback)
  342. end
  343.  
  344. local function CreateTriangleLists()
  345.         local points = {
  346.                 {0, -1},
  347.                 {1, 1},
  348.                 {-1, 1}
  349.         }
  350.        
  351.         local callback = CreatePolygonCallback(points, GL_TRIANGLES)
  352.         shapes.triangle = CreateDisplayLists(callback)
  353. end
  354.  
  355. local function DestroyShape(shape)
  356.         glDeleteList(shape.select)
  357.         glDeleteList(shape.invertedSelect)
  358.         glDeleteList(shape.inner)
  359.         glDeleteList(shape.large)
  360.         glDeleteList(shape.kill)
  361.         glDeleteList(shape.shape)
  362. end
  363.  
  364. function widget:Initialize()
  365.         if not WG.allySelUnits then
  366.                 WG.allySelUnits = {}
  367.         end
  368.        
  369.         CreateCircleLists()
  370.         CreateSquareLists()
  371.         CreateTriangleLists()
  372.        
  373.         for udid, unitDef in pairs(UnitDs) do
  374.                 local xsize, zsize = unitDef.xsize, unitDef.zsize
  375.                 local scale = scalefaktor*( xsize^2 + zsize^2 )^0.5
  376.                 local shape, xscale, zscale
  377.                
  378.                
  379.                 if (unitDef.isBuilding or unitDef.isFactory or unitDef.speed==0) then
  380.                         shape = shapes.square
  381.                         xscale, zscale = rectangleFactor * xsize, rectangleFactor * zsize
  382.                 elseif (unitDef.canFly) then
  383.                         shape = shapes.triangle
  384.                         xscale, zscale = scale, scale
  385.                 else
  386.                         shape = shapes.circle
  387.                         xscale, zscale = scale, scale
  388.                 end
  389.  
  390.                 unitConf[udid] = {shape=shape, xscale=xscale, zscale=zscale}
  391.         end
  392.  
  393.         clearquad = glCreateList(function()
  394.                 local size = 1000
  395.                 glBeginEnd(GL.QUADS, function()
  396.                         glVertex( -size,0,                      -size)
  397.                         glVertex( Game.mapSizeX+size,0, -size)
  398.                         glVertex( Game.mapSizeX+size,0, Game.mapSizeZ+size)
  399.                         glVertex( -size,0,                              Game.mapSizeZ+size)
  400.                 end)
  401.         end)
  402.         SetupCommandColors(false)
  403. end
  404.  
  405. function widget:Shutdown()
  406.         SetupCommandColors(true)
  407.        
  408.         glDeleteList(clearquad)
  409.        
  410.         for _, shape in pairs(shapes) do
  411.                 DestroyShape(shape)
  412.         end
  413. end
  414.  
  415.  
  416. --------------------------------------------------------------------------------
  417. --------------------------------------------------------------------------------
  418. local visibleUnits, visibleSelected, visibleCloaked = {}, {}, {}
  419. local degrot = {}
  420. function widget:Update()
  421.         -- [[
  422.         local mx, my = spGetMouseState()
  423.         local ct, id = spTraceScreenRay(mx, my)
  424.         if (ct == "unit") then
  425.                 hoveredUnit = id
  426.         else
  427.                 hoveredUnit = nil
  428.         end
  429.         --]]
  430.         --visibleUnits, visibleSelected = GetVisibleUnits()
  431.         visibleAllySelUnits, visibleSelected, visibleCloaked = GetVisibleUnits()
  432.         heading = {}
  433.         for i=1, #visibleUnits do
  434.                 local unitID = visibleUnits[i]
  435.                 dirx, _, dirz = spGetUnitDirection(unitID)
  436.                 if (dirz ~= nil) then
  437.                         degrot[unitID] = 180 - math_acos(dirz) * rad_con
  438.                 end
  439.         end
  440.         for i=1, #visibleCloaked do
  441.                 local unitID = visibleCloaked[i]
  442.                 dirx, _, dirz = spGetUnitDirection(unitID)
  443.                 if (dirz ~= nil) then
  444.                         if dirx < 0 then
  445.                                 degrot[unitID] = 180 - math_acos(dirz) * rad_con
  446.                         else
  447.                                 degrot[unitID] = 180 + math_acos(dirz) * rad_con
  448.                         end
  449.                 end
  450.         end
  451.         for i=1, #visibleSelected do
  452.                 local unitID = visibleSelected[i]
  453.                 dirx, _, dirz = spGetUnitDirection(unitID)
  454.                 if (dirz ~= nil) then
  455.                         if dirx < 0 then
  456.                                 degrot[unitID] = 180 - math_acos(dirz) * rad_con
  457.                         else
  458.                                 degrot[unitID] = 180 + math_acos(dirz) * rad_con
  459.                         end
  460.                 end
  461.         end
  462. end
  463.  
  464. --Funktion-vars for later use
  465.         local teamID    = 0
  466.         local unitID    = 0
  467.         local udid              = 0
  468.         local dirx              = 0
  469.         local diry              = 0
  470.         local dirz              = 0
  471.         local unit
  472. -- Drawing:
  473.  
  474.  
  475. function widget:DrawWorldPreUnit()
  476.         if Spring.IsGUIHidden() or (#visibleAllySelUnits + #visibleSelected + #visibleCloaked == 0) then return end
  477.        
  478.         glPushAttrib(GL_COLOR_BUFFER_BIT)
  479.  
  480.         glDepthTest(false)
  481.  
  482.         if #visibleSelected > 0 then
  483.                 -- To fix Water
  484.                 gl_ColorMask(false,false,false,true)
  485.                 gl_BlendFunc(GL_ONE, GL_ONE)
  486.                 glColor(0,1,0,1)
  487.                 -- Does not need to be drawn per Unit .. it covers the whole map
  488.                 gl_DrawList(clearquad)
  489.                
  490.                 --  Draw selection circles
  491.                 gl_BlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA)
  492.                 for i=1, #visibleSelected do
  493.                         unitID = visibleSelected[i]
  494.                         udid = spGetUnitDefID(unitID)
  495.                         unit = unitConf[udid]
  496.                        
  497.                         if (unit) then
  498.                                 glDrawListAtUnit(unitID, unit.shape.select, false, unit.xscale, 1.0, unit.zscale, degrot[unitID], 0, degrot[unitID], 0)
  499.                         end
  500.                 end
  501.  
  502.                 --  Here The inner of the selected circles are removed
  503.                 gl_BlendFunc(GL_ONE, GL_ZERO)
  504.                 glColor(0,0,0,1)
  505.                
  506.                 for i=1, #visibleSelected do
  507.                         unitID = visibleSelected[i]
  508.                         udid = spGetUnitDefID(unitID)
  509.                         unit = unitConf[udid]
  510.                        
  511.                         if (unit) then
  512.                                 glDrawListAtUnit(unitID, unit.shape.large, false, unit.xscale, 1.0, unit.zscale, degrot[unitID], 0, degrot[unitID], 0)
  513.                         end
  514.                 end    
  515.  
  516.                 --  Really draw the Circles now  (This could be optimised if we could say Draw as much as DST_ALPHA * SRC_ALPHA is)
  517.                 -- (without protecting form drawing them twice)
  518.                 gl_ColorMask(true,true,true,true)
  519.                 gl_BlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA)
  520.                 glColor(0,1,0,1)
  521.  
  522.                 -- Does not need to be drawn per Unit anymore
  523.                 gl_DrawList(clearquad)
  524.  
  525.                 --  Draw Circles to AlphaBuffer
  526.                 gl_ColorMask(false, false, false, true)
  527.                 gl_BlendFunc(GL_DST_ALPHA, GL_ZERO)
  528.  
  529.                 for i=1, #visibleSelected do
  530.                         unitID = visibleSelected[i]
  531.                         udid = spGetUnitDefID(unitID)
  532.                         unit = unitConf[udid]
  533.                        
  534.                         if (unit) then
  535.                                 glDrawListAtUnit(unitID, unit.shape.shape, false, unit.xscale, 1.0, unit.zscale, degrot[unitID], 0, degrot[unitID], 0)
  536.                                 glDrawListAtUnit(unitID, unit.shape.inner, false, unit.xscale, 1.0, unit.zscale, degrot[unitID], 0, degrot[unitID], 0)
  537.                         end
  538.                 end
  539.                
  540.                 for i=1, #visibleSelected do
  541.                         unitID = visibleSelected[i]
  542.                         udid = spGetUnitDefID(unitID)
  543.                         unit = unitConf[udid]
  544.                        
  545.                         if (unit) then
  546.                                 glColor(0,1,0,0)
  547.                                 glDrawListAtUnit(unitID, unit.shape.large, false, unit.xscale, 1.0, unit.zscale, degrot[unitID], 0, degrot[unitID], 0)
  548.                         end
  549.                 end
  550.         end --if #visibleSelected > 0
  551.        
  552.         --Can this massive if block be somehow merged into the above? I tried and tried.
  553.         if #visibleAllySelUnits > 0 then
  554.                 -- To fix Water
  555.                 gl_ColorMask(false,false,false,true)
  556.                 gl_BlendFunc(GL_ONE, GL_ONE)
  557.                 glColor(1,1,0,1)
  558.                 -- Does not need to be drawn per Unit .. it covers the whole map
  559.                 gl_DrawList(clearquad)
  560.                
  561.                 --  Draw selection circles
  562.                 gl_BlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA)
  563.                 for i=1, #visibleAllySelUnits do
  564.                         unitID = visibleAllySelUnits[i]
  565.                         udid = spGetUnitDefID(unitID)
  566.                         unit = unitConf[udid]
  567.                        
  568.                         if (unit) then
  569.                                 glDrawListAtUnit(unitID, unit.shape.select, false, unit.xscale, 1.0, unit.zscale, 0, 0, 0, 0)
  570.                         end
  571.                 end
  572.  
  573.                 --  Here The inner of the selected circles are removed
  574.                 gl_BlendFunc(GL_ONE, GL_ZERO)
  575.                 glColor(0,0,0,1)
  576.                
  577.                 for i=1, #visibleAllySelUnits do
  578.                         unitID = visibleAllySelUnits[i]
  579.                         udid = spGetUnitDefID(unitID)
  580.                         unit = unitConf[udid]
  581.                        
  582.                         if (unit) then
  583.                                 glDrawListAtUnit(unitID, unit.shape.large, false, unit.xscale, 1.0, unit.zscale,  0, 0, 0, 0)  
  584.                         end
  585.                 end    
  586.  
  587.                 --  Really draw the Circles now  (This could be optimised if we could say Draw as much as DST_ALPHA * SRC_ALPHA is)
  588.                 -- (without protecting form drawing them twice)
  589.                 gl_ColorMask(true,true,true,true)
  590.                 gl_BlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA)
  591.                 glColor(1,1,0,1)
  592.  
  593.                 -- Does not need to be drawn per Unit anymore
  594.                 gl_DrawList(clearquad)
  595.  
  596.                 --  Draw Circles to AlphaBuffer
  597.                 gl_ColorMask(false, false, false, true)
  598.                 gl_BlendFunc(GL_DST_ALPHA, GL_ZERO)
  599.  
  600.                 for i=1, #visibleAllySelUnits do
  601.                         unitID = visibleAllySelUnits[i]
  602.                         udid = spGetUnitDefID(unitID)
  603.                         unit = unitConf[udid]
  604.                        
  605.                         if (unit) then
  606.                                 glDrawListAtUnit(unitID, unit.shape.shape, false, unit.xscale, 1.0, unit.zscale, 0, 0, 0, 0)
  607.                                 glDrawListAtUnit(unitID, unit.shape.inner, false, unit.xscale, 1.0, unit.zscale, degrot[unitID], 0, degrot[unitID], 0)
  608.                         end
  609.                 end
  610.                
  611.                 for i=1, #visibleAllySelUnits do
  612.                         unitID = visibleAllySelUnits[i]
  613.                         udid = spGetUnitDefID(unitID)
  614.                         unit = unitConf[udid]
  615.                        
  616.                         if (unit) then
  617.                                 glColor(1,1,0,0)
  618.                                 glDrawListAtUnit(unitID, unit.shape.large, false, unit.xscale, 1.0, unit.zscale, degrot[unitID], 0, degrot[unitID], 0)
  619.                         end
  620.                 end
  621.         end --if #visibleAllySelUnits > 0
  622.        
  623.                 if #visibleCloaked > 0 then
  624.                 -- To fix Water
  625.                 gl_ColorMask(false,false,false,true)
  626.                 gl_BlendFunc(GL_ONE, GL_ONE)
  627.                 glColor(0,1,1,1)
  628.                 -- Does not need to be drawn per Unit .. it covers the whole map
  629.                 gl_DrawList(clearquad)
  630.                
  631.                 --  Draw selection circles
  632.                 gl_BlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA)
  633.                 for i=1, #visibleCloaked do
  634.                         unitID = visibleCloaked[i]
  635.                         udid = spGetUnitDefID(unitID)
  636.                         unit = unitConf[udid]
  637.                        
  638.                         if (unit) then
  639.                                 glDrawListAtUnit(unitID, unit.shape.select, false, unit.xscale, 1.0, unit.zscale, degrot[unitID], 0, degrot[unitID], 0)
  640.                         end
  641.                 end
  642.  
  643.                 --  Here The inner of the selected circles are removed
  644.                 gl_BlendFunc(GL_ONE, GL_ZERO)
  645.                 glColor(0,0,0,1)
  646.                
  647.                 for i=1, #visibleCloaked do
  648.                         unitID = visibleCloaked[i]
  649.                         udid = spGetUnitDefID(unitID)
  650.                         unit = unitConf[udid]
  651.                        
  652.                         if (unit) then
  653.                                 glDrawListAtUnit(unitID, unit.shape.large, false, unit.xscale, 1.0, unit.zscale, degrot[unitID], 0, degrot[unitID], 0)
  654.                         end
  655.                 end    
  656.  
  657.                 --  Really draw the Circles now  (This could be optimised if we could say Draw as much as DST_ALPHA * SRC_ALPHA is)
  658.                 -- (without protecting form drawing them twice)
  659.                 gl_ColorMask(true,true,true,true)
  660.                 gl_BlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA)
  661.                 glColor(0,1,1,1)
  662.  
  663.                 -- Does not need to be drawn per Unit anymore
  664.                 gl_DrawList(clearquad)
  665.  
  666.                 --  Draw Circles to AlphaBuffer
  667.                 gl_ColorMask(false, false, false, true)
  668.                 gl_BlendFunc(GL_DST_ALPHA, GL_ZERO)
  669.  
  670.                 for i=1, #visibleCloaked do
  671.                         unitID = visibleCloaked[i]
  672.                         udid = spGetUnitDefID(unitID)
  673.                         unit = unitConf[udid]
  674.                        
  675.                         if (unit) then
  676.                                 glDrawListAtUnit(unitID, unit.shape.shape, false, unit.xscale, 1.0, unit.zscale, degrot[unitID], 0, degrot[unitID], 0)
  677.                                 glDrawListAtUnit(unitID, unit.shape.inner, false, unit.xscale, 1.0, unit.zscale, degrot[unitID], 0, degrot[unitID], 0)
  678.                         end
  679.                 end
  680.                
  681.                 for i=1, #visibleCloaked do
  682.                         unitID = visibleCloaked[i]
  683.                         udid = spGetUnitDefID(unitID)
  684.                         unit = unitConf[udid]
  685.                        
  686.                         if (unit) then
  687.                                 glColor(0,1,1,0)
  688.                                 glDrawListAtUnit(unitID, unit.shape.large, false, unit.xscale, 1.0, unit.zscale, degrot[unitID], 0, degrot[unitID], 0)
  689.                         end
  690.                 end
  691.         end --if #visibleCloaked > 0
  692.        
  693.         glColor(1,1,1,1)
  694.         glPopAttrib()
  695. end
  696. --allySelUnits
  697.  
  698.        
  699.  
  700.  
  701. --------------------------------------------------------------------------------
  702. --------------------------------------------------------------------------------