Page 1 of 2

Creeping metal gadget

Posted: 25 Oct 2007, 20:23
by Decimator
What am I doing wrong here? Or am I just hopelessly lost?

This widget is supposed to display a textured groundquad under a unit. Eventually, it will be used to make a growing creep-style graphical effect.

http://pastebin.com/m539a6943

Code: Select all

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
--  file:    unit_metals.lua
--  brief:   Adds metal creep junk
--  author:  aegis
--
--  Copyright (C) 2007.
--  Licensed under the terms of the GNU GPL, v2 or later.
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function gadget:GetInfo()
  return {
    name      = "UnitMetals",
    desc      = "Adds metal creep functionality",
    author    = "aegis",
    date      = "September 23, 2007",
    license   = "GNU GPL, v2 or later",
    layer     = 0,
    enabled   = true  --  loaded by default?
  }
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
--  Proposed Command ID Ranges:
--
--    all negative:  Engine (build commands)
--       0 -   999:  Engine
--    1000 -  9999:  Group AI
--   10000 - 19999:  LuaUI
--   20000 - 29999:  LuaCob
--   30000 - 39999:  LuaRules

--------------------------------------------------------------------------------
--  COMMON
--------------------------------------------------------------------------------

function isFinished(UnitID)
  local _,_,_,_,buildProgress = Spring.GetUnitHealth(UnitID)
  if ((buildProgress) and (buildProgress>=1)) then
    return true
  end
  return false
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

if (gadgetHandler:IsSyncedCode()) then
--------------------------------------------------------------------------------
--  SYNCED
--------------------------------------------------------------------------------

include("LuaRules/colors.h.lua")



local metalDefs = {}
local metalUnits = {} -- make it global in Initialize()

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local function DefCost(paramName, udSrc, udDst)
  local pSrc = udSrc[paramName]
  local pDst = udDst[paramName]
  if ((not pSrc) or (not pDst) or
      (type(pSrc) ~= 'number') or
      (type(pDst) ~= 'number')) then
    return 0
  end
  local cost = (pDst - pSrc) * metalPenalty
  if (cost < 0) then
    cost = 0
  end
  return math.floor(cost)
end


local function ValidatemetalDefs(mds)
  local newDefs = {}
  for src,metalData in pairs(mds) do
    local udSrc = UnitDefNames[string.lower(src)]
    if (not udSrc) then
      Spring.Echo('Bad metal src type: ' .. src)
    end
    if (udSrc and udDst) then
      local unitDef = UnitDefs[udSrc.id]
      local newData = {}
      newData.into = udDst.id
      newData.speed = metalData.speed or 1
      newDefs[udSrc.id] = newData
    end
  end
  return newDefs
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local function UpdateMorphPossibilities(teamID)
  local teamTech = teamTechLevel[teamID] or 0

  local units = Spring.GetTeamUnitsSorted(teamID)
  for unitDefID,unitIDs in pairs(units) do
    local metalDefs     = metalDefs[unitDefID]

    if (metalDefs) then
      for _,unitID in ipairs(unitIDs) do
        local cmdDescID = Spring.FindUnitCmdDesc(unitID, CMD_MORPH)
        if (cmdDescID) then

          local unitXP = Spring.GetUnitExperience(unitID)
          local metalCmdDesc = {}
          metalCmdDesc.disabled = (metalDefs.tech > teamTech)or(metalDefs.xp > unitXP)
          metalCmdDesc.tooltip  = GetMorphToolTip(unitID, metalDefs, teamTech, unitXP)
          Spring.EditUnitCmdDesc(unitID, cmdDescID, metalCmdDesc)

        end
      end
    end
  end
end


--------------------------------------------------------------------------------


------------
-- REPLACE THESE WITH THE CORRECT FUNCTIONS ;)
------------


