Skip to content

Commit

Permalink
Fix for BR Ancient Rush to ensure the barracks always eventually reroots
Browse files Browse the repository at this point in the history
  • Loading branch information
SMUnlimited committed Dec 6, 2024
1 parent 0644947 commit a64f75b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
1 change: 1 addition & 0 deletions Jobs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ BUILD_EXPANSION 10 BuildExpansionJob(unit_par, unit_par2) false 0 0
ITEM_EXPANSION 20 ItemExpansionJob() false 0 0
ITEM_EXPANSION_CHECK 30 ItemExpansionCheck() false 0 0
ITEM_REPEAT_CHECK 160 ItemRepeatCheck() true 200 220
RESET_ANCIENT 10 ResetAncient(unit_par) false 0 0
50 changes: 50 additions & 0 deletions Jobs/RESET_ANCIENT.eai
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#IFDEF GLOBAL
real lastancientx = -1
real lastancienty = -1
integer retry = 0

#ELSE

//Only 1 ancient reset can run at a time
function ResetAncient takes unit u returns nothing
local unit buildu = null
local real buildx = 0
local real buildy = 0
local integer i = 0

if not UnitAlive(u) then
return
endif

if UnitAlive(u) and GetUnitCurrentOrder(u) != OrderId("root") and retry < 2 then
set i = Max(GetRandomInt(0, front_loc_num - 1),0)
if front_locs_computed and front_loc[i] != null then
set buildu = CreatePathingUnitFull(buildu, ai_player, GetUnitTypeId(u), GetLocationX(front_loc[i]) + ISign() * GetRandomReal(0, 300), GetLocationY(front_loc[i]) + ISign() * GetRandomReal(0, 300))
else
set buildu = CreatePathingUnitFull(buildu, ai_player, GetUnitTypeId(u), GetLocationX(home_location) + ISign() * GetRandomReal(500, 750), GetLocationY(home_location) + ISign() * GetRandomReal(500, 750))
endif
set buildx = GetUnitX(buildu)
set buildy = GetUnitY(buildu)
call RemoveUnit(buildu)
set buildu = null
call IssuePointOrder( u, "root", buildx, buildy)
set retry = retry + 1
elseif GetUnitCurrentOrder(u) != OrderId("root") and retry >= 2 and (GetUnitX(u) != lastancientx or GetUnitY(u) != lastancienty) then
// if moving then not rooted
set retry = 1
elseif GetUnitCurrentOrder(u) != OrderId("root") and retry >= 2 and (GetUnitX(u) == lastancientx and GetUnitY(u) == lastancienty) then
// Root done as not moved
call RecycleGuardPosition(u)
elseif retry > 0 and GetUnitX(u) != lastancientx or GetUnitY(u) != lastancienty then
// moving so all good
set retry = 1
endif

set lastancientx = GetUnitX(u)
set lastancienty = GetUnitY(u)

call TQAddUnitJob(10, RESET_ANCIENT, 0, u)

endfunction

#ENDIF
8 changes: 3 additions & 5 deletions common.eai
Original file line number Diff line number Diff line change
Expand Up @@ -12360,7 +12360,7 @@ function BRRush takes nothing returns boolean
set br_rush_attacked = true
set buildloc = GetUnitLoc(utemp)
call RemoveGuardPosition(utemp)
call IssueImmediateOrderById(utemp, 851976) // Cancel building order
call IssueImmediateOrderById(utemp, OrderIdCancel) // Cancel building order
call IssueImmediateOrder(utemp, "unroot") //try unroot
call FromGroupAndGhoulsAM(3) // unroot time
set loc = GetUnitLoc(rushcreep_target)
Expand All @@ -12369,13 +12369,11 @@ function BRRush takes nothing returns boolean
set loc = null
call AttackMoveKill(rushcreep_target)
call ReformUntilTargetDeadAM(rushcreep_target, true, false)
call Chat(C_Done)
call SleepInCombatAM(false)
call Chat(C_Done)
call Trace("===BR Finished===")
call IssuePointOrderLoc( utemp, "move", buildloc) //prevent inability cannot root
call Sleep(0.02)
call IssuePointOrderLoc( utemp, "root", buildloc) //root tree
call TQAddUnitJob(GetTimeToReachLoc(utemp, buildloc) + 2, RESET_GUARD_POSITION, 0, utemp)
call TQAddUnitJob(0.02, RESET_ANCIENT, 0, utemp)
call RemoveLocation(buildloc)
set buildloc = null
endif
Expand Down

0 comments on commit a64f75b

Please sign in to comment.