Lepus?
Join Date: Jan 2009
Posts: 1,308
|
[Script, AI] Michael Peppers's Melee AI template
This is an .ai template that eases the burden of AI scripting. It has been used as a base for the Melee AIs in my project ( The Withering Kind) and in Kam's Beyond The Throne. (from version 3.9.4.2 to 3.9.4.4 at least, latest version's one is "streamlined" according to the release notes so I'm not sure it's the same)
.ai scripts are pure JASS. This script is aimed at JASS/vJass coders that want to script quick 'n' dirty Melee AIs or that want to learn how to script AIs.
Its features: (and also its non-features) - Most common racial tasks are either fully automatized or streamlined. Namely, the AI will:
- Build houses automatically.
- Tier up when a set amount of gold and wood is reached.
- Train workers automatically with a system that covers:
- An user defined number of them, divided in main base workers and expansion workers.
- Having different harvesters types for gold and wood. (max. 2)
- Build/research/train most buildings, upgrades and units without modifications to the BuildPriorities and UpgradePriorities as long as you've set the IDs correctly. (To make the AI work right, though, you'll still have to tweak those according to the race's needs)
- (added in v0.5) Can focus on either researching upgrades or tiering up, depending on FocusTiering's value.
- Most of the AI scripting now consists in setting constants at the beginning of the script. Most users will only have to set variables and tweak the two functions I named above to have a fully working, competitive AI.
- IDs aside, all constants are already set to values that should work fine with most races.
- The most common racial differences (like the UD harvesting mechanics, the fact Naga can swim etc.) are supported. As always, it's a matter of setting up a couple of variables.
- The AI can stop creating Basic Melee (Footmen) units when they're obsolete, saving food for better units, if you want to.
- (added in v0.5) Easy and Normal difficulties are handled just like standard AI does.
- (added in v0.5) New Attack function, it's more streamlined, almost identical to standard AI and... it buys Zeppelins! Woot! (disabled by default because it makes the AI do pretty reckless stuff at times, but other than that it's fine)
- The HallCount function.
 - If a variable that should store an ID is unused, set it to 0. No, the script won't crash and burn.
- The template script is (badly) commented.
- Uhhh.... AI scripts support 4 heroes.
Differences with Blizzard's Melee AI & bugs or other misc notes: - The AI will build houses quicker than the standard AI.
- Will Tier up (if not focusing on upgrades) and build armies faster.
- Will actually research upgrades (standard AI gets stuck on that at times
) - It will not buy Zeppelins as it is now, it does with SimpleAttack enabled, but it doesn't use them anyway, so...
- Hard and Insane difficulties for now consist in Expansion number differences. Nothing more. (might be on par with what Blizzard did actually. Maybe even better)
- It's able to rebuild and recover if it can.
- Building placement can be weird. There's nothing I can do about it, blame Blizzard. =P
 JASS:
