Guest User

Mithy

a guest
Nov 28th, 2010
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.26 KB | None | 0 0
  1. function ShouldSave(unit, upgrade)
  2.     local shouldSave = 0
  3.     local unitBrain = unit:GetAIBrain()
  4.     local goldTable = {Army = unit:GetArmy(), Gold = unitBrain.mGold}
  5.  
  6.     --Make sure we have the most gold of the AIs on our team
  7.     for k, brain in unit:GetAIBrain():GetAlliedArmies() do
  8.         if not brain.TeamBrain and not brain.BrainController == 'Human' then
  9.             table.insert(goldTable, {Army = brain.GetArmyIndex(), Gold = brain.mGold })
  10.         end
  11.     end
  12.     LOG("repr goldTable: "..repr(goldTable))
  13.     table.sort(goldTable, sort_down_by('Gold'))
  14.  
  15.     if goldTable[1].Army == unit:GetArmy() then
  16.         local currentUpgrade = false
  17.  
  18.         --Currency I (ignore after 10 minutes)
  19.         if unitBrain.Score.WarScore >= 100 and GetMinute() < 10 and not TeamHasUpgrade(unit, 'CGoldIncome01') then
  20.             currentUpgrade = 'CGoldIncome01'
  21.         --Catapults
  22.         elseif ( unitBrain.Score.WarRank >= 7 or GetEnemyTeamBrain(unit).Score.WarRank >= 8 ) and not TeamHasUpgrade(unit, 'CTroopNumber04') then
  23.             currentUpgrade = 'CTroopNumber04'
  24.         --Giants
  25.         elseif unitBrain.Score.WarRank >= 8 and not TeamHasUpgrade(unit, 'CTroopNumber06') then
  26.             currentUpgrade = 'CTroopNumber06'
  27.         end
  28.  
  29.         if currentUpgrade and currentUpgrade ~= upgrade then
  30.             shouldSave = UpgradeCost(currentUpgrade)
  31.         end
  32.     end
  33.  
  34.     return shouldSave
  35. end
Advertisement
Add Comment
Please, Sign In to add comment