.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
  Posts  
Weapons bug added to v1.07 code (Groups : qc : Forum : hard_code() : Weapons bug added to v1.07 code) Locked
Thread Options
numbersix
numbersix quake-c coder++
Dec 9 2017 Anchor

This bug was added to my v1.07 qc++ code with PK3 rc1: Moddb.com

If you already have, say a rocket launcher, and you touch another there is no sound.
And the item is deleted from the map.

#ifdef code_xents
	e7__ = vchk(new, 1, self.vwepent); // get q1 std wep if we have an x_ent in that slot
	if (!e7__) vload(self, new);
#endifdef

// followed by

#ifdef hip_weapons
// some hip code not used when x_ents is compiled
#endifdef

	else
#ifdef noobjerr
	{
// NOTE: possibility of removing an improperly translated item that could rotate to something else
		remove(stemp);
		return;
	}
#else
		objerror ("weapon_touch: unknown classname");					//opgrade protected
#endifdef

The else - remove(stemp); is supposed to happen if the classname test fails.
But in this case the #ifdef set places it after if (!e7__) - which checks to see if you already have one.
If you have one it runs the remove code. Oops.

Fixed like:

	else
#ifdef noobjerr
	{
// NOTE: possibility of removing an improperly translated item that could rotate to something else
		remove(stemp);
		return;
	}
#else
		objerror ("weapon_touch: unknown classname");					//opgrade protected
#endifdef

// move this out of the else - remove sequence to down here

#ifdef code_xents
	e7__ = vchk(new, 1, self.vwepent); // get q1 std wep if we have an x_ent in that slot
	if (!e7__) vload(self, new);
#endifdef

Done.

Now the viswep check new and load happens after all the classname testing.
Like it should.


How did it get like this?

I decided first the hipnotic weapons and ammo would use the x_touch function.
Since that function is generic and can handle all extra weapons and ammo without code change.

Then I decided to #ifdef all the extra hip stuff in the v1.06 code. Like this sample.
And I thought: "Well, if I have code_xents I wont check the hip classnames. Instead I'll do the vchk / vload and #else those two."

Then when the hipnotic block of code goes away, if vchk false runs the remove code erroneously.

Edited by: numbersix

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.