local function StartMetal(unitID, metalDefs)



  -- paralyze the unit
  Spring.SetUnitHealth(unitID, { paralyze = 1.0e9 })    -- turns mexes and mm off
  Spring.SetUnitResourcing(unitID,"e",0)                -- turns solars off
  Spring.GiveOrderToUnit(unitID, CMD.ONOFF, { 0 }, { }) -- turns radars/jammers off

  metalUnits[unitID] = {
    def = metalDefs,
    progress = 0.0,
    increment = metalDefs.increment
   }



end


local function UpdateMetal(unitID, metalData)



  if (Spring.UseUnitResource(unitID, metalData.def.resTable)) then
    metalData.progress = metalData.progress + metalData.increment
  end
  if (metalData.progress >= 1.0) then
    FinishMorph(unitID, metalData)
    return false -- remove from the list, all done
  end
  return true



end


--------------------------------------------------------------------------------

function gadget:Initialize()
  --[[
  if Spring.IsReplay() then
    gadgetHandler:RemoveGadget()
    return    
  end
  --]]

  _G.metalUnits = metalUnits  -- make it global for unsynced access via SYNCED
  -- get the metalDefs
  metalDefs = include("LuaRules/Configs/metal_defs.lua")
  if (not metalDefs) then
    gadgetHandler:RemoveGadget()
    return
  end

  metalDefs = ValidatemetalDefs(metalDefs)

  -- add the Morph command to existing units
  for _,unitID in ipairs(Spring.GetAllUnits()) do
    local teamID    = Spring.GetUnitTeam(unitID)
    local unitDefID = Spring.GetUnitDefID(unitID)
    local metalDefs  = metalDefs[unitDefID]
    if (metalDefs) then
      --make code here :)
    end
  end
end

function gadget:UnitCreated(unitID, unitDefID, teamID)
  local metalDefs = metalDefs[unitDefID]
  if (metalDefs) then
    --- dunno
  end 
end

function gadget:UnitDestroyed(unitID, unitDefID, teamID)
  --use unitID to check if there's metal, remove, do something ;)
end

function gadget:UnitTaken(unitID, unitDefID, oldTeamID, teamID)
  --this should work as is
  self:UnitCreated(unitID, unitDefID, teamID)
end

function gadget:UnitGiven(unitID, unitDefID, newTeamID, teamID)
  --dunno
end

function gadget:UnitFinished(unitID, unitDefID, teamID)
  --add start function here?
  if (metalDefs) then
    local px, py, pz = Spring.GetUnitBasePosition(unitID)
	_G.px1 = px + 4
	_G.px2 = px - 4
	_G.pz1 = pz + 4
	_G.pz2 = pz - 4
  end
end


function gadget:GameFrame(n)
  if ((n+28) % 64)<1 then
    local teamIDs = Spring.GetTeamList()
    for _,teamID in ipairs(teamIDs) do
      -- UpdateMetalPossibilities(teamID)
      -- make this update the list of units with metal radii?
    end
  end

  if (next(metalUnits) == nil) then
    return  -- no metal spot units
  end
  local killUnits = {}
  for unitID, metalData in pairs(metalUnits) do
    if (not UpdateMetal(unitID, metalData)) then
      killUnits[unitID] = true
    end
  end
  for unitID in pairs(killUnits) do
    metalUnits[unitID] = nil
  end
end

--------------------------------------------------------------------------------
--  SYNCED
--------------------------------------------------------------------------------
else
--------------------------------------------------------------------------------
--  UNSYNCED
--------------------------------------------------------------------------------

--
-- speed-ups
--


local SYNCED = SYNCED

local GetUnitTeam         = Spring.GetUnitTeam
local GetUnitHeading      = Spring.GetUnitHeading
local GetUnitBasePosition = Spring.GetUnitBasePosition
local GetGameFrame        = Spring.GetGameFrame
local GetSpectatingState  = Spring.GetSpectatingState
local AddWorldIcon        = Spring.AddWorldIcon
local AddWorldText        = Spring.AddWorldText

local glColor      = gl.Color
local glPushMatrix = gl.PushMatrix
local glTranslate  = gl.Translate
local glRotate     = gl.Rotate
local glUnitShape  = gl.UnitShape
local glPopMatrix  = gl.PopMatrix


