-------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -- -- file: gui_ReclaimInfo.lua -- brief: Shows the amount of metal/energy when using area reclaim. -- original author: Janis Lukss -- -- Copyright (C) 2007. -- Licensed under the terms of the GNU GPL, v2 or later. -- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- function widget:GetInfo() return { name = "CloseFight", desc = "When making a group fight the specified radar and jammer units in it will follow others", author = "Pendrokar", date = "Nov 17, 2007", license = "GNU GPL, v2 or later", layer = 0, enabled = enable -- loaded by default? } end -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- local radarunitSet = {} local jammerunitSet = {} local unitArray = {} unitArray["radarunitArray"] = { --radar units -----BA----- "armseer", "armmark", "corvrad", "corvoyr",} unitArray["jammerunitArray"] = { --jammer units -----BA----- "armaser", "coreter", "arm_jammer", "core_spectre", "armsjam", "corsjam",} -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- function widget:Initialize() if Spring.GetSpectatingState() or Spring.IsReplay() then widgetHandler:RemoveWidget() return true end for i, v in pairs(unitArray["radarunitArray"]) do radarunitSet[v] = true end for i, v in pairs(unitArray["jammerunitArray"]) do jammerunitSet[v] = true end end function widget:CommandNotify(commandID, params, options) local selUnits = Spring.GetSelectedUnits() local count = #selUnits table.foreachi(options,Spring.Echo) if (count>1) and (commandID == CMD.FIGHT) then local radarunittable = {} local jammerunittable = {} local offensiveunittable = {} local countradars = 0 local countjammers = 0 local countoffensive = 0 for k,unitID in pairs(selUnits) do local udef = Spring.GetUnitDefID(unitID) local ud = UnitDefs[udef] if (ud ~=nil) and (radarunitSet[ud.name]) then --radar unit countradars = countradars + 1 radarunittable[countradars] = unitID elseif (ud ~=nil) and (jammerunitSet[ud.name]) then --jammer unit countjammers = countjammers + 1 jammerunittable[countjammers] = unitID elseif (ud ~= nil) then --other unit local wd = ud.weapons[1] if (wd ~= nil) then local weaponDefID = wd.weaponDef if (weaponDefID ~= nil) then --offensive unit if (WeaponDefs[weaponDefID].range ~= nil) then table.insert(offensiveunittable,{ unitID, WeaponDefs[weaponDefID].range }) end countoffensive = countoffensive + 1 end end end end if((countradars ~= 0) or (countjammers ~= 0)) and (countoffensive ~= 0) then local aradar = 1 local ajammer = 1 table.sort(offensiveunittable, compRanges) --reversed sorting for i in ipairs(offensiveunittable) do unitID = offensiveunittable[i][1] range = offensiveunittable[i][2] if(aradar b[2] end