Page 1 of 1

Detecting which unit killed another one

Posted: 27 Oct 2005, 13:17
by submarine
To be able to implement some basic learning system for my ai, i want the ai to store information about which unit types get often killed and which often kill others.

the first thing is not a problem, but is there any way to do the second one?
there is EnemyDestroyed(int enemy), but theres no direct information about the killer

is it possible to get the killer from the the unit id?


if not, i would like to request this to be added to the ai interface, because i think it is very important for learning ais...

Posted: 27 Oct 2005, 13:22
by jcnossen
But isn't it more important which enemy is actually doing the damage? I think you first get a call to UnitDamaged anyway, so you could check if it's a lethal damage.

Posted: 27 Oct 2005, 13:28
by submarine
that means i would have to check it every time, damage is beeing dealt to a unit - isn´t that a waste of cpu power?

at first, i wanted to keep it very simple:
if a unit gets killed by another type, the effincy of the killer is increased a little bit and vice versa for the killed unit. the increase would be based on the costs of both killer and killed unit, so that stronger units don´t get higher values by killing lots of pewees.

of course, this is not reflecting all situations in the game properly (as by chance even a pewee could kill a krogoth) but i want to experiment on the results of that algorithm after a long playtime

Posted: 27 Oct 2005, 13:43
by jcnossen
that means i would have to check it every time, damage is beeing dealt to a unit - isn´t that a waste of cpu power?
I doubt you could even measure a drop in fps or something. The UnitDamaged call is being done anyway, so you might as well use it.

Posted: 27 Oct 2005, 13:51
by submarine
ok agreed,

but this still only provides my ai with information about enemy killers, it´s necessary to get the own killers as well...

theres only enemydestroyed(int enemy), but i don´t know how to get the killer from that


edit: its not absolutely necessary, but it´ll take more time to get sensible values and there must be ais of different sides

Posted: 27 Oct 2005, 15:18
by jcnossen
Ok I see your point, but there afaik there is no easy way to make EnemyDestroyed(unit,killer), because I don't think the killer unit is known in the unit destructor.

EnemyDamaged would be a lot easier though, but in any case, I have no time right now, so it will have to wait.

Posted: 27 Oct 2005, 15:23
by submarine
i just talked to sj, he proposed to use the units experience instead; i´m not quite happy with that, so im thinking of etending the ai interface..

what do other ai devs think about it?

Posted: 03 Nov 2005, 17:57
by Veylon
Here, just do this. Ugly, but should work and quickly:

Code: Select all

int UnitAttacker[10000];

void CGlobalAI::UnitDamaged(int Damaged, int Attacker, etc.)
{
   UnitAttacker[Damaged] = Attacker;
}

void CGlobalAI::UnitDestroyed(int Unit)
{
   int KilledBy = UnitAttacker[Unit];
}
You can do the STL way too, with a set if you want...

Posted: 03 Nov 2005, 20:26
by submarine
i (or zaphod to be more precisely) updated spring cvs so it now provides the attacker in EnemyDestroyed and UnitDestroyed