--------------------------------------------------------------------------------

local function SelectSwap(cmd, oldID, newID)
  local selUnits = Spring.GetSelectedUnits()
  for i, unitID in ipairs(selUnits) do
    if (unitID == oldID) then
      selUnits[i] = newID
      Spring.SelectUnitArray(selUnits)
      return true
    end
  end
  return true
end


function gadget:Initialize()
  gadgetHandler:AddSyncAction("unit_metal", SelectSwap)
end


function gadget:Shutdown()
  gadgetHandler:RemoveSyncAction("unit_metal")
end


local teamColors = {}
local function SetTeamColor(teamID,a)
  local color = teamColors[teamID]
  if (color) then
    color[4]=a
    glColor(color)
    return
  end
  local _,_,_,_,_,_,r,g,b = Spring.GetTeamInfo(teamID)
  if (r and g and b) then
    color = { r, g, b }
    teamColors[teamID] = color
    glColor(color)
    return
  end
end


local function DrawMetalUnit(unitID, metalData, localTeamID)
--[[ commented out until you work it out :)
  local unitTeam = GetUnitTeam(unitID)
  local h = GetUnitHeading(unitID)
  if (not h) then
    return  -- bonus, heading is only available when the unit is in LOS
  end
  local px,py,pz = GetUnitBasePosition(unitID)
  if (not px) then
    return
  end

  local frac = math.mod(GetGameFrame() + unitID, 30) / 30
  local alpha = 2.0 * math.abs(0.5 - frac)
  --glColor(1.0, 1.0, 1.0, alpha*0.3)
  SetTeamColor(unitTeam,alpha)
  glPushMatrix()
  glTranslate(px, py, pz)
  glRotate(h * (360 / 65535), 0, 1, 0)
  glUnitShape(metalData.def.into, unitTeam)
  glPopMatrix()


  -- cheesy progress indicator
  if (localTeamID)and(unitTeam==localTeamID) then
    glPushMatrix()
    glTranslate(px, py-20, pz)
    gl.Billboard()
    local progStr = string.format("%.1f%%", 100 * metalData.progress)
    gl.Text(progStr, 0, 0, 7, "oc")
    glPopMatrix()
  end
]]--
end




function gadget:DrawWorld()
  local metalUnits = SYNCED.metalUnits
  if ((not metalUnits) or (snext(metalUnits) == nil)) then
    return -- no metals to draw
  end

  --gl.Blending(GL.SRC_ALPHA, GL.ONE)
  --gl.DepthTest(GL.LEQUAL)
  local texName = "Bitmaps/metalring.png"
  if (metalDefs) then
  local px1 = SYNCED.px1
  local px2 = SYNCED.px2
  local pz1 = SYNCED.pz1
  local pz2 = SYNCED.pz2
    gl.Texture(texName)
    gl.DrawGroundQuad(px1, pz1, px2, pz2)
    gl.Texture(false)
  end
  
  local spec, specFullView = GetSpectatingState()
  local readTeam
  if (specFullView) then
    readTeam = Script.ALL_ACCESS_TEAM
  else
    readTeam = Spring.GetLocalTeamID()
  end

  CallAsTeam({ ['read'] = readTeam }, function()
    for unitID, metalData in spairs(metalUnits) do
      if (unitID and metalData) then  -- FIXME: huh?
        DrawMorphUnit(unitID, metalData,readTeam)
      end
    end
  end)
  --gl.DepthTest(false)
  --gl.Blending(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA)
end



--------------------------------------------------------------------------------
--  UNSYNCED
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------
--  COMMON
--------------------------------------------------------------------------------

Code: Select all

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local metalDefs = {

  -- units
  aliensoldl = {
    speed = 3
  },
  alienmsoldl = {
    speed = 2.5
  },
}


return metalDefs

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

Posted: 25 Oct 2007, 21:02
by Forboding Angel
For those of us that are unlearned, could you go into a little more detail as to what this does (or is supposed to do)?

Posted: 25 Oct 2007, 21:10
by tombom
What doesn't work?

Posted: 25 Oct 2007, 21:19
by rattle
Doesn't CA have blob shadows for planes? If you're lucky they do it with a quad and blob texture.

Posted: 26 Oct 2007, 18:20
by Decimator
The groundquad simply doesn't display. No crash, no error, it just doesn't work.

Forb, all it's supposed to do at the moment is display a textured groundquad under a unit.

Posted: 26 Oct 2007, 18:43
by jK
First you shouldn't use gl.DrawGroundQuad(). don't ask me why, but it rounds the given coordinates (see the decal groundquads under factories).

For your problem see here.
-> gl.DrawGroundQuad
( number x1, number z1, number x2, number z2, [ boolean useNorm, [ number tu1, number tv1, number tu2, number tv2 | boolean useTextureCoord ] ] ) -> nil

so it must be: gl.DrawGroundQuad(px1, pz1, px2, pz2, false,true)

PS: I recommend the manual drawing of the quad (using GetGroundHeight() + glVertex)

Re: Creeping metal gadget

Posted: 28 Oct 2007, 14:36
by duderham
Decimator wrote:What am I doing wrong here? Or am I just hopelessly lost?

This widget is supposed to display a textured groundquad under a unit. Eventually, it will be used to make a growing creep-style graphical effect.

http://pastebin.com/m539a6943

Code: Select all

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
--  file:    unit_metals.lua
--  brief:   Adds metal creep junk
--  author:  aegis
--
--  Copyright (C) 2007.
--  Licensed under the terms of the GNU GPL, v2 or later.
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function gadget:GetInfo()
  return {
    name      = "UnitMetals",
    desc      = "Adds metal creep functionality",
    author    = "aegis",
    date      = "September 23, 2007",
    license   = "GNU GPL, v2 or later",
    layer     = 0,
    enabled   = true  --  loaded by default?
  }
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
--  Proposed Command ID Ranges:
--
--    all negative:  Engine (build commands)
--       0 -   999:  Engine
--    1000 -  9999:  Group AI
--   10000 - 19999:  LuaUI
--   20000 - 29999:  LuaCob
--   30000 - 39999:  LuaRules

--------------------------------------------------------------------------------
--  COMMON
--------------------------------------------------------------------------------

function isFinished(UnitID)
  local _,_,_,_,buildProgress = Spring.GetUnitHealth(UnitID)
  if ((buildProgress) and (buildProgress>=1)) then
    return true
  end
  return false
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

if (gadgetHandler:IsSyncedCode()) then
--------------------------------------------------------------------------------
--  SYNCED
--------------------------------------------------------------------------------

include("LuaRules/colors.h.lua")



local metalDefs = {}
local metalUnits = {} -- make it global in Initialize()

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local function DefCost(paramName, udSrc, udDst)
  local pSrc = udSrc[paramName]
  local pDst = udDst[paramName]
  if ((not pSrc) or (not pDst) or
      (type(pSrc) ~= 'number') or
      (type(pDst) ~= 'number')) then
    return 0
  end
  local cost = (pDst - pSrc) * metalPenalty
  if (cost < 0) then
    cost = 0
  end
  return math.floor(cost)
end


local function ValidatemetalDefs(mds)
  local newDefs = {}
  for src,metalData in pairs(mds) do
    local udSrc = UnitDefNames[string.lower(src)]
    if (not udSrc) then
      Spring.Echo('Bad metal src type: ' .. src)
    end
    if (udSrc and udDst) then
      local unitDef = UnitDefs[udSrc.id]
      local newData = {}
      newData.into = udDst.id
      newData.speed = metalData.speed or 1
      newDefs[udSrc.id] = newData
    end
  end
  return newDefs
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local function UpdateMorphPossibilities(teamID)
  local teamTech = teamTechLevel[teamID] or 0

  local units = Spring.GetTeamUnitsSorted(teamID)
  for unitDefID,unitIDs in pairs(units) do
    local metalDefs     = metalDefs[unitDefID]

    if (metalDefs) then
      for _,unitID in ipairs(unitIDs) do
        local cmdDescID = Spring.FindUnitCmdDesc(unitID, CMD_MORPH)
        if (cmdDescID) then

          local unitXP = Spring.GetUnitExperience(unitID)
          local metalCmdDesc = {}
          metalCmdDesc.disabled = (metalDefs.tech > teamTech)or(metalDefs.xp > unitXP)
          metalCmdDesc.tooltip  = GetMorphToolTip(unitID, metalDefs, teamTech, unitXP)
          Spring.EditUnitCmdDesc(unitID, cmdDescID, metalCmdDesc)

        end
      end
    end
  end
end


--------------------------------------------------------------------------------


------------
-- REPLACE THESE WITH THE CORRECT FUNCTIONS ;)
------------


local function StartMetal(unitID, metalDefs)



  -- paralyze the unit
  Spring.SetUnitHealth(unitID, { paralyze = 1.0e9 })    -- turns mexes and mm off
  Spring.SetUnitResourcing(unitID,"e",0)                -- turns solars off
  Spring.GiveOrderToUnit(unitID, CMD.ONOFF, { 0 }, { }) -- turns radars/jammers off

  metalUnits[unitID] = {
    def = metalDefs,
    progress = 0.0,
    increment = metalDefs.increment
   }



end


local function UpdateMetal(unitID, metalData)



  if (Spring.UseUnitResource(unitID, metalData.def.resTable)) then
    metalData.progress = metalData.progress + metalData.increment
  end
  if (metalData.progress >= 1.0) then
    FinishMorph(unitID, metalData)
    return false -- remove from the list, all done
  end
  return true



end


--------------------------------------------------------------------------------

function gadget:Initialize()
  --[[
  if Spring.IsReplay() then
    gadgetHandler:RemoveGadget()
    return    
  end
  --]]

  _G.metalUnits = metalUnits  -- make it global for unsynced access via SYNCED
  -- get the metalDefs
  metalDefs = include("LuaRules/Configs/metal_defs.lua")
  if (not metalDefs) then
    gadgetHandler:RemoveGadget()
    return
  end

  metalDefs = ValidatemetalDefs(metalDefs)

  -- add the Morph command to existing units
  for _,unitID in ipairs(Spring.GetAllUnits()) do
    local teamID    = Spring.GetUnitTeam(unitID)
    local unitDefID = Spring.GetUnitDefID(unitID)
    local metalDefs  = metalDefs[unitDefID]
    if (metalDefs) then
      --make code here :)
    end
  end
end

function gadget:UnitCreated(unitID, unitDefID, teamID)
  local metalDefs = metalDefs[unitDefID]
  if (metalDefs) then
    --- dunno
  end 
end

function gadget:UnitDestroyed(unitID, unitDefID, teamID)
  --use unitID to check if there's metal, remove, do something ;)
end

function gadget:UnitTaken(unitID, unitDefID, oldTeamID, teamID)
  --this should work as is
  self:UnitCreated(unitID, unitDefID, teamID)
end

function gadget:UnitGiven(unitID, unitDefID, newTeamID, teamID)
  --dunno
end

function gadget:UnitFinished(unitID, unitDefID, teamID)
  --add start function here?
  if (metalDefs) then
    local px, py, pz = Spring.GetUnitBasePosition(unitID)
	_G.px1 = px + 4
	_G.px2 = px - 4
	_G.pz1 = pz + 4
	_G.pz2 = pz - 4
  end
end


function gadget:GameFrame(n)
  if ((n+28) % 64)<1 then
    local teamIDs = Spring.GetTeamList()
    for _,teamID in ipairs(teamIDs) do
      -- UpdateMetalPossibilities(teamID)
      -- make this update the list of units with metal radii?
    end
  end

  if (next(metalUnits) == nil) then
    return  -- no metal spot units
  end
  local killUnits = {}
  for unitID, metalData in pairs(metalUnits) do
    if (not UpdateMetal(unitID, metalData)) then
      killUnits[unitID] = true
    end
  end
  for unitID in pairs(killUnits) do
    metalUnits[unitID] = nil
  end
