Skip to content

Commit

Permalink
Teleport will not cancel attacks unless it is the main attack force
Browse files Browse the repository at this point in the history
Plus some optimizations to flee rules
  • Loading branch information
SMUnlimited committed Dec 5, 2024
1 parent 25bd5dd commit 995f581
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
19 changes: 7 additions & 12 deletions HeroFleeRules.ai
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,18 @@
//call ActionRule2(true, ACTION_TP, (1 - hero_hp[hn])*15, ACTION_ZEPPELIN_FOUNTAIN, (1 - hero_hp[hn])*25)

call ActionRule2(hero_hp_loss[hn] > 0.5, ACTION_TP, 40, ACTION_ZEPPELIN_HOME, 15)
call ActionRule2((hero_enemy_density[hn] > 5) and (hero_hp_loss[hn] > 0.4), ACTION_TP, 200, ACTION_ZEPPELIN_HOME, 150)
call ActionRule2((hero_enemy_density[hn] > 2.5) and (hero_hp_loss[hn] > 0.4), ACTION_TP, 200, ACTION_ZEPPELIN_HOME, 150)
call ActionRule(hero_enemy_density[hn] > 2.5 and DistanceBetweenPoints(hero_dir[hn],hero_loc[hn]) <= 225, ACTION_TP, 200)
//call ActionRule(true, ACTION_TP, DistanceBetweenPoints(home_location, l)*0.006)

// Only here as a backup as getdensities may not totally be working correctly
if armyOfHero >= 0 then
call ActionRule(GetLocationNonCreepStrength(GetLocationX(l), GetLocationY(l), 1500) * 2 < army_strength[armyOfHero] , ACTION_TP, -100000)
endif

call ActionRule(DistanceBetweenPoints(home_location, l) < 2000 and (hero_enemy_density[hn] > 1), ACTION_TP, -100)
call ActionRule(DistanceBetweenPoints(home_location, l) < 2000 and (hero_enemy_density[hn] < 1), ACTION_TP, -1000000)
call ActionRule(town_threatened, ACTION_TP, -100000)
call ActionRule(town_threatened, ACTION_TP, -100000) // town threatened handled outside of these rules

//call ActionRule(DistanceBetweenPoints(home_location, l) < 2500, ACTION_TP, -1000000)
//if armyOfHero >= 0 then
//call ActionRule( army_strength[armyOfHero] < teleport_army_min_strength ,ACTION_TP, -100)
if armyOfHero >= 0 then
call ActionRule( army_strength[armyOfHero] < teleport_army_min_strength ,ACTION_TP, -10)
//call ActionRule( army_strength[armyOfHero] < enemy_strength_sum, ACTION_TP, -1000000)
//endif
endif
//call ActionRule3(true, ACTION_TP, (I2R(GetHeroLevel(hero_unit[hn]))*14)-20, ACTION_ZEPPELIN_HOME, I2R(GetHeroLevel(hero_unit[hn]))*8, ACTION_ZEPPELIN_FOUNTAIN, I2R(GetHeroLevel(hero_unit[hn]))*6)

// Rules of action failure
Expand All @@ -40,5 +35,5 @@
call ActionRule(nearest_neutral[NEUTRAL_MANA_FOUNTAIN] == null and nearest_neutral[NEUTRAL_POWER_FOUNTAIN] == null, ACTION_MANA_FOUNTAIN, -1000000)
call ActionRule2(not neutral_available[hFountainID] or (neutral_guarded[hFountainID] and (not neutral_night_buy[hFountainID] or (daytime > 6 and daytime < 18))) or GetLocationNonCreepStrength(GetUnitX(nearest_neutral[hFountainID]), GetUnitY(nearest_neutral[hFountainID]), 1500) > 0 , ACTION_FOUNTAIN, -1000000.0, ACTION_ZEPPELIN_FOUNTAIN, -1000000.0)
call ActionRule(not neutral_available[mFountainID] or (neutral_guarded[mFountainID] and (not neutral_night_buy[mFountainID] or (daytime > 6 and daytime < 18))) or GetLocationNonCreepStrength(GetUnitX(nearest_neutral[mFountainID]), GetUnitY(nearest_neutral[mFountainID]), 1500) > 0 , ACTION_MANA_FOUNTAIN, -1000000.0)
call ActionRule(GetItemNumberOnUnit(tp_item, hero_unit[hn]) <= 0, ACTION_TP, -1000000)
call ActionRule(GetItemNumberOnUnit(tp_item, hero_unit[hn]) <= 0 or teleporting, ACTION_TP, -1000000)
call ActionRule(healer == null, ACTION_HEALER, -1000000)
35 changes: 20 additions & 15 deletions Jobs/MICRO_HERO.eai
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,23 @@ function GetDensities takes location l, player p, real r returns nothing
set loc = null
endfunction

function GoHomeIfMainHero takes unit u, real x, real y returns nothing
if IsUnitInGroup(u, army_group[main_army]) then
call CaptainGoHome() // Retreat attack captain.
call TeleportCaptain(x, y)
set break_attack = attack_running
set isfleeing = true
set attack_running = false
endif
endfunction

function TeleportHome takes integer hn returns nothing
local integer i = 0
local real dx = GetLocationX(captain_home)
local real dy = GetLocationY(captain_home)
if teleporting then
return
endif
if not captain_tp then // can't teleport here so just go home
if home_town >= 0 and town_can_tp[home_town] then
set dx = GetLocationX(town_loc[home_town])
Expand All @@ -106,12 +119,8 @@ function TeleportHome takes integer hn returns nothing
set dy = GetLocationY(home_location)
endif
endif
call CaptainGoHome() // Retreat attack captain home
call TeleportCaptain(dx, dy)
call GoHomeIfMainHero(hero_unit[hn], dx, dy)
call UnitUseItemPoint(hero_unit[hn], GetItemOfTypeOnUnit(tp_item, hero_unit[hn]), dx + GetRandomInt(300,500) * ISign(), dy + GetRandomInt(300,500) * ISign())
set break_attack = attack_running
set isfleeing = true
set attack_running = false
set teleporting = true
if teleportloc != null then
call RemoveLocation(teleportloc)
Expand Down Expand Up @@ -161,12 +170,11 @@ endfunction

function TeleportToLoc takes unit u, location l returns nothing
local location loc = GetTeleportLandPoint(l)
set break_attack = attack_running
set isfleeing = true
set attack_running = false
if teleporting then
return
endif
call GoHomeIfMainHero(u, GetLocationX(loc), GetLocationY(loc))
set teleporting = true
call CaptainGoHome() // Retreat attack captain.
call TeleportCaptain(GetLocationX(loc), GetLocationY(loc))
call UnitUseItemPoint(u, GetItemOfTypeOnUnit(tp_item, u), GetLocationX(loc), GetLocationY(loc))
call TQAddUnitJob(0.5, TELEPORT, 0, u)
call RemoveLocation(loc)
Expand Down Expand Up @@ -246,7 +254,7 @@ function ExecuteSaveHero takes integer hn, integer a, unit healer returns nothin
call GroupAddUnit(unit_healing, hero_unit[hn])
call TQAddGroupJob(0, ZEPPELIN_MOVE, ZTARGET_FOUNTAIN, hero_unit[hn], g)
set g = null
elseif a == ACTION_TP then
elseif a == ACTION_TP and not teleporting then
call CreateDebugTag("Hero: Town Portalling", 10, hero_unit[hn], 4.00, 2.00)
call TeleportHome(hn)
elseif a == ACTION_MOONWELLS then
Expand Down Expand Up @@ -315,6 +323,7 @@ function MicroHeroJob takes integer hn returns nothing
if (not teleporting and (current_order >= 852008 and current_order <= 852013)) or current_order == OrderId("massteleport") then
if (current_order != OrderId("massteleport") and GetItemTypeId(UnitItemInSlot(hero_unit[hn], current_order - 852008)) == old_id[tp_item]) or (current_order == OrderId("massteleport") and GetUnitAbilityLevel(hero_unit[hn], 'AHmt') > 0) then
call CreateDebugTag("HERO: Already teleporting", 10, hero_unit[hn], 4.00, 2.00)
call GoHomeIfMainHero(hero_unit[hn], GetLocationX(home_location), GetLocationY(home_location))
if not teleporting and teleportloc != null then // unknown destination as was triggered by hardcoded logic
call RemoveLocation(teleportloc)
set teleportloc = null
Expand Down Expand Up @@ -347,10 +356,6 @@ function MicroHeroJob takes integer hn returns nothing
return
endif
endif
if not teleporting and hero_enemy_density[hn] > 5 and IsUnitInGroup(hero_unit[hn], unit_healing) and DistanceBetweenPoints(hero_dir[hn],hero_loc[hn]) <= 225 then
call CreateDebugTag("HERO: Surround Detection Teleportation", 10, hero_unit[hn], 4.00, 2.00)
call TeleportHome(hn)
endif
endif
call TQAddJob(1 * sleep_multiplier, MICRO_HERO, hn)
//call DisplayToAll("MICRO_HERO END")
Expand Down

0 comments on commit 995f581

Please sign in to comment.