Skip to content

Commit

Permalink
Fix captain go home logic #234
Browse files Browse the repository at this point in the history
  • Loading branch information
SMUnlimited committed Feb 24, 2024
1 parent 35a3593 commit 8ff8d8c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- AMAI does a better job collecting any items after creeping.
- (DevTools) Optimize.bat script is now called OptimizeAll.bat.
- Added build order so that Elf will now sometimes buy the moonstone and Humans will now buy lesser clarity potions.
- Optimizations to return home after an attack only when nessecary instead of all the time.

### Fixed
- Prevent desyncs with zoom function.
Expand Down
15 changes: 6 additions & 9 deletions common.eai
Original file line number Diff line number Diff line change
Expand Up @@ -11458,9 +11458,6 @@ function SleepInCombatAM takes nothing returns nothing
set count = count + 1
call Sleep(1)
endloop
if (not CaptainIsHome()) then
call CaptainGoHome()
endif
call Trace("exit SleepInCombat")
endfunction

Expand Down Expand Up @@ -12399,12 +12396,11 @@ function SleepUntilTownDefended takes integer ai_strength returns nothing
//call ClearCaptainTargets()
//call CaptainGoHome()
endif
if CaptainInCombat(true) then
if not CaptainIsHome() then
call CaptainGoHome()
endif
exitwhen not town_threatened
exitwhen not town_threatened and not TownThreatened() and not CaptainInCombat(false)
exitwhen player_defeated
exitwhen not CaptainInCombat(false)
call Sleep(2*sleep_multiplier)
set own_strength = GetOwnStrength()
endloop
Expand Down Expand Up @@ -12480,7 +12476,6 @@ function SingleMeleeAttackAM takes boolean needs_exp, boolean has_siege, boolean
set isfleeing = false
call FormGroupAM(1)
call SleepUntilTownDefended(ai_strength)
call SleepInCombatAM()
return
endif

Expand Down Expand Up @@ -13026,6 +13021,9 @@ function HealArmy takes nothing returns nothing
exitwhen player_defeated or town_threatened or ver_heroes == false
set mass_healed = false
call Trace("function HealArmy: Army is badly damaged and needs healing " + Real2Str(hs))
if (not CaptainIsHome()) then
call CaptainGoHome()
endif
set build_emergency_healing_item = 0
set mh_item = GetMassHealingItem()
if mh_item > 0 then
Expand Down Expand Up @@ -13133,12 +13131,11 @@ function universal_attack_sequence takes nothing returns nothing
call Sleep(1)
endloop

if town_threatened then
if town_threatened or TownThreatened() then // Attack has finished so any AMAI detections or hardcoded threat detections should be dealt with
set break_attack = false
set isfleeing = false
call FormGroupAM(1)
call SleepUntilTownDefended(ai_strength)
call SleepInCombatAM()
elseif not towerrush and not ancient_expanding and not militia_expanding and not item_expanding then
call SetCaptainHome(DEFENSE_CAPTAIN, GetLocationX(home_location), GetLocationY(home_location))
endif
Expand Down

0 comments on commit 8ff8d8c

Please sign in to comment.