end

--------------------------------------------------------------------------------
--  SYNCED
--------------------------------------------------------------------------------
else
--------------------------------------------------------------------------------
--  UNSYNCED
--------------------------------------------------------------------------------

--
-- speed-ups
--


local SYNCED = SYNCED

local GetUnitTeam         = Spring.GetUnitTeam
local GetUnitHeading      = Spring.GetUnitHeading
local GetUnitBasePosition = Spring.GetUnitBasePosition
local GetGameFrame        = Spring.GetGameFrame
local GetSpectatingState  = Spring.GetSpectatingState
local AddWorldIcon        = Spring.AddWorldIcon
local AddWorldText        = Spring.AddWorldText

local glColor      = gl.Color
local glPushMatrix = gl.PushMatrix
local glTranslate  = gl.Translate
local glRotate     = gl.Rotate
local glUnitShape  = gl.UnitShape
local glPopMatrix  = gl.PopMatrix


--------------------------------------------------------------------------------

local function SelectSwap(cmd, oldID, newID)
  local selUnits = Spring.GetSelectedUnits()
  for i, unitID in ipairs(selUnits) do
    if (unitID == oldID) then
      selUnits[i] = newID
      Spring.SelectUnitArray(selUnits)
      return true
    end
  end
  return true
end


function gadget:Initialize()
  gadgetHandler:AddSyncAction("unit_metal", SelectSwap)
end


function gadget:Shutdown()
  gadgetHandler:RemoveSyncAction("unit_metal")
end


local teamColors = {}
local function SetTeamColor(teamID,a)
  local color = teamColors[teamID]
  if (color) then
    color[4]=a
    glColor(color)
    return
  end
  local _,_,_,_,_,_,r,g,b = Spring.GetTeamInfo(teamID)
  if (r and g and b) then
    color = { r, g, b }
    teamColors[teamID] = color
    glColor(color)
    return
  end
end


local function DrawMetalUnit(unitID, metalData, localTeamID)
--[[ commented out until you work it out :)
  local unitTeam = GetUnitTeam(unitID)
  local h = GetUnitHeading(unitID)
  if (not h) then
    return  -- bonus, heading is only available when the unit is in LOS
  end
  local px,py,pz = GetUnitBasePosition(unitID)
  if (not px) then
    return
  end

  local frac = math.mod(GetGameFrame() + unitID, 30) / 30
  local alpha = 2.0 * math.abs(0.5 - frac)
  --glColor(1.0, 1.0, 1.0, alpha*0.3)
  SetTeamColor(unitTeam,alpha)
  glPushMatrix()
  glTranslate(px, py, pz)
  glRotate(h * (360 / 65535), 0, 1, 0)
  glUnitShape(metalData.def.into, unitTeam)
  glPopMatrix()


  -- cheesy progress indicator
  if (localTeamID)and(unitTeam==localTeamID) then
    glPushMatrix()
    glTranslate(px, py-20, pz)
    gl.Billboard()
    local progStr = string.format("%.1f%%", 100 * metalData.progress)
    gl.Text(progStr, 0, 0, 7, "oc")
    glPopMatrix()
  end
]]--
end




function gadget:DrawWorld()
  local metalUnits = SYNCED.metalUnits
  if ((not metalUnits) or (snext(metalUnits) == nil)) then
    return -- no metals to draw
  end

  --gl.Blending(GL.SRC_ALPHA, GL.ONE)
  --gl.DepthTest(GL.LEQUAL)
  local texName = "Bitmaps/metalring.png"
  if (metalDefs) then
  local px1 = SYNCED.px1
  local px2 = SYNCED.px2
  local pz1 = SYNCED.pz1
  local pz2 = SYNCED.pz2
    gl.Texture(texName)
    gl.DrawGroundQuad(px1, pz1, px2, pz2)
    gl.Texture(false)
  end
  
  local spec, specFullView = GetSpectatingState()
  local readTeam
  if (specFullView) then
    readTeam = Script.ALL_ACCESS_TEAM
  else
    readTeam = Spring.GetLocalTeamID()
  end

  CallAsTeam({ ['read'] = readTeam }, function()
    for unitID, metalData in spairs(metalUnits) do
      if (unitID and metalData) then  -- FIXME: huh?
        DrawMorphUnit(unitID, metalData,readTeam)
      end
    end
  end)
  --gl.DepthTest(false)
  --gl.Blending(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA)
