Playing with monster hunting player

Discuss programming in the QuakeC language.
Post Reply
ajay
Posts: 559
Joined: Fri Oct 29, 2004 6:44 am
Location: Swindon, UK

Playing with monster hunting player

Post by ajay »

I'm basically tinkering with Find Target. The objectives are to do the following; on finding an enemy (the player) the monster does some checks before being able to pursue it.
1. Is it behind a wall (does the monster have line of sight) if no, then go after it, if yes, then check 2.
2. Is the player moving (therefore making noise) if yes, and after then checking distance (prob if MID or NEAR, not decided yet) then pursue it, if no then check 3.
3. Is the player's torch on (therefore giving away position, potentially) if yes, and after checking distance, then pursue, if no, then continue patrolling.

So far, and this, although possibly not complicated for some, is stuff I've not attempted before, I've done the following.
1. I've taken out the distance check, so now the monster knows where the player is at all times and pursues them, and
2. Started to build in a "is the player behind a wall, and therefore not visible to me" check. How I've attempted this is by trying to send a traceline from the monster to it's enemy (the player) and then, as a starting point, if it hits a wall, then telling the monster to ignore it's enemy. Which works, except that it doesn't, it ignores the player when it's stood right in front of it!

Anyway, my 'changes to find target:
float() FindTarget =
{
local entity client;
local float r;

// earthQuake AI changes ------------------------

local vector test1, test2;
local entity option;

// ---------------------------------------------

// if the first spawnflag bit is set, the monster will only wake up on
// really seeing the player, not another monster getting angry

// spawnflags & 3 is a big hack, because zombie crucified used the first
// spawn flag prior to the ambush flag, and I forgot about it, so the second
// spawn flag works as well
if (sight_entity_time >= time - 0.1 && !(self.spawnflags & 3) )
{
client = sight_entity;
if (client.enemy == self.enemy)
return;
}
else
{
client = checkclient ();
if (!client)
return FALSE; // current check entity isn't in PVS
}

if (client == self.enemy)
return FALSE;

if (client.flags & FL_NOTARGET)
return FALSE;
if (client.items & IT_INVISIBILITY)
return FALSE;



//
// got one
//
self.enemy = client;
if (self.enemy.classname == "player")

// earthQuake AI changes ---------------------------------

option = self.enemy;

// see if any walls are in the way
test1 = self.origin + self.view_ofs;
test2 = option.origin + option.view_ofs;

traceline (test1, test2, FALSE, self);

if (trace_fraction != 1.0)
return FALSE;
else
FoundTarget ();
// --------------------------------------------------------------
return TRUE;
};
I've obviously am not trying to achieve everything (as listed above), just the allowing player to hide behind a wall bit. I'm guessing, it's either a simple error, or I'm going about it a silly way.
Thanks for reading ;)
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: Playing with monster hunting player

Post by Cobalt »

Theres a utility in AI.qc I believe its called () Visible. It also checks for water / waterlevel, which may be a better choice than your Traceline code. If you are using DP, also be aware of the built in () CheckPVS which may or may not be better than Checkclient ().

Where you commented "Got One", I would put in possibly: eprint (client); , which will tell you for sure what it is because if your option entity is world, the tracelines will always fai. Move that eprint around to different locations and run the same scenario some mre time if need be to get a better idea of whats going on. If all seems ok, then something else in other code is altering one of your entities possibly.
Post Reply