Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ShouldSave(unit, upgrade)
- local shouldSave = 0
- local unitBrain = unit:GetAIBrain()
- local goldTable = {Army = unit:GetArmy(), Gold = unitBrain.mGold}
- --Make sure we have the most gold of the AIs on our team
- for k, brain in unit:GetAIBrain():GetAlliedArmies() do
- if not brain.TeamBrain and not brain.BrainController == 'Human' then
- table.insert(goldTable, {Army = brain.GetArmyIndex(), Gold = brain.mGold })
- end
- end
- LOG("repr goldTable: "..repr(goldTable))
- table.sort(goldTable, sort_down_by('Gold'))
- if goldTable[1].Army == unit:GetArmy() then
- local currentUpgrade = false
- --Currency I (ignore after 10 minutes)
- if unitBrain.Score.WarScore >= 100 and GetMinute() < 10 and not TeamHasUpgrade(unit, 'CGoldIncome01') then
- currentUpgrade = 'CGoldIncome01'
- --Catapults
- elseif ( unitBrain.Score.WarRank >= 7 or GetEnemyTeamBrain(unit).Score.WarRank >= 8 ) and not TeamHasUpgrade(unit, 'CTroopNumber04') then
- currentUpgrade = 'CTroopNumber04'
- --Giants
- elseif unitBrain.Score.WarRank >= 8 and not TeamHasUpgrade(unit, 'CTroopNumber06') then
- currentUpgrade = 'CTroopNumber06'
- end
- if currentUpgrade and currentUpgrade ~= upgrade then
- shouldSave = UpgradeCost(currentUpgrade)
- end
- end
- return shouldSave
- end
Advertisement
Add Comment
Please, Sign In to add comment