globals
integer attackWave = 1
integer nextDelay = 0
constant integer Hall = ''
constant integer Mine = ''
constant integer HallTier2 = ''
constant integer HallTier3 = ''
constant integer GoldHarvester = ''
constant integer WoodHarvester = ''
constant integer House = ''
constant integer Altar = ''
constant integer Barracks = ''
constant integer Blacksmith = ''
constant integer LumberMill = ''
constant integer Shop = ''
constant integer CasterBarracks = ''
constant integer Tower = ''
constant integer SpecializedBarracks = ''
constant integer FlyingBarracks = ''
constant integer BasicMelee = ''
constant integer BasicRanged = ''
constant integer T2Melee = ''
constant integer MainCaster = ''
constant integer SupportCaster = ''
constant integer OwnageMelee = ''
constant integer AirAir = ''
constant integer AirGround = ''
constant integer SiegeRanged = ''
constant integer MiscUnit1 = ''
constant integer MiscUnit2 = ''
constant integer AttackUpgrade1 = ''
constant integer AttackUpgrade2 = ''
constant integer DefenseUpgrade1 = ''
constant integer DefenseUpgrade2 = ''
constant integer BasicMeleeUpgrade = ''
constant integer BasicRangedUpgrade = ''
constant integer MainCasterUpgrade = ''
constant integer SupportCasterUpgrade = ''
constant integer LumberHarvestUpgrade = ''
constant integer BuildingDefenseUpgrade = ''
constant integer MiscUpgrade1 = ''
constant integer MiscUpgrade2 = ''
constant integer MiscUpgrade3 = ''
constant integer MiscUpgrade4 = ''
constant integer MiscUpgrade5 = ''
constant integer MiscUpgrade6 = ''
constant integer MiscUpgrade7 = ''
constant integer MiscUpgrade8 = ''
constant integer MiscUpgrade9 = ''
constant integer MiscUpgrade10 = ''
constant integer MiscUpgrade11 = ''
constant integer MiscUpgrade12 = ''
constant integer Heroes = 4
constant integer H1 = ''
constant integer H2 = ''
constant integer H3 = ''
constant integer H4 = ''
constant integer H1A1 = ''
constant integer H1A2 = ''
constant integer H1A3 = ''
constant integer H1U = ''
constant integer H2A1 = ''
constant integer H2A2 = ''
constant integer H2A3 = ''
constant integer H2U = ''
constant integer H3A1 = ''
constant integer H3A2 = ''
constant integer H3A3 = ''
constant integer H3U = ''
constant integer H4A1 = ''
constant integer H4A2 = ''
constant integer H4A3 = ''
constant integer H4U = ''
constant integer Food4Attack = 80
constant integer Food4Exp = 42
constant integer GoldGuys1 = 5
constant integer WoodGuys1 = 5
constant integer GoldGuys2 = 0
constant integer WoodGuys2 = 0
constant integer HousesToBuild = 2
constant integer MaxFoodUsedByUnit = 5
constant integer MaxFood = 100
constant integer GoldForT2 = 600
constant integer WoodForT2 = 320
constant integer GoldForT3 = 800
constant integer WoodForT3 = 400
constant boolean WantName = true
constant boolean WantDifficultyInName = true
constant string Name = "Test"
constant boolean IsAmphibious = false
constant boolean SimpleAttack = false
constant boolean FocusTiering = true
constant boolean WannaKeepBasicMelee = false
constant integer KeepBasicMeleeFoodCap = 54
constant integer MinimumForceBasicMelee = 2
constant integer MinimumForceBasicRanged = 2
constant integer MinimumForceT2Melee = 2
constant integer MinimumForceOwnageMelee = 2
constant integer AIHasT2Melee = 52
constant integer AIHasOwnageMelee = 90
boolean twoharvs = false
boolean T2MeleeExists = true
integer MinesToOwn = 0
boolean HeroesYes = true
string array DifficultyName
boolean NeedHousing = false
boolean GoHall2 = false
boolean GoHall3 = false
boolean KeepBasicMelee = true
boolean CanAttack = false
endglobals
function HallCount takes integer unitid, boolean done returns integer
local integer have_qty
if (not done) then
set have_qty = GetUnitCount(unitid)
if unitid == Hall then
set have_qty = have_qty + GetUnitCount(HallTier2) + GetUnitCount(HallTier3)
elseif unitid == HallTier2 then
set have_qty = have_qty + GetUnitCount(HallTier3)
endif
else
set have_qty = GetUnitCountDone(unitid)
if unitid == Hall then
set have_qty = have_qty + GetUnitCountDone(HallTier2) + GetUnitCountDone(HallTier3)
elseif unitid == HallTier2 then
set have_qty = have_qty + GetUnitCountDone(HallTier3)
endif
endif
return have_qty
endfunction
function CheckLastCommand takes boolean pop returns integer
local integer cmd = GetLastCommand()
if (pop) then
call PopLastCommand()
endif
return cmd
endfunction
function CheckLastCommandData takes boolean pop returns integer
local integer data = GetLastData()
if (pop) then
call PopLastCommand()
endif
return data
endfunction
function BuildExpansion takes boolean build_it returns nothing
if build_it and HallsCompleted(Hall) then
call SetBuildExpa(HallCount(Hall, false) + 1, Hall)
endif
endfunction
function UpdateEcoConditions takes nothing returns nothing
if FoodCap() < MaxFood then
set NeedHousing = FoodCap() <= (FoodUsed() + MaxFoodUsedByUnit) and GetUnitCount(House) < (GetUnitCountDone(House) + HousesToBuild)
else
set NeedHousing = false
endif
set GoHall2 = HallCount(HallTier2, false) == 0 and GetGold() >= GoldForT2 and GetWood() >= WoodForT2
set GoHall3 = HallCount(HallTier2, true) > 0 and HallCount(HallTier3, false) == 0 and GetGold() >= GoldForT3 and GetWood() >= WoodForT3
endfunction
function UpdateMilConditions takes nothing returns nothing
if (not WannaKeepBasicMelee) then
set KeepBasicMelee = (FoodCap() < KeepBasicMeleeFoodCap)
endif
if T2MeleeExists then
set CanAttack = (GetUnitCountDone(BasicMelee) >= MinimumForceBasicMelee or GetUnitCountDone(T2Melee) >= MinimumForceT2Melee) and GetUnitCountDone(BasicRanged) >= MinimumForceBasicRanged
else
set CanAttack = (GetUnitCountDone(BasicMelee) >= MinimumForceBasicMelee or GetUnitCountDone(OwnageMelee) >= MinimumForceOwnageMelee) and GetUnitCountDone(BasicRanged) >= MinimumForceBasicRanged
endif
endfunction
function SetSkills takes nothing returns nothing
set skill[ 1] = H1A1
set skill[ 2] = H1A2
set skill[ 3] = H1A3
set skill[ 4] = H1A1
set skill[ 5] = H1A2
set skill[ 6] = H1U
set skill[ 7] = H1A3
set skill[ 8] = H1A1
set skill[ 9] = H1A2
set skill[10] = H1A3
if hero_id == H1 then
call SetSkillArray(1, H1)
elseif hero_id2 == H1 then
call SetSkillArray(2, H1)
elseif hero_id3 == H1 then
call SetSkillArray(3, H1)
endif
if Heroes > 1 then
set skill[ 1] = H2A1
set skill[ 2] = H2A2
set skill[ 3] = H2A3
set skill[ 4] = H2A1
set skill[ 5] = H2A2
set skill[ 6] = H2U
set skill[ 7] = H2A3
set skill[ 8] = H2A1
set skill[ 9] = H2A2
set skill[10] = H2A3
if hero_id == H2 then
call SetSkillArray(1, H2)
elseif hero_id2 == H2 then
call SetSkillArray(2, H2)
elseif hero_id3 == H2 then
call SetSkillArray(3, H2)
endif
endif
if Heroes > 2 then
set skill[ 1] = H3A1
set skill[ 2] = H3A2
set skill[ 3] = H3A3
set skill[ 4] = H3A1
set skill[ 5] = H3A2
set skill[ 6] = H3U
set skill[ 7] = H3A3
set skill[ 8] = H3A1
set skill[ 9] = H3A2
set skill[10] = H3A3
if hero_id == H3 then
call SetSkillArray(1, H3)
elseif hero_id2 == H3 then
call SetSkillArray(2, H3)
elseif hero_id3 == H3 then
call SetSkillArray(3, H3)
endif
endif
if Heroes > 3 then
set skill[ 1] = H4A1
set skill[ 2] = H4A2
set skill[ 3] = H4A3
set skill[ 4] = H4A1
set skill[ 5] = H4A2
set skill[ 6] = H4U
set skill[ 7] = H4A3
set skill[ 8] = H4A1
set skill[ 9] = H4A2
set skill[10] = H4A3
if hero_id == H4 then
call SetSkillArray(1, H4)
elseif hero_id2 == H4 then
call SetSkillArray(2, H4)
elseif hero_id3 == H4 then
call SetSkillArray(3, H4)
endif
endif
endfunction
function PickRacialHero takes nothing returns nothing
local integer first
local integer second
local integer third
local integer last
local integer array heroes
set heroes[1] = H1
set heroes[2] = H2
set heroes[3] = H3
set heroes[4] = H4
if Heroes > 3 then
if VersionCompatible(VERSION_FROZEN_THRONE) then
set last = 4
else
set last = 3
endif
else
set last = Heroes
endif
if last >= 1 then
set first = GetRandomInt(1,last)
if last >= 2 then
set second = GetRandomInt(1,last-1)
if last >= 3 then
set third = GetRandomInt(1,last-2)
else
set third = 3
endif
else
set second = 2
endif
endif
set hero_id = heroes[first]
set heroes[first] = heroes[last]
set hero_id2 = heroes[second]
set heroes[second] = heroes[last-1]
set hero_id3 = heroes[third]
endfunction
function BuildPriorities takes nothing returns nothing
local integer mine = TownWithMine()
call InitBuildArray()
call MeleeTownHall(0, Hall)
call MeleeTownHall(1, Hall)
if Hall != Mine and GetGold() < 1500 then
call SecondaryTown(mine, 1, Mine)
endif
call SetBuildUnit(GoldGuys1, GoldHarvester)
if GoHall2 then
call SetBuildUnit(1, HallTier2)
elseif GoHall3 then
call SetBuildUnit(1, HallTier3)
endif
if NeedHousing then
call SetBuildUnit(GetUnitCount(House) + 1, House)
endif
if twoharvs then
call SetBuildUnit(WoodGuys1 - 1, WoodHarvester)
else
call SetBuildUnit(GoldGuys1 + (WoodGuys1 - 1), WoodHarvester)
endif
call SetBuildUnit(1, Altar)
call SetBuildUnit(1, Barracks)
if twoharvs then
call SetBuildUnit(WoodGuys1, WoodHarvester)
else
call SetBuildUnit(GoldGuys1 + WoodGuys1, WoodHarvester)
endif
call SetBuildUnit(1, hero_id)
if KeepBasicMelee then
call SetBuildUnit(3, BasicMelee)
endif
call SetBuildUnit(1, Blacksmith)
call SetBuildUnit(2, BasicRanged)
if Blacksmith != LumberMill then
call SetBuildUnit(1, LumberMill)
endif
call SetBuildUnit(3, BasicRanged)
if KeepBasicMelee then
call SetBuildUnit(5, BasicMelee)
endif
if Shop != 0 then
call SetBuildUnit(1, Shop)
endif
call SetBuildUnit(5, BasicRanged)
call BuildExpansion(GetMinesOwned() < MinesToOwn)
if WoodGuys2 > 0 then
if twoharvs then
call SetBuildUnit(WoodGuys1 + WoodGuys2, WoodHarvester)
else
call SetBuildUnit(GoldGuys1 + WoodGuys1 + WoodGuys2, WoodHarvester)
endif
endif
call SecondaryTown(mine, 1, Tower)
call SetBuildUnit(1, CasterBarracks)
if HeroesYes and Heroes > 1 then
call SetBuildUnit(1, hero_id2)
else
if KeepBasicMelee then
call SetBuildUnit(6, BasicMelee)
else
call SetBuildUnit(1, BasicMelee)
endif
call SetBuildUnit(6, BasicRanged)
endif
call SecondaryTown(mine, 2, Tower)
if T2MeleeExists then
call SetBuildUnit(3, T2Melee)
endif
if T2MeleeExists then
call SetBuildUnit(4, T2Melee)
if (not KeepBasicMelee) then
call SetBuildUnit(6, T2Melee)
endif
endif
call SetBuildUnit(1, SupportCaster)
call SecondaryTown(mine, 3, Tower)
call SetBuildUnit(1, MainCaster)
call SetBuildUnit(1, SpecializedBarracks)
if GoldGuys2 > 0 then
if twoharvs then
call SetBuildUnit(GoldGuys1 + GoldGuys2, GoldHarvester)
else
if WoodGuys2 > 0 then
call SetBuildUnit(GoldGuys1 + GoldGuys2 + WoodGuys1 + WoodGuys2, GoldHarvester)
else
call SetBuildUnit(GoldGuys1 + GoldGuys2 + WoodGuys1, GoldHarvester)
endif
endif
endif
call SetBuildUnit(2, SiegeRanged)
call SetBuildUnit(5, OwnageMelee)
if (not KeepBasicMelee) then
call SetBuildUnit(6, OwnageMelee)
endif
if HeroesYes and Heroes > 2 then
call SetBuildUnit(1, hero_id3)
if (not KeepBasicMelee) then
call SetBuildUnit(7, OwnageMelee)
else
call SetBuildUnit(6, OwnageMelee)
endif
endif
call SetBuildUnit(1, FlyingBarracks)
call SetBuildUnit(3, AirGround)
call SetBuildUnit(3, AirAir)
endfunction
function UpgradePriorities takes nothing returns nothing
local boolean CanDoUpgrades
if FocusTiering then
if (HallCount(HallTier2, false) == 0 and (GetGold() < GoldForT2 or GetWood() < WoodForT2)) or (HallCount(HallTier3, false) == 0 and FoodCap() >= AIHasT2Melee and (GetGold() < GoldForT3 or GetWood() < WoodForT3)) then
set CanDoUpgrades = false
else
set CanDoUpgrades = true
endif
else
set CanDoUpgrades = true
endif
if GetMinesOwned() == 0 and (GetUnitGoldCost(Hall) + 100 >= GetGold() or GetUnitWoodCost(Hall) + 100 >= GetWood()) then
set CanDoUpgrades = false
endif
if CanDoUpgrades then
if GetUnitCountDone(Blacksmith) > 0 then
call StartUpgrade(1, AttackUpgrade1)
call StartUpgrade(1, AttackUpgrade2)
call StartUpgrade(1, DefenseUpgrade1)
call StartUpgrade(1, DefenseUpgrade2)
if HallCount(HallTier2, true) > 0 then
call StartUpgrade(2, AttackUpgrade1)
call StartUpgrade(2, AttackUpgrade2)
call StartUpgrade(2, DefenseUpgrade1)
call StartUpgrade(2, DefenseUpgrade2)
endif
if HallCount(HallTier3, true) > 0 then
call StartUpgrade(3, AttackUpgrade1)
call StartUpgrade(3, AttackUpgrade2)
call StartUpgrade(3, DefenseUpgrade1)
call StartUpgrade(3, DefenseUpgrade2)
endif
endif
if GetUnitCountDone(LumberMill) > 0 then
if HallCount(HallTier3, true) > 0 then
call StartUpgrade(2, LumberHarvestUpgrade)
if GetUnitCountDone(Blacksmith) > 0 then
call StartUpgrade(3, BuildingDefenseUpgrade)
endif
elseif HallCount(HallTier2, true) > 0 then
call StartUpgrade(1, LumberHarvestUpgrade)
if GetUnitCountDone(Blacksmith) > 0 then
call StartUpgrade(2, BuildingDefenseUpgrade)
endif
else
call StartUpgrade(1, BuildingDefenseUpgrade)
endif
endif
if GetUnitCountDone(Barracks) > 0 then
if GetUnitCountDone(BasicMelee) > 2 then
call StartUpgrade(1, BasicMeleeUpgrade)
endif
if HallCount(HallTier2, true) > 0 and GetUnitCountDone(BasicRanged) > 2 and GetUnitCountDone(Blacksmith) > 0 then
call StartUpgrade(1, BasicRangedUpgrade)
endif
if HallCount(HallTier3, true) > 0 and GetUnitCountDone(OwnageMelee) > 2 and GetUnitCountDone(Blacksmith) > 0 and GetUnitCountDone(CasterBarracks) > 0 then
call StartUpgrade(1, MiscUpgrade3)
endif
endif
if GetUnitCountDone(CasterBarracks) > 0 then
if HallCount(HallTier3, true) > 0 then
if GetUnitCountDone(MainCaster) > 0 then
call StartUpgrade(2, MainCasterUpgrade)
endif
if GetUnitCountDone(SupportCaster) > 0 then
call StartUpgrade(2, SupportCasterUpgrade)
endif
if GetUnitCountDone(Shop) > 0 and GetUnitCountDone(T2Melee) > 2 then
call StartUpgrade(1, MiscUpgrade2)
endif
else
if GetUnitCountDone(MainCaster) > 0 then
call StartUpgrade(1, MainCasterUpgrade)
endif
if GetUnitCountDone(SupportCaster) > 0 then
call StartUpgrade(1, SupportCasterUpgrade)
endif
endif
if GetUnitCountDone(T2Melee) > 2 then
call StartUpgrade(1, MiscUpgrade1)
endif
endif
if GetUnitCountDone(FlyingBarracks) > 0 then
if HallCount(HallTier3, true) > 0 then
if GetUnitCountDone(CasterBarracks) > 0 then
if GetUnitCountDone(Blacksmith) > 0 and GetUnitCountDone(AirGround) > 0 then
call StartUpgrade(1, MiscUpgrade5)
endif
if GetUnitCountDone(Shop) > 0 then
if GetUnitCountDone(AirAir) > 0 then
call StartUpgrade(1, MiscUpgrade4)
endif
if GetUnitCountDone(AirGround) > 0 then
call StartUpgrade(1, MiscUpgrade6)
endif
endif
endif
endif
endif
if GetUnitCountDone(SpecializedBarracks) > 0 then
if HallCount(HallTier3, true) > 0 then
if GetUnitCountDone(Blacksmith) > 0 and GetUnitCountDone(SiegeRanged) > 0 then
call StartUpgrade(1, MiscUpgrade7)
endif
if GetUnitCountDone(CasterBarracks) > 0 and GetUnitCountDone(MiscUnit1) > 0 then
call StartUpgrade(1, MiscUpgrade9)
endif
if GetUnitCountDone(Shop) > 0 and GetUnitCountDone(MiscUnit2) > 0 then
call StartUpgrade(1, MiscUpgrade10)
endif
endif
endif
if HallCount(Hall, true) > 0 then
if HallCount(HallTier2, true) > 0 and GetUnitCountDone(Shop) > 0 then
call StartUpgrade(1, MiscUpgrade8)
endif
if GetUnitCountDone(Shop) > 0 then
call StartUpgrade(1, MiscUpgrade11)
endif
endif
endif
endfunction
function GuysAtWork takes nothing returns nothing
local integer mine
loop
call UpdateEcoConditions()
call ClearHarvestAI()
set mine = TownWithMine()
call HarvestGold(mine, GoldGuys1)
call HarvestWood(0, WoodGuys1)
if GoldGuys2 != 0 then
if GetMinesOwned() >= 2 and HallCount(Hall, true) >= 2 then
call HarvestGold(mine + 1, GoldGuys2)
elseif not twoharvs then
call HarvestWood(0, GoldGuys2)
endif
endif
if WoodGuys2 != 0 then
call HarvestWood(0, WoodGuys2)
endif
call BuildPriorities()
call UpgradePriorities()
call Sleep(2)
endloop
endfunction
function HaveMinimumAttackers takes nothing returns boolean
if (attackWave > 2) then
return false
endif
return CanAttack
endfunction
function PrepareAttackGroup takes integer groupID returns nothing
if (groupID == 1) then
call SetAssaultGroup(GetUnitCountDone(hero_id), -1, hero_id)
call SetAssaultGroup(GetUnitCountDone(BasicRanged), -1, BasicRanged)
call SetAssaultGroup(GetUnitCountDone(BasicMelee), -1, BasicMelee)
if (FoodCap() >= AIHasOwnageMelee) then
call SetAssaultGroup(MinimumForceOwnageMelee, MinimumForceOwnageMelee, OwnageMelee)
endif
if (FoodCap() >= AIHasT2Melee) and T2MeleeExists then
call SetAssaultGroup(MinimumForceT2Melee, MinimumForceT2Melee, T2Melee)
endif
elseif (groupID == 2) then
call SetAssaultGroup(GetUnitCountDone(hero_id), -1, hero_id)
if Heroes > 1 then
call SetAssaultGroup(GetUnitCountDone(hero_id2), -1, hero_id2)
if Heroes > 2 then
call SetAssaultGroup(GetUnitCountDone(hero_id3), -1, hero_id3)
endif
endif
call SetAssaultGroup(GetUnitCountDone(BasicRanged), -1, BasicRanged)
call SetAssaultGroup(GetUnitCountDone(BasicMelee), -1, BasicMelee)
call SetAssaultGroup(GetUnitCountDone(OwnageMelee), -1, OwnageMelee)
call SetAssaultGroup(GetUnitCountDone(SupportCaster), -1, SupportCaster)
call SetAssaultGroup(GetUnitCountDone(MainCaster), -1, MainCaster)
if T2MeleeExists then
call SetAssaultGroup(GetUnitCountDone(T2Melee), -1, T2Melee)
endif
call SetAssaultGroup(GetUnitCountDone(AirGround), -1, AirGround)
call SetAssaultGroup(GetUnitCountDone(AirAir), -1, AirAir)
call SetAssaultGroup(GetUnitCountDone(SiegeRanged), -1, SiegeRanged)
call SetAssaultGroup(GetUnitCountDone(MiscUnit1), -1, MiscUnit1)
call SetAssaultGroup(GetUnitCountDone(MiscUnit2), -1, MiscUnit2)
endif
endfunction
function PrepareForces takes nothing returns nothing
if (attackWave == 1) then
call PrepareAttackGroup(1)
elseif (attackWave == 2) then
call PrepareAttackGroup(2)
endif
endfunction
function AttackWaveDelay takes integer inWave returns nothing
if (inWave < nextDelay) then
return
endif
if (inWave == 1) then
call Sleep(2)
endif
set nextDelay = inWave + 1
endfunction
function AttackWaveUpdate takes nothing returns nothing
call AttackWaveDelay(attackWave)
set attackWave = attackWave + 1
if (attackWave > 2) then
set attackWave = 2
set nextDelay = attackWave + 1
endif
endfunction
function AttackTarget takes unit target, boolean addAlliance returns nothing
if (target == null) then
return
endif
if (addAlliance) then
call SetAllianceTarget(target)
endif
call FormGroup(3, true)
call AttackMoveKillA(target)
if (not addAlliance) then
call SetAllianceTarget(null)
endif
endfunction
function LaunchAttack takes nothing returns nothing
local unit target = null
local boolean setAlly = true
if (TownThreatened()) then
call Sleep(2)
return
endif
if (target == null) then
set target = GetAllianceTarget()
if (target != null) then
set setAlly = false
endif
endif
if FoodUsed() >= Food4Exp then
if (target == null) then
set target = GetExpansionFoe()
endif
endif
if FoodUsed() >= Food4Attack then
if (target == null) then
set target = GetMegaTarget()
endif
if (target == null) then
set target = GetEnemyExpansion()
if (target == null) then
call StartGetEnemyBase()
loop
exitwhen (not WaitGetEnemyBase())
call SuicideSleep(1)
endloop
set target = GetEnemyBase()
endif
endif
endif
if FoodUsed() < Food4Attack then
if target == null then
set target = GetCreepCamp(0, 9, false)
endif
endif
if FoodUsed() >= Food4Attack then
if (target == null) then
set target = GetCreepCamp(10, 100, true)
endif
endif
if (target != null) then
call AttackTarget(target, setAlly)
call AttackWaveUpdate()
else
call Sleep(20)
endif
endfunction
function LaunchAttackSimple takes nothing returns nothing
local boolean exp
local boolean siege
local boolean major
local boolean air
set exp = take_exp and FoodUsed() >= Food4Exp
set siege = GetUnitCountDone(SiegeRanged) > 0 and FoodUsed() >= Food4Attack
set major = FoodUsed() >= Food4Attack
set air = GetUnitCountDone(AirGround) > 0 or GetUnitCountDone(AirAir) > 0
call SingleMeleeAttack(exp,siege,major,air)
call AttackWaveUpdate()
endfunction
function AttackAssignment takes nothing returns nothing
local integer n = 0
call StaggerSleep(0, 2)
if (attackWave == 1) then
call AttackWaveDelay(0)
endif
loop
call UpdateMilConditions()
if (HaveMinimumAttackers() and not CaptainRetreating()) then
if n == 2 then
call Sleep(2)
set n = 0
else
set n = n + 1
call InitAssaultGroup()
call PrepareForces()
call RemoveInjuries()
if SimpleAttack then
call LaunchAttackSimple()
else
call LaunchAttack()
endif
endif
else
call Sleep(2)
endif
endloop
endfunction
function main takes nothing returns nothing
set ai_player = Player(GetAiPlayer())
set DifficultyName[1] = "(Easy)"
set DifficultyName[2] = "(Normal)"
set DifficultyName[3] = "(Hard)"
set DifficultyName[4] = "(Insane)"
set MinesToOwn = 1 + MeleeDifficulty()
set HeroesYes = not isNewbie
if GoldHarvester != WoodHarvester then
set twoharvs = true
endif
if T2Melee == 0 then
set T2MeleeExists = false
endif
if WantName then
if WantDifficultyInName then
call SetPlayerName(ai_player, Name + " " + DifficultyName[MeleeDifficulty()])
else
call SetPlayerName(ai_player, Name)
endif
endif
call PickRacialHero()
call SetSkills()
call StandardAI(function SkillArrays, function GuysAtWork, function AttackAssignment)
if IsAmphibious then
call SetAmphibious()
endif
call PlayGame()
endfunction
Last edited by Michael Peppers : 12-07-2018 at 08:04 PM.
|