Advertisement
Guest User

Untitled

a guest
Jul 11th, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.91 KB | None | 0 0
  1. function gadget:GetInfo()
  2.     return {
  3.         name      = "feature placer",
  4.         desc      = "Spawns Features and Units",
  5.         author    = "Gnome, Smoth",
  6.         date      = "August 2008, updated 7/11/2014",
  7.         license   = "PD",
  8.         layer     = 0,
  9.         enabled   = true  --  loaded by default?
  10.     }
  11. end
  12.  
  13. -- these are here because I like the way they look
  14. local   spSetUnitNeutral        = Spring.SetUnitNeutral
  15. local   spSetUnitBlocking       = Spring.SetUnitBlocking
  16. local   spSetUnitRotation       = Spring.SetUnitRotation
  17. local   spSetUnitLosState       = Spring.SetUnitLosState
  18. local   spSetUnitAlwaysVisible  = Spring.SetUnitAlwaysVisible
  19. local   spCreateUnit            = Spring.CreateUnit
  20. local   spGetGaiaTeamID         = Spring.GetGaiaTeamID
  21. local   spCreateFeature         = Spring.CreateFeature
  22. local   spGetGroundHeight       = Spring.GetGroundHeight
  23. local   spEcho                  = Spring.Echo
  24.  
  25. local   featurecfg
  26. local   featureslist    = {}
  27. local   buildinglist    = {}
  28. local   unitlist        = {}   
  29.  
  30. local   rotationMultiplier  = math.pi / 32768
  31. if gadgetHandler:IsSyncedCode() then
  32.     --SYNCED
  33.     function gadget:GamePreload()
  34.         if VFS.FileExists("config/featureconfig.lua") then
  35.             featurecfg = VFS.Include("config/featureconfig.lua")
  36.  
  37.             featureslist    = featurecfg.objectlist
  38.             buildinglist    = featurecfg.buildinglist
  39.             unitlist        = featurecfg.unitlist
  40.         else
  41.             spEcho("No gamename specific features loaded")
  42.         end
  43.  
  44.         if ( featurecfg ~= nil ) then
  45.             gaiaTeamID = spGetGaiaTeamID()
  46.                
  47.             if ( featureslist ) then
  48.                 for _,fDef in pairs(featureslist) do
  49.                     if FeatureDefNames[fDef.name] then
  50.                             spCreateFeature(fDef.name, fDef.x, spGetGroundHeight(fDef.x,fDef.z)+5, fDef.z, fDef.rot)
  51.                     else
  52.                         spEcho("featureplacer warning: invalid feature name", fDef.name)
  53.                     end
  54.                 end
  55.             end
  56.                        
  57.             if ( unitlist ) then   
  58.                 for _,uDef in pairs(unitlist) do
  59.                     if UnitDefNames[uDef.name] then
  60.                         local unitId = spCreateUnit(uDef.name, uDef.x, 0, uDef.z, 0, gaiaTeamID)
  61.                         if unitId ~= nil then
  62.                             spSetUnitRotation(unitId, 0, -uDef.rot * rotationMultiplier, 0)
  63.                             spSetUnitNeutral(unitId,true)
  64.                             spSetUnitBlocking(unitId,true)
  65.                             spSetUnitAlwaysVisible(unitId,true)
  66.                             spSetUnitLosState(unitId,0,{los=true, prevLos=true, contRadar=true, radar=true})
  67.                         end
  68.                     else
  69.                         spEcho("featureplacer warning: invalid unit def name", bDef.name)
  70.                     end
  71.                 end
  72.             end
  73.                        
  74.             if ( buildinglist ) then
  75.                 for _,bDef in pairs(buildinglist) do
  76.                     if UnitDefNames[bDef.name] then
  77.                         local buildingId = spCreateUnit(bDef.name, bDef.x, 0, bDef.z, bDef.rot, gaiaTeamID)
  78.                         if buildingId ~= nil then
  79.                             spSetUnitNeutral(buildingId,true)
  80.                             spSetUnitBlocking(buildingId,true)
  81.                             spSetUnitAlwaysVisible(buildingId,true)
  82.                             spSetUnitLosState(buildingId,0,{los=true, prevLos=true, contRadar=true, radar=true})
  83.                         end
  84.                     else
  85.                         spEcho("featureplacer warning: invalid building def name", bDef.name)
  86.                     end
  87.                 end
  88.             end
  89.         end
  90.     end
  91. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement