mikeyy

AIAbilityUtilities.lua v2

Jun 19th, 2011
132
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Shared function for determining when a general is at max summon count
  2. function ShouldSummon(unit, action)
  3.     local abilityBP = Ability[action.Ability]
  4.     local maxSummons, summonCat = false, false
  5.     if abilityBP then
  6.         if abilityBP.MaxYeti then
  7.             maxSummons = abilityBP.MaxYeti
  8.             summonCat = categories.YETI
  9.             LOG("ShouldSummon: MaxYeti: "..maxSummons)
  10.         elseif abilityBP.MaxShamblers then
  11.             maxSummons = abilityBP.MaxShamblers
  12.             summonCat = categories.ENT
  13.             LOG("ShouldSummon: MaxShamblers: "..maxSummons)
  14.         elseif abilityBP.MaxBalls then
  15.             maxSummons = abilityBP.MaxBalls
  16.             summonCat = categories.BALLLIGHTNING
  17.             LOG("ShouldSummon: MaxBalls: "..maxSummons)
  18.         end
  19.     else
  20.         LOG("ShouldSummon: Error: Could not get ability BP for ability '"..repr(action.Ability).."', bypassing")
  21.         return true
  22.     end
  23.     if maxSummons and summonCat then
  24.         if table.getn(unit:GetAIBrain():GetListOfUnits(summonCat, false)) < maxSummons then
  25.             return true
  26.         else
  27.             LOG("ShouldSummon: Already at max, abort action")
  28.         end
  29.     else
  30.         LOG("ShouldSummon: Error: Could not find max summons for ability '"..action.Ability.."', bypassing")
  31.         return true
  32.     end
  33.     return false
  34. end
  35.  
  36. --InstantStatusFunction for general summons
  37. function SummonStatusFunction(unit, action)
  38.     LOG("SummonStatusFunction "..repr(unit:GetAIBrain().Nickname).."/"..repr(unit:GetUnitId()))
  39.     if DefaultStatusFunction(unit, action) and ShouldSummon(unit, action) then
  40.         return true
  41.     end
  42.     return false
  43. end
  44.  
  45. --ActionFunction for general summons
  46. function SummonActionFunction(unit, action)
  47.     LOG("SummonActionFunction: "..repr(unit:GetAIBrain().Nickname).."/"..repr(unit:GetUnitId()))
  48.     local actionBp = HeroAIActionTemplates[action.ActionName]
  49.     local abilities = actionBp.Abilities
  50.     local ready = GetReadyAbility( unit, abilities )
  51.     if ready and ShouldSummon(unit, action) then
  52.         local timeout = actionBp.InstantTimeout or 7
  53.         return UseInstantAbility( unit, ready, timeout )
  54.     end
  55.     return false
  56. end
RAW Paste Data