Page 1 of 1
Group AI question
Posted: 17 May 2006, 14:11
by colorblind
I want to make a group AI that alerts the player whenever an enemy unit enter LOS / radar. I wondered if I could use the function
Code: Select all
virtual void EnemyEnterRadar(int enemy)=0;
in /trunk/rts/ExternalAI/IGlobalAI.h for that, even though it belongs to the global AI class and not to the group AI class.
If that isn't allowed, I'll probably have to use
Code: Select all
virtual int GetEnemyUnitsInRadarAndLos(int *units)=0;
in /trunk/rts/ExternalAI/IAICallback.h, but that'd be some more work (and I'm not too so how to go about it).
Some help and pointers would be appreciated, and flames about this group AI most defenitely not.
Posted: 17 May 2006, 14:39
by AF
You couldnt use functions formt eh globalAI itnerface in a groupAI
Your best bet is keep a map of all units you know about as in map<int,bool> having a true for in LOs and false for nto in LOS
Then you'd issue an entered alert whenever you changed from false -> true and a left alert on true ->false
However this is all problematic as in any game after so long you'll have a lto of alerts.
Also a group fo 5 units entering LOS at the same time will issue 5 alerts.
And the alerts arent to good if you cant press f3 to centre on them.
These can be avoided using the marker stuff that was added recently but then you have to delete those markers, and your allies cna see them and to delete them you end up deleting any nearby markers or lines the AI has drawn, even markers and lines the player put down.
Posted: 17 May 2006, 15:21
by colorblind
I don't think it will generate a whole lot of messages, as you can just do a check like
Code: Select all
if(lastLOSentertime > minTime){
do message
}
and
Code: Select all
if(lastLOSenterdistance > minDistance) {
do message
}
You just have to set minTime and minDistance to appropriate values.
But can you explain how you can put the information about enemy units into an array a bit more? Looking at /trunk/rts/ExternalAI/IGroupAI.h there are no such functions avaible, and isn't that the only header file you can include for a group AI?
Posted: 17 May 2006, 15:30
by AF
well, pseudocode::
Code: Select all
update(){
get all the enemy units in LOS and Radar
vector<int> last;
vector<int> temp
for every enemy unit{
add to temp vector<>
check if it's in the map<>
ifnot add it set the value tot rue and issue an alert!
if it is in the map
if map[unit] == false
add an alert
set equal to true
}
iterate through last{
if in last but not in temp
set map[unit] == false
}
clear last vector and fill it with temp vector<>
}
Posted: 17 May 2006, 16:22
by colorblind
Ok, I get that, but what exact function would you call to iterate through every enemy unit?
Posted: 17 May 2006, 16:25
by AF
erm
vector<int> container;
//do stuff to fill container with values
if(contianer.empty() == false){
for(vector<int>::iterator i = container.begin(); i != container.end() ++i){
char c[20];
sprintf(c,"%i",*i);
print(c);
}
}
would iterate through the vector container printing out the values.
Go read up on stl.
You may also find ti useful to look at the source for my groupAI's and XE8.
Posted: 17 May 2006, 17:02
by colorblind
It seems like I haven't made myself clear. I don't want to know how to iterate through a container, I would like to know how you'd fill them with enemyunits data.
I.E., how do you obtain the enemyunits data using a group AI?
Posted: 17 May 2006, 20:05
by AF
In exactly the same way you would in a globalAI
int* enemies = new int[1000];
int number_of_enemies = cb->gtenemyunits(enemies);
//do stuff
delete [] enemies;