Skip to content

Commit

Permalink
ezmorph picks at random
Browse files Browse the repository at this point in the history
requested by damgam
  • Loading branch information
sprunk committed Jan 24, 2019
1 parent c41c8ec commit c537def
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions LuaRules/Gadgets/unit_morph.lua
Expand Up @@ -1069,13 +1069,19 @@ local function handleEzMorph(unitID, unitDefID, teamID, targetDefID)
if not morphSet then
return true, true
end

local validMorphs = {}
for morphCmd, morphDef in pairs(morphSet) do
if (not targetDefID or morphDef.into == targetDefID)
and MorphRequirementsFulfilled(unitID, morphDef, teamTechLevel[teamID] or 0, TechReqList(teamID, morphDef.require)) then
StartMorph(unitID, unitDefID, teamID, morphDef)
break
validMorphs[#validMorphs+1] = morphDef
end
end

if #validMorphs > 0 then
StartMorph(unitID, unitDefID, teamID, validMorphs[math.random(1, #validMorphs)])
end

return true, true
end

Expand Down

0 comments on commit c537def

Please sign in to comment.