Skip to content

Commit

Permalink
Bring in reviewed changes of pr181
Browse files Browse the repository at this point in the history
  • Loading branch information
SMUnlimited committed Nov 5, 2023
1 parent b051a31 commit 141b94c
Show file tree
Hide file tree
Showing 17 changed files with 369 additions and 329 deletions.
41 changes: 19 additions & 22 deletions Jobs/ANCIENT_EXPANSION.eai
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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))
Expand Down
15 changes: 10 additions & 5 deletions Jobs/ANCIENT_EXPANSION_CHECK.eai
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions Jobs/BUY_ITEM.eai
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
94 changes: 47 additions & 47 deletions Jobs/BUY_NEUTRAL.eai
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -88,25 +90,23 @@ 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
set buy_time_small[nn] = current_time
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
85 changes: 45 additions & 40 deletions Jobs/BUY_NEUTRAL_HERO.eai
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit 141b94c

Please sign in to comment.