Detecting a walking/flying monster via QC

Discuss programming in the QuakeC language.
Post Reply
Seven
Posts: 301
Joined: Sat Oct 06, 2007 8:49 pm
Location: Germany

Detecting a walking/flying monster via QC

Post by Seven »

Hello,

I am searching for a way to be able to detect if a monster is spawned walking/flying along a path or spawned idling.

Let me try to explain:
I would like to be able to detect in the monsters spawn function (example "monster_army"), if this monster is walking along a path or is only idling on a spot.
I need to do it in the initial run of the monsters spawn function, because I need to manipulate the monster accordingly.

I noticed that a 'target' is always set for a walking monster, besides the regular parms (like origin, spawnflag and angle).
Could I check for a 'target' ? If the monster has one, can I be sure that it is walking (and not idling) ?
Like vanilla Quake checks for the zombie´s spawnflag if it is crucified or not:
if (self.spawnflags & SPAWN_CRUCIFIED)

Could this work:

Code: Select all

if (self.target)
	// monster is walking
Or is an existing 'target' not evidence enough to be sure that the monster is walking/flying ?

I am not a mapper, so I need my code to be able to run (on) existing maps.
Thank you for your help and tips.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Detecting a walking/flying monster via QC

Post by Spike »

the qc is a bit convoluted. and frankly looks buggy to me.
but...

after *monster_start_go
if (time > self.pausetime)
monster is meant to be walking (assuming its not dead, anyway).

before then, you'll need to check if it has a target, and that its target is a "path_corner" entity. The monster will only patrol/walk if it targets a path_corner. Other entities are ignored (as they are triggered on the monster's death).
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: Detecting a walking/flying monster via QC

Post by frag.machine »

Code: Select all

if (self.goalentity != world)
{
  if (self.goalentity.classname == "path_corner")
  {
    // following a path
  }
  else
  {
    // angry with something (possibly a player)
    if (self.goalentity.classname == "player")
    {
      // yup, it's a player
    }
    else
    {
      // maybe another monster ?
    }
  }
}
else
{
  // no goals, just sitting idle
}
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
Seven
Posts: 301
Joined: Sat Oct 06, 2007 8:49 pm
Location: Germany

Re: Detecting a walking/flying monster via QC

Post by Seven »

Thank you very much frag.machine and Spike.

frag.machine, the part of your code that checks for player is *normaly* not necessary,
as i have to make the decision in the first second after map starts.
Monsters are *normaly* not placed around players spawnpoint, but who knows...
Some mappers like this kind of extra thrill :)

So .goalentity is my way to go/check.

Thank you again for your help.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Detecting a walking/flying monster via QC

Post by Spike »

either way, entity load ordering means you cannot check this reliably in the spawn function itself.

so walkmonster_start_go would be the place to put any code that depends upon patrolling. and that's where the existing code figures out if its meant to be patrolling anyway.
Seven
Posts: 301
Joined: Sat Oct 06, 2007 8:49 pm
Location: Germany

Re: Detecting a walking/flying monster via QC

Post by Seven »

Hello,

I didnt want to start a new thread for my small question.

It always bothered me, which of these 2 lines have more randomness, or if the engine interprets them equal:
1.) foo = random() + random() + random() + random() + random();
2.) foo = 5 * random();

Both lines can create foo values between 0 .. 5
But isnt the second line less random ?
As it multiplies the same value by 5, while the 1st line adds 5 random values ?

Sorry for this stupid question, but I use a lot of randomness in my small mod and this question bothered me for quite some time.
I plan to create a random value between 0 .. 100, so I was thinking if foo = 100 * random(); would be sufficient * random* LOL.

Thank you for your ideas.
Nahuel
Posts: 495
Joined: Wed Jan 12, 2011 8:42 pm
Location: mar del plata

Re: Detecting a walking/flying monster via QC

Post by Nahuel »

Seven wrote:Hello,

I didnt want to start a new thread for my small question.

It always bothered me, which of these 2 lines have more randomness, or if the engine interprets them equal:
1.) foo = random() + random() + random() + random() + random();
2.) foo = 5 * random();

Both lines can create foo values between 0 .. 5
But isnt the second line less random ?
As it multiplies the same value by 5, while the 1st line adds 5 random values ?

Sorry for this stupid question, but I use a lot of randomness in my small mod and this question bothered me for quite some time.
I plan to create a random value between 0 .. 100, so I was thinking if foo = 100 * random(); would be sufficient * random* LOL.

Thank you for your ideas.
in ther first option you have more posibilities to get a number near "2.5" , the second is more "random", see this image


Image

so use "foo = 100 * random();" just logic :P
Last edited by Nahuel on Sun Sep 01, 2013 3:13 pm, edited 1 time in total.
hi, I am nahuel, I love quake and qc.
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: Detecting a walking/flying monster via QC

Post by Cobalt »

Also dont forget,

foo = 5 * random();
has an equal chance of returning zero as well as the rest of the possibilities.

The other code has an increased chance , (I guess 4 times less likely than the other code) that zero will be the result returned.


Seven wrote:Hello,

I didnt want to start a new thread for my small question.

It always bothered me, which of these 2 lines have more randomness, or if the engine interprets them equal:
1.) foo = random() + random() + random() + random() + random();
2.) foo = 5 * random();

Both lines can create foo values between 0 .. 5
But isnt the second line less random ?
As it multiplies the same value by 5, while the 1st line adds 5 random values ?

Sorry for this stupid question, but I use a lot of randomness in my small mod and this question bothered me for quite some time.
I plan to create a random value between 0 .. 100, so I was thinking if foo = 100 * random(); would be sufficient * random* LOL.

Thank you for your ideas.
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: Detecting a walking/flying monster via QC

Post by frag.machine »

At least in theory, random() returns evenly spread values. Adding the return of 5 calls only reduces drastically the chance of lower values as result. Maybe what you really want is to reduce chances of, let's say, a value near limits to occur, and in this case a more efficient approach would be:

Code: Select all

local float r;

r=random();
if((r<0.15)||(r>0.85))
  r=random(); // randomize again
Note that inverting the condition has the effect of forcing more occurencies near the range limits, so you can force some skewing in th final results.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
Seven
Posts: 301
Joined: Sat Oct 06, 2007 8:49 pm
Location: Germany

Re: Detecting a walking/flying monster via QC

Post by Seven »

Thank you very much for your posts and explanations.
Post Reply