From 141b94c43bcdcd00904a9d72011a46055d69aa89 Mon Sep 17 00:00:00 2001 From: SMUnlimited Date: Sun, 5 Nov 2023 14:13:13 +0000 Subject: [PATCH] Bring in reviewed changes of pr181 --- Jobs/ANCIENT_EXPANSION.eai | 41 +++--- Jobs/ANCIENT_EXPANSION_CHECK.eai | 15 +- Jobs/BUY_ITEM.eai | 2 + Jobs/BUY_NEUTRAL.eai | 94 ++++++------ Jobs/BUY_NEUTRAL_HERO.eai | 85 +++++------ Jobs/DETECT_DEFEAT.eai | 31 ++-- Jobs/FAST_BUILD.eai | 2 + Jobs/FOCUSFIRE_CONTROL.eai | 71 +++++---- Jobs/HARASS.eai | 8 +- Jobs/ITEM_EXPANSION.eai | 2 +- Jobs/MICRO_UNITS.eai | 8 +- Jobs/MILITIA_CHECK.eai | 9 +- Jobs/MILITIA_EXPAND.eai | 84 ++++++----- Jobs/SEND_HOME.eai | 4 +- Jobs/ZEPPELIN_FOLLOW.eai | 2 +- common.eai | 239 ++++++++++++++++--------------- races.eai | 1 - 17 files changed, 369 insertions(+), 329 deletions(-) diff --git a/Jobs/ANCIENT_EXPANSION.eai b/Jobs/ANCIENT_EXPANSION.eai index d92519ce1..443e945b8 100644 --- a/Jobs/ANCIENT_EXPANSION.eai +++ b/Jobs/ANCIENT_EXPANSION.eai @@ -14,7 +14,7 @@ function SearchTree takes nothing returns nothing local integer i = 2 loop exitwhen i > 3 or ancient_exp_unit != null - set ancient_exp_unit = GetOneOfId(ai_player, old_id[racial_hall[i]]) + set ancient_exp_unit = GetOneOfId(ancient_exp_unit, ai_player, old_id[racial_hall[i]]) set i = i + 1 endloop endfunction @@ -45,7 +45,7 @@ if (ancient_exp_unit != null and GetUnitState(ancient_exp_unit, UNIT_STATE_LIFE) endif set exp_time_count = ai_time set not_taken_expansion = current_expansion -set u = GetExpFoe() +set u = GetExpFoe(u) if ancient_exp_state == 0 then //if current_expansion == null then //call TQAddJob(5, ANCIENT_EXPANSION, 0) @@ -124,7 +124,7 @@ elseif ancient_exp_state == 1 then else set ancient_exp_unit = GetOneOfIdNearLoc(ancient_exp_unit, ai_player, old_id[racial_expansion], ancient_exp_loc, 400) if ancient_exp_unit == null and TownCount(race_manual_loading_mine) == 0 then // no mine , check all hall - set ancient_exp_unit = GetOneOfId(ai_player, old_id[racial_expansion]) + set ancient_exp_unit = GetOneOfId(ancient_exp_unit, ai_player, old_id[racial_expansion]) if ancient_exp_unit == null then call SearchTree() endif @@ -145,25 +145,21 @@ elseif ancient_exp_state == 1 then call TQAddJob(1, ANCIENT_EXPANSION, 0) endif elseif ancient_exp_state == 2 then - if GetUnitMoveSpeed(ancient_exp_unit) == 0 then - call CreateDebugTag("Expansion State 2: Uproot Tree", 10, ancient_exp_unit, 3.00, 1.50) - call IssueImmediateOrderById(ancient_exp_unit, OrderIdCancel) - call IssueImmediateOrder(ancient_exp_unit, "unroot") - else - - if hero_built[1] then - set ancient_exp_state = 3 - //call RemoveGuardPosition(hero_unit[1]) - //call IssuePointOrder(hero_unit[1], "move", GetUnitX(ancient_exp_unit), GetUnitY(ancient_exp_unit)) - //call GroupClear(ancient_exp_group) - //call GroupEnumUnitsOfPlayer(ancient_exp_group, ai_player, null) - //set ancient_exp_group = SelectByAlive(ancient_exp_group, true) - //set ancient_exp_group = SelectUnittype(ancient_exp_group, UNIT_TYPE_STRUCTURE, false) - //set ancient_exp_group = SelectUnittype(ancient_exp_group, UNIT_TYPE_PEON, false) - //set ancient_exp_group = SelectByUnitStandard(ancient_exp_group, true) - //call GroupRemoveGuardPositionInstant(ancient_exp_group) - //call GroupPointOrder(ancient_exp_group, "smart", GetUnitX(ancient_exp_unit), GetUnitY(ancient_exp_unit)) - endif + call CreateDebugTag("Expansion State 2: Uproot Tree", 10, ancient_exp_unit, 3.00, 1.50) + call IssueImmediateOrderById(ancient_exp_unit, OrderIdCancel) + call IssueImmediateOrder(ancient_exp_unit, "unroot") + if hero_built[1] then + set ancient_exp_state = 3 + //call RemoveGuardPosition(hero_unit[1]) + //call IssuePointOrder(hero_unit[1], "move", GetUnitX(ancient_exp_unit), GetUnitY(ancient_exp_unit)) + //call GroupClear(ancient_exp_group) + //call GroupEnumUnitsOfPlayer(ancient_exp_group, ai_player, null) + //set ancient_exp_group = SelectByAlive(ancient_exp_group, true) + //set ancient_exp_group = SelectUnittype(ancient_exp_group, UNIT_TYPE_STRUCTURE, false) + //set ancient_exp_group = SelectUnittype(ancient_exp_group, UNIT_TYPE_PEON, false) + //set ancient_exp_group = SelectByUnitStandard(ancient_exp_group, true) + //call GroupRemoveGuardPositionInstant(ancient_exp_group) + //call GroupPointOrder(ancient_exp_group, "smart", GetUnitX(ancient_exp_unit), GetUnitY(ancient_exp_unit)) endif call TQAddJob(3, ANCIENT_EXPANSION, 0) elseif ancient_exp_state == 3 then @@ -181,6 +177,7 @@ elseif ancient_exp_state == 3 then set ancient_exp_group = SelectByUnitStandard(ancient_exp_group, true) if not isstrong then call GroupAddUnit(ancient_exp_group, ancient_exp_unit) + call IssueTargetOrder(ancient_exp_unit, "move", current_expansion) endif ////call GroupAddTypeAndRemoveGuard(ancient_exp_group, race_ancient_expansion_help_id, ai_player) //call GroupPointOrder(ancient_exp_group, "smart", GetUnitX(u), GetUnitY(u)) diff --git a/Jobs/ANCIENT_EXPANSION_CHECK.eai b/Jobs/ANCIENT_EXPANSION_CHECK.eai index d8b8fab25..b52469374 100644 --- a/Jobs/ANCIENT_EXPANSION_CHECK.eai +++ b/Jobs/ANCIENT_EXPANSION_CHECK.eai @@ -9,29 +9,34 @@ // ################################################################## function AncientExpansionCheck takes nothing returns nothing - call DisplayToAllJobDebug("ANCIENT_EXPANSION_CHECK JOB START") + local unit u = null + call DisplayToAllJobDebug("ANCIENT_EXPANSION_CHECK JOB START") if not ancient_expanding then // call DisplayToAll("Ancient Expansion Check") // if ai_time > 60 then // 5 mins // call DisplayToAll("Past time to expand with ancient") // set ancient_expanding = false -// if GetExpansionStrength() < race_ancient_expansion_strength and GetExpFoe() != null and (hero[1] == race_ancient_expansion_hero1 or hero[1] == race_ancient_expansion_hero2) then +// if GetExpansionStrength() < race_ancient_expansion_strength and u != null and (hero[1] == race_ancient_expansion_hero1 or hero[1] == race_ancient_expansion_hero2) then if current_expansion != null then + set u = GetExpFoe(u) call Trace("expansion free") - if GetExpansionStrength() < race_ancient_expansion_strength and GetExpFoe() != null and hero_rush_bonus[hero[1]] >= race_ancient_expansion_hero_rush_level then + if GetExpansionStrength() < race_ancient_expansion_strength and u != null and hero_rush_bonus[hero[1]] >= race_ancient_expansion_hero_rush_level then call Trace("Acient expansion - Begin Job") set ancient_expanding = true - call TQAddJob(1, ANCIENT_EXPANSION, 0) + call TQAddJob(1, ANCIENT_EXPANSION, 0) + set u = null return elseif hero_rush_bonus[hero[1]] < race_ancient_expansion_hero_rush_level then call Trace("Ancient Expansion not possible with hero") + set u = null return endif + set u = null else call Trace("Ancient expansion - No expansion available") endif endif - call TQAddJob(50, ANCIENT_EXPANSION_CHECK, 0) + call TQAddJob(50, ANCIENT_EXPANSION_CHECK, 0) endfunction #ENDIF \ No newline at end of file diff --git a/Jobs/BUY_ITEM.eai b/Jobs/BUY_ITEM.eai index 5f52bc107..e7c9d885a 100644 --- a/Jobs/BUY_ITEM.eai +++ b/Jobs/BUY_ITEM.eai @@ -38,10 +38,12 @@ function DropNonHealingItem takes unit u returns nothing set t = UnitItemInSlot(u, i) if t != null and not IsHealingItem(GetItemTypeId(t)) then call UnitDropItemPoint(u, t, GetUnitX(u), GetUnitY(u)) + set t = null return endif set i = i + 1 endloop + set t = null endfunction function BuyItemJob takes integer id returns nothing diff --git a/Jobs/BUY_NEUTRAL.eai b/Jobs/BUY_NEUTRAL.eai index bab1d3347..fc15c7ca5 100644 --- a/Jobs/BUY_NEUTRAL.eai +++ b/Jobs/BUY_NEUTRAL.eai @@ -9,77 +9,79 @@ function BuyNeutral takes integer id returns nothing local integer nn = GetNeutralNumber(id) local unit buy_place = nearest_neutral[nn] local boolean place_guarded = neutral_guarded[nn] -local integer detectedenemies = GetLocationNonCreepStrength(GetUnitX(neutral_sent[nn]), GetUnitY(neutral_sent[nn]), 1000) + local integer detectedenemies = GetLocationNonCreepStrength(GetUnitX(neutral_sent[nn]), GetUnitY(neutral_sent[nn]), 1000) local location l = null - local boolean retreat_home = false + //local boolean retreat_home = false call DisplayToAllJobDebug("BUY_NEUTRAL JOB START") - // moved this check here to prevent a job crash if placed lower down - if neutral_sent[nn] == null or not UnitAlive(neutral_sent[nn]) then - if retreat_home then - set retreat_home = false - return - endif - set neutral_sent[nn] = GetUnitToBuy(buy_place) - if neutral_sent[nn] == null then - call TQAddJob(sleep_multiplier, BUY_NEUTRAL, id) - return - endif - call GroupAddUnit(unit_buying_merc, neutral_sent[nn]) - endif - + if neutral_sent[nn] == null or not UnitAlive(neutral_sent[nn]) then + if retreat_home then + set retreat_home = false + set buy_place = null + return + endif + set neutral_sent[nn] = GetUnitToBuy(neutral_sent[nn], buy_place) + if neutral_sent[nn] == null then + call TQAddJob(sleep_multiplier, BUY_NEUTRAL, id) + set buy_place = null + return + endif + call GroupAddUnit(unit_buying_merc, neutral_sent[nn]) + endif if retreat_home then - set l = GetUnitLoc(neutral_sent[nn]) - if DistanceBetweenPoints(l, home_location) >= 1100 then - call CreateDebugTag("BUY_ITEM: Retreat to Home", 10, neutral_sent[nn], 3.00, 1.50) - call RemoveGuardPosition(neutral_sent[nn]) - call IssuePointOrder(neutral_sent[nn], "move", GetLocationX(home_location), GetLocationY(home_location)) - call TQAddJob(5, BUY_NEUTRAL, id) - else - call GroupRemoveUnit(unit_buying_merc, neutral_sent[nn]) - call RecycleGuardPosition(neutral_sent[nn]) - set retreat_home = false - set neutral_sent[nn] = null - set neutral_ordered[nn] = false - set buy_time_large[nn] = -1 - set buy_time_small[nn] = -1 - endif - call RemoveLocation(l) - set l = null - return + set l = GetUnitLoc(neutral_sent[nn]) + if DistanceBetweenPoints(l, home_location) >= 1100 then + call CreateDebugTag("BUY_ITEM: Retreat to Home", 10, neutral_sent[nn], 3.00, 1.50) + call RemoveGuardPosition(neutral_sent[nn]) + call IssuePointOrder(neutral_sent[nn], "move", GetLocationX(home_location), GetLocationY(home_location)) + call TQAddJob(5, BUY_NEUTRAL, id) + else + call GroupRemoveUnit(unit_buying_merc, neutral_sent[nn]) + call RecycleGuardPosition(neutral_sent[nn]) + set retreat_home = false + set neutral_sent[nn] = null + set neutral_ordered[nn] = false + set buy_time_large[nn] = -1 + set buy_time_small[nn] = -1 + endif + set buy_place = null + call RemoveLocation(l) + set l = null + return endif - // Enemies are present so get home before they harm us if DistanceBetweenUnits(neutral_sent[nn], buy_place) <= 800 and detectedenemies >= GetUnitStrength(neutral_sent[nn]) then + call RemoveGuardPosition(neutral_sent[nn]) call IssuePointOrder(neutral_sent[nn], "move", GetLocationX(home_location), GetLocationY(home_location)) //call TQAddUnitJob(GetTimeToReachLoc(neutral_sent[nn], home_location), RESET_GUARD_POSITION, 1, neutral_sent[nn]) - set retreat_home = true + set retreat_home = true call TQAddJob(1, BUY_NEUTRAL, id) + set buy_place = null + return endif - // call DisplayToAll("Buy Neutral Started") if (buy_time_large[nn] >= 0 and buy_time_large[nn] + buy_timeout_large < current_time) or (buy_time_small[nn] >= 0 and buy_time_small[nn] + buy_timeout_small < current_time) then set available_time[id] = ai_time + regenerate_time[id] / 2 call RecycleGuardPosition(neutral_sent[nn]) - call GroupRemoveUnit(unit_buying_merc, neutral_sent[nn]) + call GroupRemoveUnit(unit_buying_merc, neutral_sent[nn]) set neutral_sent[nn] = null set neutral_ordered[nn] = false set buy_time_large[nn] = -1 set buy_time_small[nn] = -1 + set buy_place = null return endif - if TownCountDone(id) >= neutral_wanted[nn] then call RecycleGuardPosition(neutral_sent[nn]) - call GroupRemoveUnit(unit_buying_merc, neutral_sent[nn]) + call GroupRemoveUnit(unit_buying_merc, neutral_sent[nn]) set neutral_sent[nn] = null set neutral_ordered[nn] = false set buy_time_large[nn] = -1 set buy_time_small[nn] = -1 + set buy_place = null return endif - if place_guarded and daytime >= 5 and daytime < 18 then set time_next_try = (18 - daytime)*20 else @@ -88,12 +90,10 @@ local integer detectedenemies = GetLocationNonCreepStrength(GetUnitX(neutral_sen if buy_time_large[nn] < 0 then set buy_time_large[nn] = current_time endif - - set timetotravel = GetTimeToReachUnit(neutral_sent[nn], buy_place) - + set timetotravel = GetTimeToReachUnit(neutral_sent[nn], buy_place) set dist = DistanceBetweenUnits(neutral_sent[nn], buy_place) if dist < buy_distance then - call CreateDebugTag("buy unit", 10, neutral_sent[nn], 3.00, 1.50) + call CreateDebugTag("buy unit", 10, neutral_sent[nn], 3.00, 1.50) call IssueImmediateOrder(neutral_sent[nn], "stop") call IssueNeutralImmediateOrderById(ai_player, buy_place, old_id[id]) if buy_time_small[nn] < 0 then @@ -101,12 +101,12 @@ local integer detectedenemies = GetLocationNonCreepStrength(GetUnitX(neutral_sen endif set time_next_try = 0.5 else - call CreateDebugTag("move to merc camp", 10, neutral_sent[nn], 3.00, 1.50) + call CreateDebugTag("move to merc camp", 10, neutral_sent[nn], 3.00, 1.50) call IssuePointOrder(neutral_sent[nn], "move", GetUnitX(buy_place), GetUnitY(buy_place)) - set time_next_try = 4 endif endif call TQAddJob(time_next_try, BUY_NEUTRAL, id) + set buy_place = null endfunction #ENDIF \ No newline at end of file diff --git a/Jobs/BUY_NEUTRAL_HERO.eai b/Jobs/BUY_NEUTRAL_HERO.eai index 992dc8a34..9d19712ed 100644 --- a/Jobs/BUY_NEUTRAL_HERO.eai +++ b/Jobs/BUY_NEUTRAL_HERO.eai @@ -12,57 +12,62 @@ function BuyNeutralHero takes integer id returns nothing local boolean place_guarded = neutral_guarded[nn] call DisplayToAllJobDebug("BUY_NEUTRAL_HERO JOB START") - - //call Trace("Get Tavern Hero Job") - if TownCountDone(id) >= neutral_wanted[nn] then - call RecycleGuardPosition(neutral_sent[nn]) - call GroupRemoveUnit(unit_buying_merc, neutral_sent[nn]) - set neutral_sent[nn] = null - set neutral_ordered[nn] = false - set buy_time_large[nn] = -1 - set buy_time_small[nn] = -1 - return - endif + //call Trace("Get Tavern Hero Job") + + if TownCountDone(id) >= neutral_wanted[nn] then + call RecycleGuardPosition(neutral_sent[nn]) + call GroupRemoveUnit(unit_buying_tavern, neutral_sent[nn]) + set neutral_sent[nn] = null + set neutral_ordered[nn] = false + set buy_time_large[nn] = -1 + set buy_time_small[nn] = -1 + set buying_unit = null + set tavern = null + return + endif - if place_guarded and daytime >= 5 and daytime < 18 then - set time_next_try = (18 - daytime)*20 - else + if place_guarded and daytime >= 5 and daytime < 18 then + set time_next_try = (18 - daytime)*20 + else if buying_unit == null or GetUnitState(buying_unit, UNIT_STATE_LIFE) <= 0 then - set neutral_sent[nn] = GetUnitToBuy(tavern) - set buying_unit = neutral_sent[nn] - if neutral_sent[nn] == null then - call TQAddJob(sleep_multiplier, BUY_NEUTRAL, id) - call Trace("No unit to get neutral hero") - return - else - call RemoveGuardPosition(buying_unit) - call Trace("unit for neutral hero obtained") - endif + set neutral_sent[nn] = GetUnitToBuy(neutral_sent[nn], tavern) + set buying_unit = neutral_sent[nn] + if neutral_sent[nn] == null then + call TQAddJob(sleep_multiplier, BUY_NEUTRAL, id) + call Trace("No unit to get neutral hero") + set buying_unit = null + set tavern = null + return + else + call RemoveGuardPosition(buying_unit) + call Trace("unit for neutral hero obtained") + endif endif - call GroupAddUnit(unit_buying_merc, buying_unit) + call GroupAddUnit(unit_buying_merc, buying_unit) set timetotravel = GetTimeToReachUnit(buying_unit, tavern) if current_time < (neutral_hero_time*5) - timetotravel then - set time_next_try = RMax((neutral_hero_time*5) - timetotravel - current_time, 0.5 ) + set time_next_try = RMax((neutral_hero_time*5) - timetotravel - current_time, 0.5 ) else - set distance = DistanceBetweenUnits(buying_unit, tavern) - if distance >= buy_distance then - call CreateDebugTag("Move to Tavern", 10, buying_unit, 3.00, 1.50) - call IssuePointOrder(buying_unit, "move", GetUnitX(tavern), GetUnitY(tavern)) - set time_next_try = 4 - else - call CreateDebugTag("buy tavern hero", 10, buying_unit, 3.00, 1.50) - call IssueImmediateOrder(buying_unit, "stop") - call IssueNeutralImmediateOrderById(ai_player, tavern, old_id[id]) - set time_next_try = 0.5 - endif + set distance = DistanceBetweenUnits(buying_unit, tavern) + if distance >= buy_distance then + call CreateDebugTag("Move to Tavern", 10, buying_unit, 3.00, 1.50) + call IssuePointOrder(buying_unit, "move", GetUnitX(tavern), GetUnitY(tavern)) + set time_next_try = 4 + else + call CreateDebugTag("buy tavern hero", 10, buying_unit, 3.00, 1.50) + call IssueImmediateOrder(buying_unit, "stop") + call IssueNeutralImmediateOrderById(ai_player, tavern, old_id[id]) + set time_next_try = 0.5 + endif endif - endif - - call TQAddJob(time_next_try, BUY_NEUTRAL_HERO, id) + endif + call TQAddJob(time_next_try, BUY_NEUTRAL_HERO, id) + set buying_unit = null + set tavern = null endfunction #ENDIF \ No newline at end of file diff --git a/Jobs/DETECT_DEFEAT.eai b/Jobs/DETECT_DEFEAT.eai index 34cf03111..07c2c51e2 100644 --- a/Jobs/DETECT_DEFEAT.eai +++ b/Jobs/DETECT_DEFEAT.eai @@ -6,43 +6,42 @@ integer gold_problem_level = 0 boolean ask_for_gold = false boolean desperation_assault = false - integer SaveYourselfMode = 0 + integer SaveYourselfMode = -1 #ELSE //============================================================================ // Self destruction //============================================================================ function SaveYourself takes nothing returns boolean - local boolean b = false - if SaveYourselfMode == 0 then // Choose self methods based on racial abilities , one ability use one num/mode , not recommended sale item or build(like UD) + if SaveYourselfMode == -1 then // Choose self methods based on racial abilities , one ability use one num/mode , not recommended sale item or build(like UD) if current_expansion == null then call ChooseExpansion() endif if race_ancient_expansion_available == true and TownCountDone(racial_expansion) > 0 then call TQAddJob(2, ANCIENT_EXPANSION, 0) - set ancient_exp_nobuild = true - set SaveYourselfMode = 1 - set b = true + set ancient_expanding = true + set SaveYourselfMode = ANCIENT_EXPANSION + return true elseif race_militia_available == true then call TQAddJob(2, MILITIA_EXPAND, 0) - set SaveYourselfMode = 2 - set b = true + set SaveYourselfMode = MILITIA_EXPAND + return true endif else //Check Self rescue situation - if SaveYourselfMode == 1 then + if SaveYourselfMode == ANCIENT_EXPANSION then if ancient_expanding == true then - set b = true // In self rescue, wait + return true // In self rescue, wait elseif TownCount(race_manual_loading_mine) > 0 or not HallsCompleted(racial_expansion) or GetMinesOwned() > 0 then - set SaveYourselfMode = 0 // Self rescue successful , because ancient_expanding is false and have mine - set b = true + set SaveYourselfMode = -1 // Self rescue successful , because ancient_expanding is false and have mine + return true endif - elseif SaveYourselfMode == 2 then + elseif SaveYourselfMode == MILITIA_EXPAND then if not HallsCompleted(racial_expansion) or GetMinesOwned() > 0 then - set SaveYourselfMode = 0 - set b = true + set SaveYourselfMode = -1 + return true endif endif endif - return b + return false endfunction function RemoveFromOwnForce takes player p returns nothing diff --git a/Jobs/FAST_BUILD.eai b/Jobs/FAST_BUILD.eai index ffcb6a3cf..4d8076999 100644 --- a/Jobs/FAST_BUILD.eai +++ b/Jobs/FAST_BUILD.eai @@ -39,6 +39,8 @@ function GetBuildingBuilt takes unit u returns unit call GroupEnumUnitsInRange(g, next_expansion_x, next_expansion_y, 1000, null) endif set g = SelectByPlayer(g, ai_player, true) + set g = SelectByHidden(g, false) + set g = SelectByAlive(g, true) set g = SelectNumberOfId(g, 1, old_id[racial_hall[1]]) set u = FirstOfGroup(g) call DestroyGroup(g) diff --git a/Jobs/FOCUSFIRE_CONTROL.eai b/Jobs/FOCUSFIRE_CONTROL.eai index bc020acaf..31c0ebf73 100644 --- a/Jobs/FOCUSFIRE_CONTROL.eai +++ b/Jobs/FOCUSFIRE_CONTROL.eai @@ -39,14 +39,13 @@ function GroupMicroSystem takes group g, group meleeg, group focus_group returns local location l = null local unit melee = null local group copy = null - loop set u = FirstOfGroup(g) - set unitloc = GetUnitLoc(u) exitwhen u == null + set unitloc = GetUnitLoc(u) set copy = CopyGroup(meleeg) - set melee = GetNearestOfGroup(copy, unitloc) - if not IsUnitInGroup(u, focus_fire_group) and IsUnitFacingUnit(melee, u) and DistanceBetweenUnits(u, melee) < 150 and GetUnitMoveSpeed(melee) <= GetUnitMoveSpeed(u) and (not IsUnitType(u, UNIT_TYPE_FLYING) or (IsUnitType(u, UNIT_TYPE_FLYING) and IsUnitType(melee, UNIT_TYPE_ATTACKS_FLYING))) then // 220 is the smallest ranged unit in warcraft 3. + set melee = GetNearestOfGroup(melee, copy, unitloc) + if melee != null and not IsUnitInGroup(u, focus_fire_group) and IsUnitFacingUnit(melee, u) and DistanceBetweenUnits(u, melee) < 150 and GetUnitMoveSpeed(melee) <= GetUnitMoveSpeed(u) and (not IsUnitType(u, UNIT_TYPE_FLYING) or (IsUnitType(u, UNIT_TYPE_FLYING) and IsUnitType(melee, UNIT_TYPE_ATTACKS_FLYING))) then // 220 is the smallest ranged unit in warcraft 3. set l = GetSubtractionLoc_kd(unitloc, GetUnitLoc(melee)) set l = GetProjectedLoc_dd(unitloc, l, 400) call RemoveGuardPosition(u) @@ -55,12 +54,15 @@ function GroupMicroSystem takes group g, group meleeg, group focus_group returns call TQAddUnitJob(1, RESET_GUARD_POSITION_ONLY, 80, u) call GroupRemoveUnit(focus_group, u) // prevent focus fire controls interrupting call RemoveLocation(l) + else + call RemoveLocation(unitloc) endif call DestroyGroup(copy) - call RemoveLocation(unitloc) call GroupRemoveUnit(g, u) endloop set copy = null +set melee = null + set unitloc = null set l = null endfunction @@ -73,11 +75,11 @@ function GroupOrderFocusWindInstant_d takes group g returns nothing //call CreateDebugTag("HARASS: WINDWALK COMMANDED", 10, u, 3.00, 1.50) if not IsUnitInGroup(u, windwalk_group) then call GroupAddUnit(windwalk_group, u) - call TQAddUnitJob(8, RESET_WINDWALKER, 0, u) endif if not UnitInvis(u) then call CreateDebugTag("FF: windwalk", 10, u, 1.00, 0.80) call IssueImmediateOrder(u, "windwalk") + call TQAddUnitJob(8, RESET_WINDWALKER, 0, u) endif endif call GroupRemoveUnit(g, u) @@ -90,10 +92,11 @@ function GroupOrderAttack_d takes group g, unit target returns nothing loop set u = FirstOfGroup(g) exitwhen u == null - call RemoveGuardPosition(u) + call RemoveGuardPosition(u) if UnitInvis(u) then call IssueTargetOrder(u, "attack", target) endif + call RecycleGuardPosition(u) call GroupRemoveUnit(g, u) endloop call DestroyGroup(g) @@ -102,7 +105,7 @@ endfunction function FocusGroupRemoveGuard takes group g returns nothing local unit u = null local group ug = CopyGroup(g) - + loop set u = FirstOfGroup(ug) exitwhen u == null @@ -110,8 +113,8 @@ function FocusGroupRemoveGuard takes group g returns nothing call CreateDebugTag("FF", 10, u, 1.00, 0.80) //call RemoveGuardPosition(u) //call TQAddUnitJob(1.5, RESET_GUARD_POSITION_ONLY, 80, u) - call GroupRemoveUnit(ug,u) endif + call GroupRemoveUnit(ug,u) endloop call DestroyGroup(ug) set ug = null @@ -141,13 +144,15 @@ function FocusFire takes unit u returns nothing call GroupEnumUnitsInRange(t, GetUnitX(u), GetUnitY(u), focus_fire_ranged_dist, null) set t = SelectUnittype(t, UNIT_TYPE_RANGED_ATTACKER, true) set temp_focus = GroupAddGroup(temp_focus, t) - call DestroyGroup(t) - set t = CreateGroup() + call GroupClear(t) + // call DestroyGroup(t) + // set t = CreateGroup() call GroupEnumUnitsInRange(t, GetUnitX(u), GetUnitY(u), focus_fire_melee_dist, null) set t = SelectUnittype(t, UNIT_TYPE_MELEE_ATTACKER, true) set temp_focus = GroupAddGroup(temp_focus, t) - call DestroyGroup(t) - set t = CreateGroup() + call GroupClear(t) + // call DestroyGroup(t) + // set t = CreateGroup() call GroupEnumUnitsInRange(t, GetUnitX(u), GetUnitY(u), normal_battle_radius, null) set t = SelectByInvisible(t, GetOwningPlayer(u), true) set temp_focus = GroupAddGroup(temp_focus, t) @@ -158,8 +163,8 @@ function FocusFire takes unit u returns nothing set temp_focus = SelectUnittype(temp_focus, UNIT_TYPE_ATTACKS_FLYING, true) endif set temp_focus = SelectUnittype(temp_focus, UNIT_TYPE_PEON, false) - set temp_focus = SelectByUnitStandard(temp_focus, true) set temp_focus = SelectByAlive(temp_focus, true) + set temp_focus = SelectByUnitStandard(temp_focus, true) //set temp_focus = SelectByOrderOr2(focus_fire_group,OrderId("move"),OrderId("attack"),OrderId("stop"), true) set temp_focus = SelectByOrder(temp_focus, OrderId("blizzard"), false) set temp_focus = SelectByOrder(temp_focus, OrderId("flamestrike"), false) @@ -176,11 +181,11 @@ function FocusFire takes unit u returns nothing if FirstOfGroup(micro_enemymelee_group) != null then call GroupMicroSystem(micro_ranged_group, micro_enemymelee_group, temp_focus) // Move ranged units away from melee units, if moved here they will not focus fire endif - + call DestroyGroup(t) if BlzGroupGetSize(temp_focus) > 0 then if focus_fire_unit == null or focus_fire_unit != u then if IsUnitType(u,UNIT_TYPE_STRUCTURE) == false and not IsUnitOwnedByPlayer(u, Player(PLAYER_NEUTRAL_AGGRESSIVE)) then // Dont windwalk for non-critical enemies - call GroupOrderFocusWindInstant_d(CopyGroup(temp_focus)) + call GroupOrderFocusWindInstant_d(CopyGroup(temp_focus)) endif set focus_fire_unit = u endif @@ -190,6 +195,7 @@ function FocusFire takes unit u returns nothing call GroupOrderAttack_d(CopyGroup(windwalk_group), u) // Forces Windwalking invisible units to attack directly as normal group order is ignored set focus_fire_group = GroupAddGroup(focus_fire_group, temp_focus) // Finally add units to group to say they have focus fired endif + set t = null call DestroyGroup(temp_focus) set temp_focus = null endfunction @@ -207,7 +213,8 @@ function FocusEnemyUnitsNearGroup takes group g returns nothing local real range_strength = 0 local integer enemy_count = 0 local real unit_life = 0 - + local real x = 0 + local real y = 0 call GroupClear(micro_ranged_group) call GroupClear(micro_enemymelee_group) call MoveLocation(enemy_melee_loc, 0,0) @@ -221,21 +228,23 @@ function FocusEnemyUnitsNearGroup takes group g returns nothing if unit_life > 0 and not IsUnitHidden(u) then if IsPlayerEnemy(GetOwningPlayer(u), ai_player) and not (UnitInvis(u) and not IsUnitDetected(u, ai_player)) and IsUnitVisible(u, ai_player) then if IsUnitType(u, UNIT_TYPE_MELEE_ATTACKER) == true then - set enemy_melee_loc = GetSumLoc_dd(enemy_melee_loc, GetUnitLoc(u)) + set x = x + GetUnitX(u) // Prevent loc exceeding map range + set y = y + GetUnitY(u) + //set enemy_melee_loc = GetSumLoc_dd(enemy_melee_loc, GetUnitLoc(u)) set enemy_count = enemy_count + 1 call GroupAddUnit(micro_enemymelee_group, u) endif - if IsUnitType(u, UNIT_TYPE_HERO) and UnitAlive(u) then + if IsUnitType(u, UNIT_TYPE_HERO) then if unit_life < hero_min_health then set hero_min_health = unit_life set hero_min_health_unit = u endif else - if unit_life < min_health and UnitAlive(u) and not UnitIsSleeping(u) and (unit_life < GetUnitState(u, UNIT_STATE_MAX_LIFE) or IsUnitType(u, UNIT_TYPE_MELEE_ATTACKER) or IsUnitType(u, UNIT_TYPE_RANGED_ATTACKER) or IsUnitType(u, UNIT_TYPE_TOWNHALL)) then + if unit_life < min_health and not UnitIsSleeping(u) and (unit_life < GetUnitState(u, UNIT_STATE_MAX_LIFE) or IsUnitType(u, UNIT_TYPE_MELEE_ATTACKER) or IsUnitType(u, UNIT_TYPE_RANGED_ATTACKER) or IsUnitType(u, UNIT_TYPE_TOWNHALL)) then set min_health = unit_life set min_health_unit = u endif - if unit_life < disabled_min_health and GetUnitMoveSpeed(u) == 0 and not IsUnitType(u, UNIT_TYPE_STRUCTURE) and UnitAlive(u) and not UnitIsSleeping(u) then + if unit_life < disabled_min_health and GetUnitMoveSpeed(u) == 0 and not IsUnitType(u, UNIT_TYPE_STRUCTURE) and not UnitIsSleeping(u) then set disabled_min_health = unit_life set disabled_min_health_unit = u endif @@ -244,7 +253,7 @@ function FocusEnemyUnitsNearGroup takes group g returns nothing set building_min_health_unit = u endif endif - elseif IsPlayerAlly(GetOwningPlayer(u), ai_player) and UnitAlive(u) then + elseif IsPlayerAlly(GetOwningPlayer(u), ai_player) then if IsUnitType(u, UNIT_TYPE_RANGED_ATTACKER) then set range_strength = range_strength + GetUnitStrength(u) if unit_life < GetUnitState(u, UNIT_STATE_MAX_LIFE)*0.70 then @@ -255,7 +264,13 @@ function FocusEnemyUnitsNearGroup takes group g returns nothing endif call GroupRemoveUnit(g,u) endloop - set enemy_melee_loc = GetDivisionLoc_d(enemy_melee_loc, I2R(Max(enemy_count, 1))) + if enemy_count != 0 then + set x = x / I2R(enemy_count) + set y = y / I2R(enemy_count) + call RemoveLocation(enemy_melee_loc) + set enemy_melee_loc = Location(x, y) + //set enemy_melee_loc = GetDivisionLoc_d(enemy_melee_loc, I2R(enemy_count)) + endif if hero_min_health_unit != null and (hero_min_health < focus_fire_limit * range_strength or disabled_min_health_unit == hero_min_health_unit) then call SetTargetHeroes(true) call FocusFire(hero_min_health_unit) @@ -277,6 +292,11 @@ function FocusEnemyUnitsNearGroup takes group g returns nothing call FocusFire(building_min_health_unit) endif endif + set u = null + set hero_min_health_unit = null + set min_health_unit = null + set building_min_health_unit = null + set disabled_min_health_unit = null endfunction //============================================================================ @@ -311,7 +331,7 @@ function FocusFireJob takes nothing returns nothing endif set i = i + 1 endloop - else + //else //call GroupRecycleGuardPositionInstant(windwalk_group) //loop // set u = FirstOfGroup(windwalk_group) @@ -322,9 +342,10 @@ function FocusFireJob takes nothing returns nothing // endif //endloop endif + call SetTargetHeroes(difficulty != EASY) call DestroyGroup(g) set g = null call TQAddJob(2 * sleep_multiplier, FOCUSFIRE_CONTROL, 0) endfunction -#ENDIF +#ENDIF \ No newline at end of file diff --git a/Jobs/HARASS.eai b/Jobs/HARASS.eai index c093cf112..f4e112c59 100644 --- a/Jobs/HARASS.eai +++ b/Jobs/HARASS.eai @@ -17,7 +17,7 @@ function GetHarassPeonTarget takes unit ru, unit u returns unit set g = SelectByAlive(g, true) set g = SelectByLoaded(g, false) set g = SelectByHidden(g, false) // Hopefully to get peons not currently building - set ru = GetNearestOfGroup(g, unitloc) + set ru = GetNearestOfGroup(ru, g, unitloc) call RemoveLocation(unitloc) call DestroyGroup(g) set unitloc = null @@ -35,7 +35,7 @@ function GetHarassExpansionTarget takes unit ru, unit u returns unit set g = SelectUnittype(g, UNIT_TYPE_TOWNHALL, true) set g = SelectByLocation(g, baseloc, 1000, false) set g = SelectByAlive(g, true) - set ru = GetNearestOfGroup(g, unitloc) + set ru = GetNearestOfGroup(ru, g, unitloc) call RemoveLocation(unitloc) call RemoveLocation(baseloc) call DestroyGroup(g) @@ -51,7 +51,7 @@ function GetHarassLocationTarget takes unit ru, real x, real y returns unit call GroupEnumUnitsInRange(g, x, y, 1000, null) set g = SelectByEnemy(g, ai_player, true) set g = SelectByAlive(g, true) - set ru = GetLeastHPUnitOfGroup(g) + set ru = GetLeastHPUnitOfGroup(ru,g) set g = null return ru endfunction @@ -66,7 +66,7 @@ function GetHarassMainHallTarget takes unit ru, unit u returns unit set g = SelectUnittype(g, UNIT_TYPE_TOWNHALL, true) set g = SelectByAlive(g, true) set g = SelectByLocation(g, baseloc, 1000, true) - set ru = GetNearestOfGroup(g, unitloc) + set ru = GetNearestOfGroup(ru, g, unitloc) call RemoveLocation(unitloc) call RemoveLocation(baseloc) call DestroyGroup(g) diff --git a/Jobs/ITEM_EXPANSION.eai b/Jobs/ITEM_EXPANSION.eai index 6921b7815..ce2cde234 100644 --- a/Jobs/ITEM_EXPANSION.eai +++ b/Jobs/ITEM_EXPANSION.eai @@ -24,7 +24,7 @@ function ItemExpansionJob takes nothing returns nothing return endif set exp_time_count = ai_time - set u = GetExpFoe() + set u = GetExpFoe(u) if item_exp_state == 0 then call Trace("Expansion Distance: " + Int2Str(R2I(GetExpansionDistance()))) call Trace("Expansion state 0: Check Expansion Hero and Location") diff --git a/Jobs/MICRO_UNITS.eai b/Jobs/MICRO_UNITS.eai index c1ddedbb3..00555d35b 100644 --- a/Jobs/MICRO_UNITS.eai +++ b/Jobs/MICRO_UNITS.eai @@ -16,14 +16,16 @@ //function MakeUnitHeal takes unit u returns nothing -// local unit healer = GetHealer(healer) -// local location unitloc = GetUnitLoc(healer) +// local unit healer = null +// local location unitloc = null // local real daytime = GetFloatGameState(GAME_STATE_TIME_OF_DAY) // if IsUnitType(u, UNIT_TYPE_HERO) then // return // endif +// set healer = GetHealer(healer) // if healer != null and not IsUnitType(u, UNIT_TYPE_MECHANICAL) then +// set unitloc = GetUnitLoc(healer) // call RemoveGuardPosition(u) // call GroupAddUnit(unit_healing, u) // call TQAddUnitJob(GetTimeToReachLoc(u, unitloc) + 1, RESET_GUARD_POSITION, 0, u) @@ -193,7 +195,7 @@ function MicroUnitsJob takes nothing returns nothing local real unit_health_ratio = 0.0 local integer id = 0 if major_hero == null or not UnitAlive(major_hero) then - set major_hero = GetMajorHero() + set major_hero = GetMajorHero(major_hero) endif //call DisplayToAllJobDebug("MICRO_UNITS Job Started") diff --git a/Jobs/MILITIA_CHECK.eai b/Jobs/MILITIA_CHECK.eai index 283381f3c..2eb318db7 100644 --- a/Jobs/MILITIA_CHECK.eai +++ b/Jobs/MILITIA_CHECK.eai @@ -10,7 +10,7 @@ function GetMilitiaHall takes unit u returns unit loop set u = FirstOfGroup(g) exitwhen u == null - if GetUnitAbilityLevel(u, race_militia_hall_ability) > 0 then + if UnitAlive(u) and GetUnitAbilityLevel(u, race_militia_hall_ability) > 0 then call DestroyGroup(g) set g = null return u @@ -34,13 +34,13 @@ function IsMilitiaAllowed takes nothing returns boolean endfunction function MilitiaCheckJob takes nothing returns nothing - local group g =null + local group g = null local unit u = null local integer i = 0 local boolean big_dist = false local integer militiarequired = 0 call DisplayToAllJobDebug("MILITIA_CHECK JOB START") - if militia_hall == null or GetUnitState(militia_hall, UNIT_STATE_LIFE) <= 0 or UnitAlive(militia_hall) == false then + if militia_hall == null or GetUnitState(militia_hall, UNIT_STATE_LIFE) <= 0 then set militia_hall = GetMilitiaHall(militia_hall) endif if race_militia_available and (militia_hall == null or towerrush) then @@ -52,6 +52,7 @@ function MilitiaCheckJob takes nothing returns nothing set g = CreateGroup() call GroupEnumUnitsOfType(g, race_militia_unitstring, null) set g = SelectByPlayer(g, ai_player, true) + set g = SelectByAlive(g, true) loop set u = FirstOfGroup(g) exitwhen u == null @@ -88,4 +89,4 @@ function MilitiaCheckJob takes nothing returns nothing call TQAddJob(5, MILITIA_CHECK, 0) endif endfunction -#ENDIF +#ENDIF \ No newline at end of file diff --git a/Jobs/MILITIA_EXPAND.eai b/Jobs/MILITIA_EXPAND.eai index 27a84908d..0e92df06e 100644 --- a/Jobs/MILITIA_EXPAND.eai +++ b/Jobs/MILITIA_EXPAND.eai @@ -46,13 +46,15 @@ endfunction function TryMilitiaExpansionFoot takes nothing returns nothing local group g = null +local unit u = null local integer ownstrength = 0 local integer expansionstrength = 0 local location l = null +local boolean buildend = false call DisplayToAllJobDebug("MILITIA_EXPAND JOB START") - if towerrush then + if towerrush or GetMinesOwned() >= 2 then // have mine , peon need harvest call TQAddJob(80, MILITIA_EXPAND, 0) return endif @@ -85,29 +87,32 @@ local location l = null set gold_buffer = 0 set wood_buffer = 0 call Trace("MILITIA_EXPAND: Militia expansion will not be done") - set militia = false + //set militia = false + set buildend = true endif endif endif - if militia then + if not buildend then call TQAddJob(7, MILITIA_EXPAND, 0) + return endif elseif militia_state == 1 then set gold_buffer = GetUnitGoldCost2(racial_expansion) set wood_buffer = GetUnitWoodCost2(racial_expansion) + set u = GetExpFoe(u) if ownstrength + 6 < GetExpansionStrength() then set militia_expanding = false set militia_state = 0 // Lost units so stop trying to expand - elseif GetMilitiaExpansionStrength() <= 0 and GetExpFoe() == null then + elseif GetMilitiaExpansionStrength() <= 0 and u == null then set militia_expanding = false set militia_state = 2 call Trace("Militia state 1 done") else set militia_expanding = true endif - if militia then - call TQAddJob(2, MILITIA_EXPAND, 0) - endif + set u = null + call TQAddJob(2, MILITIA_EXPAND, 0) + return elseif militia_state == 2 then call Trace("Militia state 2") if GetMilitiaExpansionStrength() > 0 then @@ -147,9 +152,8 @@ local location l = null set militia_state = 3 call Trace("Militia state 2 done") endif - if militia then - call TQAddJob(2, MILITIA_EXPAND, 0) - endif + call TQAddJob(2, MILITIA_EXPAND, 0) + return elseif militia_state == 3 then if GetMilitiaExpansionStrength() > 0 then set militia_state = 1 @@ -159,7 +163,7 @@ local location l = null set militia_state = 2 else if CheckExpansionTaken(militia_expansion) then - set militia = false + //set militia = false set militia_state = 0 set militia_expansion = null call RemoveLocation(militia_loc) @@ -168,40 +172,42 @@ local location l = null set wood_buffer = 0 call Trace("Militia Ended") call RecycleGuardPosition(militia_builder) - return - endif - if militia_loc == null then - call GetMilitiaExpansionLoc(old_id[racial_expansion]) - endif - if GetGold() >= GetUnitGoldCost2(racial_hall[1]) and GetWood() >= GetUnitWoodCost2(racial_hall[1]) then - //call IssueTargetOrder(militia_fastb1, "stop", current_expansion) - //call IssueTargetOrder(militia_fastb2, "stop", current_expansion) - call RecycleGuardPosition(militia_builder) // has to be here or peasant comes off construction - call BuildMilitiaExpansion(militia_builder, old_id[racial_expansion]) - //set militia = false - //set militia_state = 0 - //set militia_expansion = null - call Trace("Militia Build commanded") - else - set gold_buffer = GetUnitGoldCost2(racial_expansion) - set wood_buffer = GetUnitWoodCost2(racial_expansion) - call Trace("Moving near") - call RemoveGuardPosition(militia_builder) + set buildend = true + else if militia_loc == null then - call IssueTargetOrder(militia_builder, "move", current_expansion) - //call IssueTargetOrder(militia_fastb1, "move", current_expansion) - //call IssueTargetOrder(militia_fastb2, "move", current_expansion) - else - call IssuePointOrderLoc(militia_builder, "move", militia_loc) + call GetMilitiaExpansionLoc(old_id[racial_expansion]) + endif + if GetGold() >= GetUnitGoldCost2(racial_hall[1]) and GetWood() >= GetUnitWoodCost2(racial_hall[1]) then + //call IssueTargetOrder(militia_fastb1, "stop", current_expansion) + //call IssueTargetOrder(militia_fastb2, "stop", current_expansion) + call RecycleGuardPosition(militia_builder) // has to be here or peasant comes off construction + set buildend = BuildMilitiaExpansion(militia_builder, old_id[racial_expansion]) + //set militia = false + //set militia_state = 0 + //set militia_expansion = null + call Trace("Militia Build commanded") + else + set gold_buffer = GetUnitGoldCost2(racial_expansion) + set wood_buffer = GetUnitWoodCost2(racial_expansion) + call Trace("Moving near") + call RemoveGuardPosition(militia_builder) + if militia_loc == null then + call IssueTargetOrder(militia_builder, "move", current_expansion) + //call IssueTargetOrder(militia_fastb1, "move", current_expansion) + //call IssueTargetOrder(militia_fastb2, "move", current_expansion) + else + call IssuePointOrderLoc(militia_builder, "move", militia_loc) + endif endif - endif endif - if militia then + endif + if not buildend then call TQAddJob(3, MILITIA_EXPAND, 0) + return endif endif - + call TQAddJob(50, MILITIA_EXPAND, 0) endfunction -#ENDIF +#ENDIF \ No newline at end of file diff --git a/Jobs/SEND_HOME.eai b/Jobs/SEND_HOME.eai index f05ab0707..b94b57515 100644 --- a/Jobs/SEND_HOME.eai +++ b/Jobs/SEND_HOME.eai @@ -61,8 +61,8 @@ function SendUnitHomeJob takes unit u, integer p returns nothing endif //set shop_wanted = 1 if buy_type[racial_healing_item] == BT_RACIAL_ITEM then - //set shop_unit = GetUnitOfTypeNearUnit(old_id[racial_shop], u) - set nearshopunit = GetUnitOfTypeNearUnit(old_id[racial_shop], u) + //set shop_unit = GetUnitOfTypeNearUnit(old_id[racial_shop], u, shop_unit) + set nearshopunit = GetUnitOfTypeNearUnit(old_id[racial_shop], u, nearshopunit) // set shop_distance_limit = raceshop_distance_limit else // set shop_unit = nearest_neutral[NEUTRAL_MERCHANT] diff --git a/Jobs/ZEPPELIN_FOLLOW.eai b/Jobs/ZEPPELIN_FOLLOW.eai index f7857b3c0..32976bb0f 100644 --- a/Jobs/ZEPPELIN_FOLLOW.eai +++ b/Jobs/ZEPPELIN_FOLLOW.eai @@ -21,7 +21,7 @@ function ZeppelinFollowJob takes nothing returns nothing call GroupPointOrderLoc(g, "attack", exist_town[GetRandomInt(0,Max(exist_town_num-1,0))]) if major_hero != null and UnitAlive(major_hero) then set heroloc = GetUnitLoc(major_hero) - set follow_zeppelin = GetNearestOfGroup(g, heroloc) + set follow_zeppelin = GetNearestOfGroup(follow_zeppelin, g, heroloc) call RemoveLocation(heroloc) set heroloc = null endif diff --git a/common.eai b/common.eai index 2ccb6ecf4..7c5dc267f 100644 --- a/common.eai +++ b/common.eai @@ -480,6 +480,7 @@ globals real gold_income = 0 integer income_per_mine = 3000 real gold_unit_percentage = 0.9 + boolean take_all_ghouls_along = false integer racial_peon = 0 @@ -3973,8 +3974,7 @@ endfunction //========================================================================== // (AMAI) GetOneOfId //========================================================================== -function GetOneOfId takes player p, integer id returns unit - local unit u = null +function GetOneOfId takes unit u, player p, integer id returns unit local group g = CreateGroup() call GroupEnumUnitsOfPlayer(g, p, null) set g = SelectByHidden(g, false) @@ -3991,7 +3991,7 @@ function GetOneOfId takes player p, integer id returns unit endloop call DestroyGroup(g) set g = null - return null + return u endfunction //========================================================================== @@ -4424,11 +4424,11 @@ endfunction // (AMAI) GetNearestOfGroup // NOTE: Function will remove units from the group passed to it //========================================================================== -function GetNearestOfGroup takes group g, location l returns unit +function GetNearestOfGroup takes unit ru, group g, location l returns unit local real d = 0 local unit u = null - local unit ru = null local real sd = 1000000 + set ru = null if l != null then loop set u = FirstOfGroup(g) @@ -4493,33 +4493,33 @@ endfunction //========================================================================== // (AMAI) GetFarestOfGroup //========================================================================== -function GetFarestOfGroup takes group g, location l returns unit +function GetFarestOfGroup takes unit ru, group g, location l returns unit local real d = 0 local unit u = null - local unit nu = null local real sd = 0 + set ru = null loop set u = FirstOfGroup(g) exitwhen u == null set d = DistanceBetweenPoints_dk(GetUnitLoc(u), l) if d > sd then set sd = d - set nu = u + set ru = u endif call GroupRemoveUnit(g, u ) endloop - return nu + return ru endfunction //========================================================================== // (AMAI) GetFastestToPointOfGroup //========================================================================== -function GetFastestToPointOfGroup takes group g, location l returns unit +function GetFastestToPointOfGroup takes unit ru, group g, location l returns unit local real d = 0 local unit u = null - local unit nu = null local real sd = 1000000 local real ms = 0 + set ru = null loop set u = FirstOfGroup(g) exitwhen u == null @@ -4527,33 +4527,33 @@ function GetFastestToPointOfGroup takes group g, location l returns unit set d = DistanceBetweenPoints_dk(GetUnitLoc(u), l) / ms if d < sd then set sd = d - set nu = u + set ru = u endif call GroupRemoveUnit(g, u ) endloop - return nu + return ru endfunction //========================================================================== // (AMAI) GetLeastHPUnitOfGroup //========================================================================== -function GetLeastHPUnitOfGroup takes group g returns unit +function GetLeastHPUnitOfGroup takes unit ru, group g returns unit local real hp = 0 local unit u = null - local unit lhpu = null local real lhp = 1000000 + set ru = null loop set u = FirstOfGroup(g) exitwhen u == null set hp = GetUnitState(u, UNIT_STATE_LIFE) if hp < lhp then set lhp = hp - set lhpu = u + set ru = u endif call GroupRemoveUnit(g, u ) endloop call DestroyGroup(g) - return lhpu + return ru endfunction //========================================================================== @@ -4580,13 +4580,12 @@ endfunction //========================================================================== // (AMAI) GetUnitToBuy //========================================================================== -function GetUnitToBuy takes unit buy_place returns unit +function GetUnitToBuy takes unit ru, unit buy_place returns unit local group g = CreateGroup() local unit u = null - local unit buyingunit = null local real distance = 10000 local real newdistance = 0 - + set ru = null call GroupEnumUnitsOfPlayer(g, ai_player, null) set g = SelectByUnitStandard(g, true) loop @@ -4596,37 +4595,37 @@ function GetUnitToBuy takes unit buy_place returns unit set newdistance = DistanceBetweenUnits(buy_place, u) if newdistance < distance then set distance = newdistance - set buyingunit = u + set ru = u endif endif call GroupRemoveUnit(g, u) endloop - - if buyingunit == null then - set buyingunit = GetExpansionPeon() - endif call DestroyGroup(g) set g = null - set u = null - return buyingunit + if ru == null then + set ru = GetExpansionPeon() + if ru == null then + set ru = GetExpansionPeon2(ru) + endif + endif + return ru endfunction //========================================================================== // (AMAI) GetUnitOfTypeNearUnit //========================================================================== -function GetUnitOfTypeNearUnit takes integer ut, unit nu returns unit +function GetUnitOfTypeNearUnit takes integer ut, unit nu, unit ru returns unit local group g = CreateGroup() - local unit u = null local location unitloc = GetUnitLoc(nu) call GroupEnumUnitsOfPlayer(g, ai_player, null) set g = SelectById(g, ut, true) - set u = GetNearestOfGroup(g, unitloc) + set ru = GetNearestOfGroup(ru, g, unitloc) call DestroyGroup(g) - call RemoveLocation(unitloc) set g = null + call RemoveLocation(unitloc) set unitloc = null - return u + return ru endfunction //========================================================================== @@ -4640,7 +4639,7 @@ function GetUnusedZeppelinNearUnit takes unit ru, unit nu returns unit set g = SelectByPlayer(g, ai_player, true) set g = SelectByOrderOr(g, 0, order_cancel, true) set g = SelectByUnitStandard(g, true) - set ru = GetNearestOfGroup(g, unitloc) + set ru = GetNearestOfGroup(ru, g, unitloc) call DestroyGroup(g) set g = null call RemoveLocation(unitloc) @@ -4698,10 +4697,8 @@ endfunction //========================================================================== // gets a unit that can act as a hero for versions without heroes -function GetUnitHero takes nothing returns unit +function GetUnitHero takes unit u returns unit local group g = CreateGroup() - local unit u = null - call GroupEnumUnitsOfPlayer(g,ai_player,null) set g = SelectByAlive(g, true) set g = SelectByUnitStandard(g, true) @@ -4717,7 +4714,7 @@ function GetUnitHero takes nothing returns unit endloop call DestroyGroup(g) set g = null - return null + return u endfunction function GetUnitHeroReplacement takes unit u , location l returns unit @@ -4740,7 +4737,7 @@ function GetUnitHeroReplacement takes unit u , location l returns unit return u endfunction -function GetMajorHero takes nothing returns unit +function GetMajorHero takes unit u returns unit local integer i = 1 loop exitwhen i > 3 @@ -4749,7 +4746,7 @@ function GetMajorHero takes nothing returns unit endif set i = i + 1 endloop - return GetUnitHero() + return GetUnitHero(u) //return null endfunction @@ -5200,7 +5197,7 @@ function GetLocationNonCreepStrength takes real x, real y, real radius returns i endfunction //============================================================================ -function GetLocationEnemyStructures takes real x, real y, real radius returns integer +function GetLocationEnemyStrength takes real x, real y, real radius, boolean only_structures returns integer local group g = CreateGroup() local integer sum = 0 local unit u = null @@ -5208,7 +5205,7 @@ function GetLocationEnemyStructures takes real x, real y, real radius returns in loop set u = FirstOfGroup(g) exitwhen u == null - if IsUnitType(u,UNIT_TYPE_STRUCTURE) == true and GetUnitState(u, UNIT_STATE_LIFE) > 0 and GetOwningPlayer(u) != Player(PLAYER_NEUTRAL_AGGRESSIVE) and GetOwningPlayer(u) != Player(PLAYER_NEUTRAL_PASSIVE) and IsPlayerEnemy(ai_player, GetOwningPlayer(u)) and not IsUnitHidden(u) then + if ((only_structures and IsUnitType(u, UNIT_TYPE_STRUCTURE)) or (not only_structures and not IsUnitType(u, UNIT_TYPE_PEON))) and GetUnitState(u, UNIT_STATE_LIFE) > 0 and GetOwningPlayer(u) != Player(PLAYER_NEUTRAL_AGGRESSIVE) and GetOwningPlayer(u) != Player(PLAYER_NEUTRAL_PASSIVE) and IsPlayerEnemy(ai_player, GetOwningPlayer(u)) and not IsUnitHidden(u) then set sum = sum + 1 endif call GroupRemoveUnit(g,u) @@ -5218,6 +5215,7 @@ function GetLocationEnemyStructures takes real x, real y, real radius returns in return sum endfunction + //============================================================================ function IsUnitTower takes unit u returns boolean if IsUnitType(u, UNIT_TYPE_STRUCTURE) == true and IsUnitType(u, UNIT_TYPE_RANGED_ATTACKER) == true and not IsUnitHidden(u) then @@ -5664,33 +5662,23 @@ function BuildBRAtCreep takes nothing returns nothing endif set loc = GetBuildLocationInDistanceFromLoc_d(old_id[racial_rushcreep], loc, 600) if loc != null and DistanceBetweenPoints(loc, home_location) < distance then //Prevent some islands/shallow water terrain from creating u on the other side of the map - set g = CreateGroup() - call GroupEnumUnitsInRangeOfLoc(g, loc, 510, null) - loop - set u = FirstOfGroup(g) - exitwhen u == null or s == -2 - if IsPlayerEnemy(GetOwningPlayer(u), ai_player) then //if have enemy , cannot build (if use getlocationstrength need judge twice -- creep and player) - set s = -2 - endif - call GroupRemoveUnit(g,u) - endloop - if s != -2 then + if GetLocationCreepStrength(GetLocationX(loc), GetLocationY(loc), 510) <= 0 then //if have enemy , cannot build set u = GetExpansionPeon2(u) if u == null or GetUnitCurrentOrder(u) != OrderId("harvest") then - call GroupClear(g) + set g = CreateGroup() call GroupEnumUnitsOfPlayer(g, ai_player, null) set g = SelectUnittype(g, UNIT_TYPE_PEON, true) set g = SelectByLoaded(g, true) set u = FirstOfGroup(g) + call DestroyGroup(g) + set g = null call IssueTargetOrder(own_town_mine[0], "unload", u) call Sleep(0.01) endif call RemoveGuardPosition(u) // no need reset guard , the tree can train call IssuePointOrderByIdLoc(u, old_id[racial_rushcreep], loc) + set u = null endif - call DestroyGroup(g) - set g = null - set u = null endif call RemoveLocation(loc) set loc = null @@ -6395,18 +6383,14 @@ function ChooseExpansion takes nothing returns nothing endfunction //============================================================================ -function GetExpFoe takes nothing returns unit +function GetExpFoe takes unit u returns unit local group g = CopyGroup(current_expansion_creeps) - local unit u = null local location l = GetUnitLoc(current_expansion) //call Trace("Copy group") - set g = SelectByAlive(g, true) - set u = GetNearestOfGroup(g, l) - if l != null then - call RemoveLocation(l) - set l = null - endif + set u = GetNearestOfGroup(u, g, l) + call RemoveLocation(l) + set l = null call DestroyGroup(g) set g = null //call Trace("Have a foe") @@ -6424,7 +6408,7 @@ function GetNeutralGuard takes integer nn returns boolean set g = CopyGroup(neutral_guards[nn]) set g = SelectByAlive(g, true) set l = GetUnitLoc(nearest_neutral[nn]) - set u = GetNearestOfGroup(g, l) + set u = GetNearestOfGroup(u, g, l) call RemoveLocation(l) set l = null call DestroyGroup(g) @@ -6749,7 +6733,7 @@ endfunction function GetItemHero takes item it returns unit local integer i = 1 loop - exitwhen i > 3 + exitwhen i > 3 or it == null if hero_built[i] and UnitAlive(hero_unit[i]) then if UnitHasItem(hero_unit[i], it) then return hero_unit[i] @@ -10028,25 +10012,25 @@ endfunction //============================================================================ function BuildMovePeonZeppelin takes unit peon, unit target returns boolean - if expansion_peon == null or not UnitAlive(expansion_peon) then - set expansion_peon = peon - endif // Disabled just in case - if IsUnitInTransport(expansion_peon, build_zeppelin) then + if IsUnitInTransport(peon, build_zeppelin) then if DistanceBetweenUnits(build_zeppelin, target) > 300 then call IssuePointOrder(build_zeppelin, "move", GetUnitX(target) + GetRandomReal(-200,200), GetUnitY(target) + GetRandomReal(-200,200)) else - call IssueTargetOrder(build_zeppelin, "unload", expansion_peon) - call Sleep(1.2) //unload time + call IssueImmediateOrder(build_zeppelin, "stop") + call IssueTargetOrder(build_zeppelin, "unload", peon) + call Sleep(0.5) //unload time call GroupRemoveUnit(unit_zepplin_move, build_zeppelin) + call IssueImmediateOrder(peon, "stop") return true endif else - if DistanceBetweenUnits(expansion_peon, target) < 400 then + if DistanceBetweenUnits(peon, target) < race_max_expa_mine_distance then call GroupRemoveUnit(unit_zepplin_move, build_zeppelin) + call IssueImmediateOrder(peon, "stop") return true else - call IssueTargetOrder(expansion_peon, "smart", build_zeppelin) + call IssueTargetOrder(peon, "smart", build_zeppelin) endif endif return false @@ -10056,11 +10040,13 @@ endfunction function StartExpansionAM takes integer qty, integer hall returns integer local integer count = TownCount(hall) local integer countdone = TownCountDone(hall) - local unit peon = null + local integer mines = GetMinesOwned() + local integer i = racial_expansion local unit u = null local integer gold_cost = 0 local integer wood_cost = 0 - + local boolean f = false + local boolean w = false if countdone >= qty then return BUILT_ALL endif @@ -10068,10 +10054,8 @@ function StartExpansionAM takes integer qty, integer hall returns integer return BUILT_SOME endif - if first_town_mine > 1 then - if MultipleMinefix() then - return BUILT_ALL - endif + if first_town_mine > 1 and MultipleMinefix() then + return BUILT_ALL endif if current_expansion == null or CheckExpansionTaken(current_expansion) then @@ -10088,7 +10072,12 @@ function StartExpansionAM takes integer qty, integer hall returns integer // call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Expansion Taken Checked") // call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Expansion choosen") - + if first_town_mine > 0 and (race_uses_mine_expansion or race_manual_loading) then //home_location have multiple mine , fix GetMinesOwned bug(ELF and UD) + if race_manual_loading then + set i = race_manual_loading_mine + endif + set mines = Min(TownCount(i),mines) // check actual number of gold mines + endif set gold_cost = GetUnitGoldCost2(hall) set wood_cost = GetUnitWoodCost2(hall) @@ -10101,15 +10090,18 @@ function StartExpansionAM takes integer qty, integer hall returns integer if total_wood < 0 then set total_wood = 0 endif - - if total_gold <= 0 and not (gold_cost == 0) then + if mines != 0 then + if total_gold <= 0 and not (gold_cost == 0) then + return NOT_ENOUGH_RES + endif + if total_wood <= 0 and not (wood_cost == 0) then + return NOT_ENOUGH_RES + endif + elseif GetGold() < gold_cost or GetWood() < wood_cost then //fix priority , if have rescources and not mine , ensure expansion return NOT_ENOUGH_RES endif - if total_wood <= 0 and not (wood_cost == 0) then - return NOT_ENOUGH_RES - endif - set take_exp = (GetExpFoe() != null) + set take_exp = (GetExpFoe(u) != null) set u = null if take_exp or total_gold <= 0 or total_wood <= 0 then return BUILT_SOME @@ -10117,18 +10109,22 @@ function StartExpansionAM takes integer qty, integer hall returns integer // call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Expansion rescources sorted") - set peon = GetExpansionPeon() - if peon == null then - set peon = GetExpansionPeon2(peon) + if expansion_peon == null or not UnitAlive(expansion_peon) then + set expansion_peon = GetExpansionPeon() + if expansion_peon == null or not UnitAlive(expansion_peon) then + set expansion_peon = GetExpansionPeon2(expansion_peon) + endif endif - // call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Peon Got") - if not IsUnitInGroup(current_expansion, water_expansion) and DistanceBetweenUnits(peon,current_expansion) > 6000 and not IsUnitInGroup(current_expansion, far_expansion) then + set f = IsUnitInGroup(current_expansion, far_expansion) + set w = IsWaterExpansion(current_expansion) + if not w and DistanceBetweenUnits(expansion_peon,current_expansion) > 6000 and not f then call GroupAddUnit(far_expansion, current_expansion) + set f = true endif - if peon != null then - if (IsWaterExpansion(current_expansion) or IsUnitInGroup(current_expansion, far_expansion)) and neutral_available[NEUTRAL_OBSERVATORY] then + if expansion_peon != null and UnitAlive(expansion_peon) then + if (w or f) and neutral_available[NEUTRAL_OBSERVATORY] then if build_zeppelin == null or not UnitAlive(build_zeppelin) then if not UnitAlive(build_zeppelin) then call GroupRemoveUnit(unit_zepplin_move, build_zeppelin) @@ -10141,23 +10137,20 @@ function StartExpansionAM takes integer qty, integer hall returns integer endif endif call Trace("AMAIStartexpa: Is a water or far expansion so using zeppelin") - if (IsWaterExpansion(current_expansion) and build_zeppelin == null) or (build_zeppelin != null and not BuildMovePeonZeppelin(peon, current_expansion)) then + if (w and build_zeppelin == null) or (build_zeppelin != null and not BuildMovePeonZeppelin(expansion_peon, current_expansion)) then call Trace("AMAIStartexpa: zeppelin cannot expand") - set peon = null return BUILT_SOME endif - set peon = expansion_peon endif set exp_time_count = ai_time // This sets time to next expansion to current time so it waits enough time before starting another expansion if race_uses_mine_expansion then - call TQAddUnitJob(2 * sleep_multiplier, BUILD_EXPANSION, 0, peon) - call IssueTargetOrderById(peon, old_id[hall], current_expansion) + call TQAddUnitJob(2 * sleep_multiplier, BUILD_EXPANSION, 0, expansion_peon) + call IssueTargetOrderById(expansion_peon, old_id[hall], current_expansion) else - call ConstructExpansion(peon,old_id[hall]) + call ConstructExpansion(expansion_peon,old_id[hall]) endif - set peon = null endif -// call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Expansion Finished") + // call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Expansion Finished") return BUILT_SOME endfunction @@ -10173,7 +10166,7 @@ function BuyItem takes integer qty, integer id returns boolean endif set shop_wanted = qty if buy_type[id] == BT_RACIAL_ITEM then - set shop_unit = GetOneOfId(ai_player, old_id[racial_shop]) + set shop_unit = GetOneOfId(shop_unit, ai_player, old_id[racial_shop]) set shop_distance_limit = raceshop_distance_limit else set shop_unit = nearest_neutral[NEUTRAL_MERCHANT] @@ -10215,7 +10208,7 @@ function BuyAllyShopItem takes integer qty, integer id returns boolean loop set u = FirstOfGroup(g) exitwhen u == null - if GetUnitAbilityLevel(u, 'Aall') > 0 and UnitAlive(u) then // select ally shop , use JOB TrackTown record ally shop is best, but worried about affecting efficiency , if use new JOB then too wasteful + if GetUnitAbilityLevel(u, 'Aall') > 0 and UnitAlive(u) and not IsUnitHidden(u) then // select ally shop , use JOB TrackTown record ally shop is best, but worried about affecting efficiency , if use new JOB then too wasteful if shop_unit == null or GetRandomInt(0,1) == 1 then set shop_unit = u // get Random shop endif @@ -10339,13 +10332,12 @@ function StartItem takes integer ask_qty, integer itemid returns integer if BuyItem(have_qty + 1, itemid) then return BUILT_SOME else - if IsHealingItem(itemid) and buy_type[itemid] == BT_RACIAL_ITEM and GetGold() > 1000 and c_ally_total > 0 then + if IsHealingItem(itemid) and buy_type[itemid] == BT_RACIAL_ITEM and c_ally_total > 0 and GetGold() > 1000 then if BuyAllyShopItem(have_qty + 1,itemid) then //return false just run next time return BUILT_SOME - else - return CANNOT_BUILD endif endif + return CANNOT_BUILD endif return BUILT_SOME endfunction @@ -10488,7 +10480,7 @@ set i = 2 if active_expansion == true then set i = 3 endif -set u = GetExpFoe() +set u = GetExpFoe(u) if mines < i and ai_time - exp_time_count > exp_first_time then if u != null then set take_exp = true @@ -10556,7 +10548,7 @@ function HeroReviver takes nothing returns nothing exitwhen i > 3 if GetUnitCountDone(old_id[hero[i]]) > 0 then if not hero_built[i] then - set hero_unit[i] = GetOneOfId(ai_player, old_id[hero[i]]) + set hero_unit[i] = GetOneOfId(hero_unit[i], ai_player, old_id[hero[i]]) if hero_unit[i] != null then set hero_built[i] = true call InitHeroInfo(i) @@ -10971,6 +10963,9 @@ function FormGroupAM takes integer seconds returns nothing if unitid == racial_ghoul then set desire = attacking_ghouls + if towerrush then + set desire = Min(Max(count - 2 , 0),desire) // reserve + endif endif call ConversionsAM(desire,unitid) @@ -10978,7 +10973,9 @@ function FormGroupAM takes integer seconds returns nothing if count >= desire then call AddAssault(desire,old_id[unitid]) else - set desire = attack_qty[index] + if unitid != racial_ghoul or take_all_ghouls_along then + set desire = attack_qty[index] + endif if count < desire then call AddAssault(desire,old_id[unitid]) @@ -10995,7 +10992,7 @@ endfunction //============================================================================ function DoAttackJobs takes nothing returns nothing if major_hero == null or not UnitAlive(major_hero) then - set major_hero = GetMajorHero() + set major_hero = GetMajorHero(major_hero) endif set battle_radius = normal_battle_radius set break_attack = false @@ -11017,7 +11014,7 @@ function GetDistractionTarget takes unit ru, unit target returns unit call GroupEnumUnitsOfPlayer(g, GetOwningPlayer(target), null) set g = SelectUnittype(g, UNIT_TYPE_STRUCTURE, true) set g = SelectByLocation(g, unitloc, 3000, false) - set ru = GetFarestOfGroup(g, unitloc) + set ru = GetFarestOfGroup(ru, g, unitloc) call RemoveLocation(unitloc) set unitloc = null call DestroyGroup(g) @@ -11178,7 +11175,7 @@ function CommonSleepUntilTargetDeadAM takes unit target, boolean iscreeping, boo exitwhen target == null endif //if not iscreeping then - // exitwhen GetLocationNonCreepStrength(unitx, unity, battle_radius) <= 0 and not UnitAlive(target) and GetLocationEnemyStructures(unitx, unity, battle_radius) <= 0 // enemies are dead and target dead + // exitwhen GetLocationNonCreepStrength(unitx, unity, battle_radius) <= 0 and not UnitAlive(target) and GetLocationEnemyStrength(unitx, unity, battle_radius, true) <= 0 // enemies are dead and target dead //else //call Trace("Units, Creeps: " + Int2Str(GetLocationNonCreepStrength(unitx, unity, battle_radius)) + "," + Int2Str(GetLocationCreepStrength(unitx, unity, 500))) // exitwhen GetLocationNonCreepStrength(unitx, unity, battle_radius) <= 0 and not UnitAlive(target) and GetLocationCreepStrength(unitx, unity, 500) <= 0 @@ -11873,8 +11870,9 @@ function Militia_Expansion takes integer m returns nothing local group g = null local group cg = null local unit u = null - local unit efoe = GetExpFoe() + local unit efoe = null local integer t = 0 + set efoe = GetExpFoe(efoe) if efoe == null or IsUnitInGroup(current_expansion,water_expansion) then //is WaterExpansion set efoe = null return @@ -12168,12 +12166,14 @@ function SingleMeleeAttackAM takes boolean needs_exp, boolean has_siege, boolean call FormGroupAM(3) //call AddAssault(1, old_id[racial_hall[1]]) call SetCaptainHome(BOTH_CAPTAINS,GetUnitX(ancient_exp_unit),GetUnitY(ancient_exp_unit)) - //if DistanceBetweenUnits(ancient_exp_unit, GetExpFoe()) <= 500 then - call AttackMoveKillCreep(GetExpFoe()) + set creep = GetExpFoe(creep) + //if DistanceBetweenUnits(ancient_exp_unit, creep) <= 500 then + call AttackMoveKillCreep(creep) //else //call AttackMoveKillXYAAM(R2I(GetUnitX(ancient_exp_unit)), R2I(GetUnitY(ancient_exp_unit))) //endif set ancient_attack_running = false + set creep = null return endif endif @@ -12185,8 +12185,9 @@ function SingleMeleeAttackAM takes boolean needs_exp, boolean has_siege, boolean set item_attack_running = true call FormGroupAM(3) if item_exp_state == 1 then - call AttackMoveKillCreep(GetExpFoe()) + call AttackMoveKillCreep(GetExpFoe(creep)) set item_attack_running = false + set creep = null elseif item_exp_state > 0 then call AttackMoveKillXYAAM(R2I(GetLocationX(item_exp_guard_loc)),R2I(GetLocationY(item_exp_guard_loc))) //Prevent the army from leaving before using the item , so no set item_attack_running endif @@ -12228,7 +12229,7 @@ function SingleMeleeAttackAM takes boolean needs_exp, boolean has_siege, boolean return endif endif - set creep = GetExpFoe() + set creep = GetExpFoe(creep) if creep != null and UnitAlive(creep) then call Trace("Creep the Expansion") set attacking_expansion = true @@ -12663,7 +12664,7 @@ function universal_attack_sequence takes nothing returns nothing endif set most_threatened_town = Max(most_threatened_town,0) if major_hero == null or not UnitAlive(major_hero) or not IsStandardUnit(major_hero) or (IsUnitType(major_hero, UNIT_TYPE_HERO) == false and ver_heroes) then - set major_hero = GetMajorHero() + set major_hero = GetMajorHero(major_hero) endif set needs_exp = take_exp and (ai_strength > exp_strength) diff --git a/races.eai b/races.eai index e7c60562d..fd69c85cb 100644 --- a/races.eai +++ b/races.eai @@ -45,7 +45,6 @@ globals integer wave = 1 boolean peons_assigned = false - boolean take_all_ghouls_along = false endglobals