Changeset 3344

Show
Ignore:
Timestamp:
12/01/08 19:29:39 (5 weeks ago)
Author:
licho
Message:

PW morphing takes unit owner directly as parameter

Location:
trunk/mods/ca/LuaRules/Gadgets
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/mods/ca/LuaRules/Gadgets/planetwars.lua

    r3342 r3344  
    4343                                        if (unitDef.isBuilding == true or unitDef.maxAcc == 0) then -- structure 
    4444                                                uid = CreateUnit("armpwdeploy", tryx, tryy, tryz, 'N', teamnum - 1) -- todo determine side name 
    45                                                 GG.morphHandler.AddExtraUnitMorph(uid, {into = m.unitname, time = 10, metal=0, energy=0,}) 
     45                                                GG.morphHandler.AddExtraUnitMorph(uid, {into = m.unitname, time = 20, metal=0, energy=0,}, m.owner) 
    4646                                        else -- normal unit 
    4747                                                uid = CreateUnit(m.unitname, tryx, tryy, tryz, 'N', teamnum - 1)                                         
     
    7878        local err, success 
    7979        local modOptions = Spring.GetModOptions() 
    80                  
     80         
    8181        if (modOptions) and modOptions.planetwars and modOptions.planetwars ~= '' then 
    8282                optionsRaw = modOptions.planetwars 
     
    9696        if err then Spring.Echo('Planet Wars error: ' .. err) end 
    9797        --options did not load, remove 
     98         
    9899        return false 
    99100end 
  • trunk/mods/ca/LuaRules/Gadgets/unit_morph.lua

    r3336 r3344  
    107107local morphDefs  = {} --// make it global in Initialize() 
    108108local extraUnitMorphDefs = {} -- stores mainly planetwars morphs 
     109local pwUnitOwners = {} -- stores owners of planetwars units 
    109110local hostName = nil -- planetwars hostname 
    110111local morphUnits = {} --// make it global in Initialize() 
     
    300301 
    301302 
    302 local function AddExtraUnitMorph(unitID, morphDef)  -- adds extra unit morph (planetwars morphing) 
     303local function AddExtraUnitMorph(unitID, morphDef, owner)  -- adds extra unit morph (planetwars morphing) 
    303304        local unitDefID = Spring.GetUnitDefID(unitID) 
    304305        local ud = UnitDefs[unitDefID] 
    305306        local teamID = Spring.GetUnitTeam(unitID) 
     307        pwUnitOwners[unitID] = owner 
    306308        morphDef = BuildMorphDef(ud, morphDef) 
    307309        extraUnitMorphDefs[unitID] = morphDef 
     
    394396 
    395397  local newUnit = Spring.CreateUnit(defName, px, py, pz, 0, unitTeam) 
     398 
     399  Spring.SetUnitPosition(newUnit, px, py, pz)   
    396400   
    397401  if (extraUnitMorphDefs[unitID] ~= nil and hostName ~= nil) then  -- send planetwars deployment message 
    398         local data = unitTeam..","..defName..","..math.floor(px)..","..math.floor(pz)..",".."S" -- todo determine and apply smart orientation of the structure 
     402        local data = (pwUnitOwners[unitID] or unitTeam)..","..defName..","..math.floor(px)..","..math.floor(pz)..",".."S" -- todo determine and apply smart orientation of the structure 
    399403        Spring.SendCommands("w "..hostName.." pwdeploy:"..data) 
    400404        extraUnitMorphDefs[unitID] = nil 
    401   end 
    402    
    403   Spring.SetUnitPosition(newUnit, px, py, pz) 
    404    
    405   local h = Spring.GetUnitHeading(unitID) 
    406   Spring.SetUnitRotation(newUnit, 0, -h * math.pi / 32768, 0) 
     405        pwUnitOwners[unitID] = nil 
     406  else  -- set rotation only if unit is not planetwars 
     407        local h = Spring.GetUnitHeading(unitID) 
     408        Spring.SetUnitRotation(newUnit, 0, -h * math.pi / 32768, 0) 
     409  end 
     410 
    407411 
    408412  --//copy experience