.qc (dot qc) - the group for quake c coders of all denominations. If you make quake one mods and write code in quake c, join our group! I'll try to answer any quake c questions - please post your inquiry in the forums...

Forum Thread
Runner! (Groups : qc : Forum : hard_code() : Runner!) Locked
Thread Options
numbersix quake-c coder++
Feb 20 2017 Anchor

Quick, someone get a sandman. Heh heh.

from: Quake c - gone bad #11 - Runner!

So, I noticed a few months back while working on Quake-hack maps that
monsters start up and then get stuck running in place.

When I find a new bug, I make a note for later so I'm not constantly
side tracked to fix one little thing. Much easier to finish a project.

I'm in the middle of a major recode. I generally only do a big
recode when the code-base has some seriously unworkable issue.

In this case I broke frikqcc by using to many globals:
7753 numglobaldefs (of 32768)
The engine has a hard limit of 32768.

I switched to fteqcc which is much better with globals. However,
I know before I can complete Archon, I'll break it again.
And I have this idea to clear a ton of globals... (It works too.)
Plus I want to make the PainKeep 3.0 code seperate from Archon.

Quirky bugs like this can be seriously frustrating.
The code base has 3 major components right now - PK3, Archon
and Quake-hack. And Quake-hack uses engine side mods.

I had not done anything with monster code in months.
First I figured it might have something to do with Quake-hack.
The maps are not normal quake maps. They are made from discrete
bsp model chunks the engine strings together.

So I tried a normal map. Monsters still get stuck.
I dont need monsters for PK3, so no biggie.
But then I start bot testing, and they get stuck!

What the!? How the!?
Now it has to be fixed before the PK3 release. Great.
And I have no idea where this bug comes from.
Take a look at monster code, module by module.

Hrm. One of the first things I did was take the hipnotic
code base and wrap all the hip code in #ifdef #endif sets so I could isolate it.

I turn off hipnotic. The monsters & bots work.
Woo. That was a big relief. Start looking at the code.

A-ha moment:

#ifdef hip_monsters_notused
// has bug with new x_ents / x_monsters where monsters / some bots get stuck running in place
// believe this is from SUB_Null def. load on all .void fields
 if (self.th_turn)
//  local float angledelta;
 #define angledelta  f0__

  angledelta = fabs(self.angles_y - enemy_yaw);
  if (angledelta > MIN_ANGLE_DELTA)

This is a section in "ai_run()".

Now, this works fine with the normal hipnotic qc, the monsters never get stuck.
So, what the heck is going on?

I see the problem instantly:

 if (self.th_turn)
// snip
// snip

One thing I want to change from the chaos-mod 2 base is having to constantly
change or add a bunch of code every time I want a new weapon or monster.
Archon adds a bunch of weapons via "weapon system 6". But I have more.
This also takes up a ton of globals - especially the monsters.

So, I came up with a generic system that uses SV_OnEntityPreSpawnFunction from
darkplaces extensions.

A big issue is all the .void fields that are used, some on the engine side.
If those are null in the wrong place qc crashes hard.

So I where I manipulate the entity load in cvar_fields (a custom function I wrote for this)
I assign all .void "SUB_Null()" by default. That happens to include map spawned monsters.

.void() th_turn is added by hipnotic and used in the snipped shown.
But with the SUB_Null value - it runs!
And makes monsters get stuck.

In the current case, th_turn is not assigned a value - so I blocked the code from compile.

The other solution is:

 if ( self.th_turn && self.th_turn != SUB_Null )
You can not simply test for != SUB_Null - then you might try to call a true null.
That will crash qc as well.

I'm considering an engine mod that allows a default .void value to be set via cvar.

You could use SUB_Null, or setup a warning function to identify when a null call
is being issued.

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.