Skip to content

Commit

Permalink
General BR logic fixes and ensure we check creep strength before atta…
Browse files Browse the repository at this point in the history
…cking #440
  • Loading branch information
SMUnlimited committed Nov 21, 2024
1 parent b1ca87b commit f0d497c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
44 changes: 18 additions & 26 deletions common.eai
Original file line number Diff line number Diff line change
Expand Up @@ -5882,9 +5882,6 @@ function BuildBRAtCreep takes nothing returns boolean
local unit array uc
local location loc = null
local boolean success = false
if GetRandomInt(1, 100) <= race_ancient_barracks_rush_chance then
return false
endif
call Trace("Build Ancient Barracks for creeping")
set g = CreateGroup()
call GroupEnumUnitsInRange(g,GetLocationX(home_location), GetLocationY(home_location),distance,null)
Expand Down Expand Up @@ -11725,21 +11722,23 @@ function FromGroupAndGhoulsAM takes integer seconds returns nothing
endfunction

//============================================================================
function EnableRetreatControl takes nothing returns nothing
set break_attack = false
if not retreat_controlled then
call Trace("===Retreat control started===")
set retreat_controlled = true
call SetGroupsFlee(false)
call SetTargetHeroes(false)
call TQAddJob(2 * sleep_multiplier, RETREAT_CONTROL, 0)
endif
endfunction

function DoAttackJobs takes nothing returns nothing
if major_hero == null or not UnitAlive(major_hero) then
set major_hero = GetMajorHero(major_hero)
endif
set battle_radius = normal_battle_radius
set break_attack = false
//if major_hero != null and UnitAlive(major_hero) then
if not retreat_controlled then
call Trace("===Retreat control started===")
set retreat_controlled = true
call SetGroupsFlee(false)
call SetTargetHeroes(false)
call TQAddJob(2 * sleep_multiplier, RETREAT_CONTROL, 0)
endif
//endif
call EnableRetreatControl()
endfunction

//============================================================================
Expand Down Expand Up @@ -12116,6 +12115,7 @@ function BRRush takes nothing returns boolean
if i != 1 and utemp != null and GetUnitState(utemp, UNIT_STATE_LIFE) >= GetUnitState(utemp, UNIT_STATE_MAX_LIFE) * 0.65 then
call Trace("Ancient Barracks Creep Rush Attack")
set attack_running = true
call EnableRetreatControl()
set br_rush_attacked = true
set buildloc = GetUnitLoc(utemp)
call RemoveGuardPosition(utemp)
Expand Down Expand Up @@ -12182,15 +12182,9 @@ function AttackMoveKillCreep takes unit target, boolean ally_override returns no
call Sleep(3 * sleep_multiplier)
return
endif
call FromGroupAndGhoulsAM(3)
set attack_running = true
set break_attack = false
if not retreat_controlled then
call Trace("===Retreat control started===")
set retreat_controlled = true
call SetGroupsFlee(false)
call SetTargetHeroes(false)
call TQAddJob(2 * sleep_multiplier, RETREAT_CONTROL, 0)
endif
call EnableRetreatControl()
call AttackMoveKill(target)
call ReformUntilTargetDeadAM(target, true, ally_override)
call Chat(C_Done)
Expand Down Expand Up @@ -12341,7 +12335,6 @@ function CreepAttack takes integer str returns nothing
if air_strength > 15 then
call SetAllianceTargetIfLeadAndChat(target, C_Creep)
endif
call FormGroupAM(3)
call AttackMoveKillCreep(target, true)
call ClearAllianceTarget(target)
set target = null
Expand Down Expand Up @@ -13011,7 +13004,6 @@ function SingleMeleeAttackAM takes boolean needs_exp, boolean has_siege, integer
elseif ancient_exp_state == 4 then
set ancient_attack_running = true
call Trace("An Ancient Expansion - Final stage")
call FromGroupAndGhoulsAM(3)
//call AddAssault(1, old_id[racial_hall[1]])
call SetCaptainHome(BOTH_CAPTAINS,GetUnitX(ancient_exp_unit),GetUnitY(ancient_exp_unit))
set creep = GetExpFoe(creep)
Expand All @@ -13031,12 +13023,13 @@ function SingleMeleeAttackAM takes boolean needs_exp, boolean has_siege, integer
if item_expanding then
call Trace("An Item Expansion Attack or Guard")
set item_attack_running = true
call FromGroupAndGhoulsAM(3)

if item_exp_state == 1 then
call AttackMoveKillCreep(GetExpFoe(creep), false)
set item_attack_running = false
set creep = null
elseif item_exp_state > 0 then
call FromGroupAndGhoulsAM(3)
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
return
Expand Down Expand Up @@ -13070,7 +13063,6 @@ function SingleMeleeAttackAM takes boolean needs_exp, boolean has_siege, integer
set attacking_expansion = true
set battle_radius = creep_battle_radius
call SetAllianceTargetIfLeadAndChat(creep, C_Expansion)
call FromGroupAndGhoulsAM(3)
call AttackMoveKillCreep(creep, false)
call ClearAllianceTarget(creep)
if creep == null or not UnitAlive(creep) then
Expand Down Expand Up @@ -13153,7 +13145,7 @@ function SingleMeleeAttackAM takes boolean needs_exp, boolean has_siege, integer
//
set battle_radius = creep_battle_radius

if rushcreep_target != null and UnitAlive(rushcreep_target) then
if rushcreep_target != null and UnitAlive(rushcreep_target) and GetLocationCreepStrength(GetUnitX(rushcreep_target), GetUnitY(rushcreep_target), 510) < own_strength + 5 then // Matches getOwnStrength +5 addition for ancient
call Trace("ELF BR Attack")
if BRRush() then
return
Expand Down
3 changes: 3 additions & 0 deletions races.eai
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ function initRacialUnits takes nothing returns nothing
#INCLUDETABLE <$VER$\StandardUnits.txt> #COND "%3" eq "$RACE$" and "%4" =~ /\brushcreep\b/
if difficulty != EASY then
set racial_rushcreep = %1 // EASY build one , Impact Development
if GetRandomInt(1, 100) > race_ancient_barracks_rush_chance then
set br_rush_built = true // This disables the rush this time
endif
endif
#ENDINCLUDE

Expand Down

0 comments on commit f0d497c

Please sign in to comment.