end



--------------------------------------------------------------------------------
--  UNSYNCED
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------
--  COMMON
--------------------------------------------------------------------------------

Code: Select all

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local metalDefs = {

  -- units
  aliensoldl = {
    speed = 3
  },
  alienmsoldl = {
    speed = 2.5
  },
}


return metalDefs

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Had a quick look through it. I've found some errors and I'll try and sort them out. I should have a working prototype by this afternoon. :P

Posted: 28 Oct 2007, 15:07
by Decimator
No need, duderham. I made progress last night.

Image

Next on my list is to texture that circle with a repeating texture. Trepan suggested multitexturing. I think gl.multitexgen is the command I need to use.

Posted: 28 Oct 2007, 15:43
by jK
multitexuring is done with gl.Texture([0-7], texturename).
gl.MultiTexGen auto-generates the texcoord for you, so you can generate the texcoords of the 2nd texture (normally you need to use gl.MultiTexCoord() to do so) in gl.DrawGroundQuad() (itself don't set the 2nd texcoords!).

Use google if you want to learn more about glTexGen.

PS: the easiest way is still multi pass rendering (you need gl.PolygonOffset() for this).

Posted: 28 Oct 2007, 18:44
by Decimator
Still needs a better overlay texture, but it works. :)

The current script: http://pastebin.com/f505bd679

Next will be to make it a permanent feature of a building and have it grow over time.

Image

Posted: 28 Oct 2007, 21:14
by 1v0ry_k1ng
zerg?

Posted: 28 Oct 2007, 21:31
by imbaczek
toss!

Posted: 28 Oct 2007, 23:44
by [XIII]Roxas
Bravo. One question, though: You've said that it can grow up walls. Does it treat these walls as elevated terrain, or simply a large slope?

Posted: 29 Oct 2007, 00:13
by rattle
The ground texture gets overdrawn if it conforms to terrain.
gl.DrawGroundQuad(px1, pz1, px2, pz2)
Indeed it does.

Posted: 29 Oct 2007, 03:00
by Decimator
It acts like the map texture:

Image

Re: Creeping metal gadget

Posted: 01 Aug 2008, 16:02
by FrOzEnTaCo
reminds me of the aeon. :-)

Re: Creeping metal gadget

Posted: 01 Aug 2008, 16:13
by Peet
Stop unnecessarily resurrecting threads, please.

Re: Creeping metal gadget

Posted: 01 Aug 2008, 16:19
by Hoi
Peet wrote:Stop unnecessarily resurrecting threads, please.
its good that he bumped it, i need something like this!

Re: Creeping metal gadget

Posted: 02 Aug 2008, 04:47
by REVENGE
Whoa shit, didn't even realize something like this existed. Ok, so how far have we gotten with this? Do we have the ability to modify the metalmap ingame now? Also, could this be modified to make the metal creep out randomly instead of in a circle, like vines growing out from a plant or something like that?

Re: Creeping metal gadget

Posted: 08 Aug 2008, 03:09
by Decimator
REVENGE wrote:Whoa shit, didn't even realize something like this existed. Ok, so how far have we gotten with this? Do we have the ability to modify the metalmap ingame now? Also, could this be modified to make the metal creep out randomly instead of in a circle, like vines growing out from a plant or something like that?
It was never intended to modify the metalmap and does not. I have not touched it since what you see here, due to my lack of lua ability and lack of current interest. It cannot easily be made to creep out randomly due to how it functions. That would require something quite different.