by Sajt » Fri Jul 22, 2005 9:13 pm
I haven't really ever looked at the Quake AI code to much extent, but I think the function you're looking for is FindTarget. Be warned however that monsters sighting monsters will be slower than monsters sighting players, because vs players they can use a fast PVS solution, but the Quake builtins don't have a function to check for anything other than clients by PVS. Therefore you must use find() or findradius() (the sighting players code used checkclient()).
checkclient will return a client in the current PVS of 'self'. If there is more than one client in the PVS, it will cycle through them each time it is called, or each frame, or every 0.1 seconds or something (not sure), so every time you call checkclient() you will get the next player in the PVS.
Instead of that you will probably have to do something such as
ent = findradius (self, 1024);
while (ent != world)
{
if ((ent.flags & FL_MONSTER || ent.classname == "player") && ent.classname != self.classname)
{
// traceline for line of sight, check dot-product for FOV/facing, whatever else you want to do
// if true, set the target or whatever the ai does
}
ent = ent.chain;
}
You can change the 1024 to a higher number for a longer-range vision, but it may be slower. The MAIN thing to remember when using findradius like this is to call it as sparsely as possible, and try not to have 10 guys calling it at once. Perhaps make them check for opponents every 0.2 - 0.5 seconds or so. And try to spread out think times by setting the initial thinktime with an additional random factor. This may take some modifications to the AI code though, because I think currently AI is tied to animation (i.e. animation calls ai_stand() which calls FindTarget if there is no enemy). Perhaps you could make only every other stand frame, and every other walk frame, etc, call ai_stand/ai_walk.
Not sure if that helped at all...
Last edited by
Sajt on Sat Jul 23, 2005 7:07 am, edited 1 time in total.
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.