⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gui_team_platter.lua

📁 这是整套横扫千军3D版游戏的源码
💻 LUA
字号:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------  file:    gui_team_platter.lua--  brief:   team colored platter for all visible units--  author:  Dave Rodgers----  Copyright (C) 2007.--  Licensed under the terms of the GNU GPL, v2 or later.------------------------------------------------------------------------------------------------------------------------------------------------------------------function widget:GetInfo()  return {    name      = "TeamPlatter",    desc      = "Shows a team color platter above all visible units",    author    = "trepan",    date      = "Apr 16, 2007",    license   = "GNU GPL, v2 or later",    layer     = 5,    enabled   = false  --  loaded by default?  }end------------------------------------------------------------------------------------------------------------------------------------------------------------------ Automatically generated local definitionslocal GL_LINE_LOOP           = GL.LINE_LOOPlocal GL_TRIANGLE_FAN        = GL.TRIANGLE_FANlocal glBeginEnd             = gl.BeginEndlocal glColor                = gl.Colorlocal glCreateList           = gl.CreateListlocal glDeleteList           = gl.DeleteListlocal glDepthTest            = gl.DepthTestlocal glDrawListAtUnit       = gl.DrawListAtUnitlocal glLineWidth            = gl.LineWidthlocal glPolygonOffset        = gl.PolygonOffsetlocal glVertex               = gl.Vertexlocal spDiffTimers           = Spring.DiffTimerslocal spGetAllUnits          = Spring.GetAllUnitslocal spGetGroundNormal      = Spring.GetGroundNormallocal spGetSelectedUnits     = Spring.GetSelectedUnitslocal spGetTeamColor         = Spring.GetTeamColorlocal spGetTimer             = Spring.GetTimerlocal spGetUnitBasePosition  = Spring.GetUnitBasePositionlocal spGetUnitDefDimensions = Spring.GetUnitDefDimensionslocal spGetUnitDefID         = Spring.GetUnitDefIDlocal spGetUnitRadius        = Spring.GetUnitRadiuslocal spGetUnitTeam          = Spring.GetUnitTeamlocal spGetUnitViewPosition  = Spring.GetUnitViewPositionlocal spIsUnitSelected       = Spring.IsUnitSelectedlocal spIsUnitVisible        = Spring.IsUnitVisiblelocal spSendCommands         = Spring.SendCommands----------------------------------------------------------------------------------------------------------------------------------------------------------------local function SetupCommandColors(state)  local alpha = state and 1 or 0  local f = io.open('cmdcolors.tmp', 'w+')  if (f) then    f:write('unitBox  0 1 0 ' .. alpha)    f:close()    spSendCommands({'cmdcolors cmdcolors.tmp'})  end  os.remove('cmdcolors.tmp')end----------------------------------------------------------------------------------------------------------------------------------------------------------------local teamColors = {}local trackSlope = truelocal circleLines  = 0local circlePolys  = 0local circleDivs   = 32local circleOffset = 0local startTimer = spGetTimer()----------------------------------------------------------------------------------------------------------------------------------------------------------------function widget:Initialize()  circleLines = glCreateList(function()    glBeginEnd(GL_LINE_LOOP, function()      local radstep = (2.0 * math.pi) / circleDivs      for i = 1, circleDivs do        local a = (i * radstep)        glVertex(math.sin(a), circleOffset, math.cos(a))      end    end)  end)  circlePolys = glCreateList(function()    glBeginEnd(GL_TRIANGLE_FAN, function()      local radstep = (2.0 * math.pi) / circleDivs      for i = 1, circleDivs do        local a = (i * radstep)        glVertex(math.sin(a), circleOffset, math.cos(a))      end    end)  end)  SetupCommandColors(false)endfunction widget:Shutdown()  glDeleteList(circleLines)  glDeleteList(circlePolys)  SetupCommandColors(true)end----------------------------------------------------------------------------------------------------------------------------------------------------------------local realRadii = {}local function GetUnitDefRealRadius(udid)  local radius = realRadii[udid]  if (radius) then    return radius  end  local ud = UnitDefs[udid]  if (ud == nil) then return nil end  local dims = spGetUnitDefDimensions(udid)  if (dims == nil) then return nil end  local scale = ud.hitSphereScale  scale = (scale == 0.0) and 1.0 or scale  radius = dims.radius / scale  realRadii[udid] = radius  return radiusend----------------------------------------------------------------------------------------------------------------------------------------------------------------local teamColors = {}local function GetTeamColorSet(teamID)  local colors = teamColors[teamID]  if (colors) then    return colors  end  local r,g,b = spGetTeamColor(teamID)    colors = {{ r, g, b, 0.4 },            { r, g, b, 0.7 }}  teamColors[teamID] = colors  return colorsend----------------------------------------------------------------------------------------------------------------------------------------------------------------function widget:DrawWorldPreUnit()  glLineWidth(3.0)  glDepthTest(true)    glPolygonOffset(-50, -2)  local lastColorSet = nil  for _,unitID in ipairs(spGetAllUnits()) do    if (spIsUnitVisible(unitID)) then      local teamID = spGetUnitTeam(unitID)      if (teamID) then        local udid = spGetUnitDefID(unitID)        local radius = GetUnitDefRealRadius(udid)        if (radius) then          local colorSet  = GetTeamColorSet(teamID)          if (trackSlope and (not UnitDefs[udid].canFly)) then            local x, y, z = spGetUnitBasePosition(unitID)            local gx, gy, gz = spGetGroundNormal(x, z)            local degrot = math.acos(gy) * 180 / math.pi            glColor(colorSet[1])            glDrawListAtUnit(unitID, circlePolys, false,                             radius, 1.0, radius,                             degrot, gz, 0, -gx)            glColor(colorSet[2])            glDrawListAtUnit(unitID, circleLines, false,                             radius, 1.0, radius,                             degrot, gz, 0, -gx)          else            glColor(colorSet[1])            glDrawListAtUnit(unitID, circlePolys, false,                             radius, 1.0, radius)            glColor(colorSet[2])            glDrawListAtUnit(unitID, circleLines, false,                             radius, 1.0, radius)          end        end      end    end  end  glPolygonOffset(false)  --  -- Blink the selected units  --  glDepthTest(false)  local diffTime = spDiffTimers(spGetTimer(), startTimer)  local alpha = 1.8 * math.abs(0.5 - (diffTime * 3.0 % 1.0))  glColor(1, 1, 1, alpha)  for _,unitID in ipairs(spGetSelectedUnits()) do    local udid = spGetUnitDefID(unitID)    local radius = GetUnitDefRealRadius(udid)    if (radius) then      if (trackSlope and (not UnitDefs[udid].canFly)) then        local x, y, z = spGetUnitBasePosition(unitID)        local gx, gy, gz = spGetGroundNormal(x, z)        local degrot = math.acos(gy) * 180 / math.pi        glDrawListAtUnit(unitID, circleLines, false,                         radius, 1.0, radius,                          degrot, gz, 0, -gx)      else        glDrawListAtUnit(unitID, circleLines, false,                         radius, 1.0, radius)      end    end  end  glLineWidth(1.0)end              ----------------------------------------------------------------------------------------------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -