diff --git a/Jobs.txt b/Jobs.txt index efdaa1013..a71fe95a6 100644 --- a/Jobs.txt +++ b/Jobs.txt @@ -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 diff --git a/Jobs/RESET_ANCIENT.eai b/Jobs/RESET_ANCIENT.eai new file mode 100644 index 000000000..3044872a0 --- /dev/null +++ b/Jobs/RESET_ANCIENT.eai @@ -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 \ No newline at end of file diff --git a/common.eai b/common.eai index defe26e0b..95e335cd7 100644 --- a/common.eai +++ b/common.eai @@ -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) @@ -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