PDA

View Full Version : Tower Targetting AI



LightRain
02-08-2010, 03:09 PM
Tower AI is not, as it may appear, and as many falsely claim, random, but is actually completely deterministic.

There are two layers of Tower AI: hero protection, and everything else.

Rule 1: The tower will attack any hero that attacks an enemy hero.*

*Spells don't count. This includes manually casting orbs (ie Vindicator's, Arachna's)!
"Attacking" means "starting your autoattack animation". Unlike with creeps, you can right click an enemy hero and not draw tower fire until your hero actually lifts his arm to attack. You can cancel your attack animation by moving, stopping, holding, etc. and still get shot by the tower.

Rule 2: The tower will attack nearby units, with priority given to units attacking it, and then to units closest to it.

Three things trigger a tower to check for new targets: Any unit attacks an ally hero in range; the current target dies or leaves the tower's range; a possible target enters the range of a tower which has no targets at the moment.
When the first trigger (attack on enemy hero) occurs, the tower checks what its current target is doing. If the current target is not actively attacking an enemy hero, it will switch to a new target.^ However, if the target has not stopped attacking a hero, the tower will continue to attack it.

The second trigger basically returns the tower to its neutral state. Then, if other heroes are still attacking heroes, the tower will pick a new, closest one. Otherwise, it will pick the closest unit that is attacking the tower and fire on it until it dies, leaves, or something attacks an ally hero; if nothing is attacking the tower at the moment, it will pick the closest unit and fire on it until it dies, leaves, or something attacks an ally hero.
If it runs out of targets, the tower waits for something to come in range, and fires on it.

^This means that if you and an ally are attacking an enemy hero under a tower and the tower is shooting at you, you can press Hold and wait until the tower fires on your ally. Then you can continue attacking, and the tower will continue to attack your ally unless your ally dies, leaves the range, is disabled, or presses Hold himself.

Now with video! Thanks to siknoz!

Here ya go, ran in practice mode literally about 15min ago, sorry I don't really do editing so you'll just have to take it as is.

1st vid - Vindicator at enemy tower
http://www.youtube.com/watch?v=xMbr8lTd-7E
1st set of attacks - Right-Clicked his Master's Incantation, notice that when this is set to auto-cast, that I draw aggro from the tower immediately
2nd set of attacks - Regular ranged attacks draw aggro immediately
3rd set of attacks - Individually casting\clicking Master's Incantation, in this I do not draw any aggro at all. I am also standing BEHIND my units so according to the AI it will not attack me because it will attack the closest or Lowest HP target, neither of which I am.

2nd vid since someone asked about it
http://www.youtube.com/watch?v=uV9S6jldJHA

Electrician's hold doesn't draw aggro, Pyromancer using all 3 spells within tower range, does not draw aggro. I lowered the fps on the vid a little bit so you can see the tower attacks a little better.

Hope this helps...
Made another quick vid to show some mechanics for the tower ai as well.

http://www.youtube.com/watch?v=dbzZpeAyHR8

Notes :

Segment 1 - Shows that you can attack the tower while the tower currently has a target, as long as you stop attacking before that creep dies, and as long as there is another unit that is closer to the tower than you, it will not attack you. This is good for when you want to put some damage on the tower but don't have insta-wave kill ability.

Segment 2 - If you continue to attack the tower, after the current target is dead, the tower will attack you.

Segment 3 - Tower will attack the CLOSEST ATTACKING target, which means that if you are attacking the tower with creep and YOU are the closest target, the tower will attack you.

Segment 4 - Even though you may be the closest target, if another unit is attacking the tower, the tower will target that unit first.

Hopefully the 3 vids I posted in the thread will answer most questions people had about the mechanics of towers in HoN.

practical experiments (reproducible):
Take for example this situation: Demented Shaman and some Hellbourne creeps approach a tower. The tower targets the first creep that gets in range and kills it, then picks another melee creep and targets it. Meanwhile Demented Shaman is attacking the tower.
Now, some Legion creeps come. The Hellbourne creeps switch to attacking the Legion creeps, while Demented Shaman continues to attack the tower. Because this isn't a Rule 1 trigger, Demented Shaman will not be shot at if the melee creep that is targeted is still alive. In fact, Shaman can keep that creep alive longer through healing and Arcane Hide in order to get even more attacks in on the Tower. However, when the creep is about to die, Demented Shaman should stop attacking the tower and let it acquire a new target before he continues to attack the tower - otherwise, the tower will attack him, and he will be forced to back away if he doesn't want to be shot at.

In another situation, Keeper of the Forest and two Forsaken Archers are attacking a Legion Succubus next to a Legion tower. (Training mode okay >.>) Tree moves in first and gets shot at by the tower for attacking Succubus. Then, the two Forsaken Archers (let's call 'em FA and FB) move in and begin attacking Succubus. Now, the tower will continue to attack Tree until I press the Kill! button and he dies. Then, because FA is closer to the tower, the tower attacks FA. Now if FA presses hold and waits for FB to continue attacking Succ, the tower will attack FB. FA can then continue attacking Succ without getting shot at, even though she is closer to the tower, until FB gets Mesmerized by Succ. At that point FA will be the only one attacking Succ, and she will be fired upon.

Credit goes to Meowshi's guide to Heroes of Newerth Basics (http://forums.heroesofnewerth.com/showthread.php?t=5465) for the basic info, and to those who questioned me and got me to investigate further. As always, any feedback and independent information is appreciated.
I maintain an open call for any replays, videos, or other such evidence that contradicts anything in here.

I am aware of the issue of it switching targets between creeps and... guess what! siknoz to the rescue!
Ok, I finished the video, I even added in a bonus for ya ^_-

In the first segment it basically does what you said it does. Exactly the way I explained, since the ranged creep was technically the FIRST unit to attack me, the tower switched from the melee to the ranged.

In the second segment it shows that I can manipulate it and make it attack a different melee creep too. Notice the melee creep attacks me before any other units do, so the tower switches from its current target, to the attacking target.

http://www.youtube.com/watch?v=kHYplTAGVwI

Enjoy..hopefully this answered Cordial's question.

Also if you want to avoid having the tower switch targets, simply move up enough to allow the melee creep to attack you(actually swing at you), after that the tower target will be LOCKED and won't change.

Rabbagast
02-08-2010, 03:24 PM
good research well written.

ElementUser
02-08-2010, 04:28 PM
Nice :)

BrownieMcHob
02-20-2010, 11:29 AM
I thought this was pretty common knowledge

LightRain
02-20-2010, 08:38 PM
I thought this was pretty common knowledge

After the twentieth time I read a post saying the tower ai was all f'ed up and random, I made this guide. It actually took a bit of research, because A) the weird way it will occasionally switch targets on creeps, which is a creep ai thing and not a tower ai thing, and B) the fact that it doesn't switch off a nearby, non-aggressive target of something else attacks the tower is not obvious.

Wize
03-03-2010, 07:25 PM
Why cant we do the trick we used to be able to do in Dota? That is, issuing an attack command on ANY allied unit (on any hp) will force the tower to stop attacking you, provided it has another target to acquire...

ElementUser
03-03-2010, 07:38 PM
Why cant we do the trick we used to be able to do in Dota? That is, issuing an attack command on ANY allied unit (on any hp) will force the tower to stop attacking you, provided it has another target to acquire...

Actually that doesn't work 100% of the time in DotA too - though it works like 50% of the time now from my experiences in DotA

LightRain
03-04-2010, 06:26 AM
Someone asked about that in the first thread. Simple answer is they didn't code that in.

Cordial
03-04-2010, 05:03 PM
This question has not been solved yet:
Why do towers switch target from a melee creep (with health left) to a ranged creep when you advance the tower and draw creep aggro? This never happened in DotA and I've lost a lot of creep kills due to it...

Similar question has been asked by Vulpes in the longer thread:

Ok, so how do you explain the tower shooting twice at a Melee Creep and then switching to another?
It happens quite regularly, most often if none of my Creeps are nearby.

3 Melee Creeps are attacking the tower, I come to pull them away from it, Tower kills the one he shot at first, two left.
He shoots two times at one Creep, I wait for the third shot to hit so I can last hit (while I am running in circles around the tower).
Then it shoots & proceeds to kill the last Melee left, without any apparent reason.

E: Good Stuff of course. Just the Creep thingie really bugs me..

LokoLoko
03-04-2010, 05:32 PM
Actually that doesn't work 100% of the time in DotA too - though it works like 50% of the time now from my experiences in DotA

Which means u can click A + attack two times in less than a second and it'll work 100%, basically. Not exactly a great point there sir :D

ElementUser
03-04-2010, 05:37 PM
Which means u can click A + attack two times in less than a second and it'll work 100%, basically. Not exactly a great point there sir :D

No that's not what I meant, the AI is a bit buggy in DotA and even though I A+attack my allied creep MULTIPLE times, it fails to work (this is 50% of the times of the attempts in a certain timeframe). The other 50% of the time though it magically works (for some unknown reason).

I don't really like arguing semantics btw

LightRain
03-04-2010, 06:52 PM
I've been able to reproduce but not explain it with a hero that's moving. When your hero stands still and doesn't move, I have not been able to reproduce it. I plan to test that a bit more (and also test this HP thing that was in DOTA) when I have time this weekend (this computer can't run HoN)

siknoz
03-04-2010, 07:34 PM
I've been able to reproduce but not explain it with a hero that's moving. When your hero stands still and doesn't move, I have not been able to reproduce it. I plan to test that a bit more (and also test this HP thing that was in DOTA) when I have time this weekend (this computer can't run HoN)

If you ran the practices in a slower time scale you can see why this is. And to answer the previous question about why does the tower switch target I will try to explain, if anyone sees a flaw, or knows specific coding that I don't have access to please rebut.

When a tower is targeting a unit, it runs through its lines of priority. To start, take heroes out of the equation.

A) Tower will attack the CLOSEST target, so if you take out a creep wave(legion) instantly, and a wave(hellbourne) is approaching the tower, the FIRST unit that comes within attack range of the tower will be "locked" and attacked. This will not change UNLESS changed by a hero(I will explain in a min). After that first target is dead, it will run through its priority again(at this time there is 4-5 creep within range), so the list broadens, now it will target the lowest HP creep possible. If all are the same, then the closest one will be targeted.

You allow the units to attack the tower first, all melee, all ranged attack the tower, you move up to draw aggro and you move back or circle around the tower. In this case, if you manage to aggro ALL creep in the area, they all only have a "lock" target (you) but none have actually attacked. Apparently there is a difference between the "lock" and the actual "attack". Of course while this is all happening the tower is attacking the melee creep(the first one that came up to the tower) but after they have shifted and "locked" on the hero, they start moving towards the hero, *IF* the ranged creep is the first to ATTACK the hero, then the ATTACK command takes precedence over the "LOCK" command. This is why the tower suddenly switches from the melee creep that isn't dead yet, to the ranged creep. Because the ranged creep is actually ATTACKING the hero, while the melee creep technically aren't. The tower's FIRST priority is to attack units that are ATTACKING the hero.

B) Now we will add heroes into the mix. Lets say you are defending the tower and try to pull the creep away from it. Here is where it gets tricky,

If an enemy hero comes to the tower and either 1) attacks the hero or 2) attacks the tower long enough to draw aggro then the creep will switch from you, back to the tower. However sometimes the ranged creep does not switch to the tower depending on the range of the creep in reference to the enemy hero and the tower. So if that happens, again the 1st scenario I outlined above will take place and the tower will switch to the ranged creep again(if its the only unit attacking you).

This works 100% of the time in practice mode. I will try to get another video that shows a clear example.

siknoz
03-04-2010, 08:17 PM
Ok, I finished the video, I even added in a bonus for ya ^_-

In the first segment it basically does what you said it does. Exactly the way I explained, since the ranged creep was technically the FIRST unit to attack me, the tower switched from the melee to the ranged.

In the second segment it shows that I can manipulate it and make it attack a different melee creep too. Notice the melee creep attacks me before any other units do, so the tower switches from its current target, to the attacking target.

http://www.youtube.com/watch?v=kHYplTAGVwI

Enjoy..hopefully this answered Cordial's question.

Also if you want to avoid having the tower switch targets, simply move up enough to allow the melee creep to attack you(actually swing at you), after that the tower target will be LOCKED and won't change.

Vulpes
03-04-2010, 08:25 PM
Which means u can click A + attack two times in less than a second and it'll work 100%, basically. Not exactly a great point there sir :D

That's the first time someone beyond grade school told me 2x 50% is 100%. If you toss a coin twice, probability for heads is 100%, eh?

E: Thanks to siknoz for clearing that up nicely. :) Might try to "abuse" that.

Cordial
03-04-2010, 08:27 PM
It did answer my question, thank you :).
Harder to get gold for the ranged creep but instead offer opportunities to manipulate the tower.

siknoz
03-04-2010, 08:34 PM
It did answer my question, thank you :).
Harder to get gold for the ranged creep but instead offer opportunities to manipulate the tower.

What kind of monster have I unleashed :P

LightRain
03-04-2010, 09:07 PM
Awesome. Simply awesome. Someone give this man a puzzlebox.

MacroHard
05-08-2010, 12:35 PM
Three things trigger a tower to check for new targets: Any unit attacks an ally hero in range; the current target dies or leaves the tower's range; a possible target enters the range of a tower which has no targets at the moment.

Did you mean "any unit attacks an ally hero in range"? or "any unit in range attacks an ally hero"? Or are both true?

Situation A:
Legion Hero close to Hellbourne tower. Legion Hero is not current target of tower. Legion Hero right clicks a Hellbourne hero across the map. Would this trigger the tower AI (causing tower to attack Legion hero)?

Situation B:
Legion Hero at Legion well. Legion Hero right clicks a Hellbourne hero near Hellbourne tower. Would this trigger the tower AI (causing tower to attack a new Legion creep)?

If Situation B is the case, this could explain some of the wacky change of hearts that towers seem to exhibit... an unseen enemy is unknowingly messing with your tower's AI from across the map!

LightRain
05-08-2010, 11:49 PM
Most anomalies involve creep following ai and are nicely explained, or at least demonstrated, by siknoz.

I'm pretty sure it should be "any unit in tower range attacks an ally hero" but I might as well test it to be sure. Thanks!

Rapid
05-10-2010, 03:09 PM
Every dota player with exp. should know this.
but thanks its useful in some ways :))

Tweak
05-10-2010, 03:44 PM
Situation A: No, the hero you set the attack command on has to be in range of the tower also (I'm pretty sure, will have to test when I get home)
Situation B: No that would be crazy :)

LightRain
05-11-2010, 04:33 PM
Every dota player with exp. should know this.
but thanks its useful in some ways :))

haha, right? but people would always be posting that the ai was wonky.
also dota players should know that the attack-allied-creep trick doesn't work.

moosef
07-03-2010, 02:37 PM
thank you for this very helpful guide!