Forum

Confusing error

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Confusing error

Postby ooppee » Mon Mar 21, 2011 5:46 pm

Ok did a Chainlightning gun. Works upon pickup fine. I currently have it only selectable via Impulse 64 (not in scroll weapon commands) as I am doing other things first.

My issue though is the cheat command - impulse 9. I added the IT_CLIGHTNING.

Code: Select all
void() CheatCommand =
{
   if (deathmatch || coop)
      return;

   self.ammo_rockets1 = 100;
   self.ammo_nails1 = 200;
   self.ammo_shells1 = 100;
   
   self.items = self.items |
      IT_AXE |
      IT_SHOTGUN |
      IT_SUPER_SHOTGUN |
      IT_NAILGUN |
      IT_SUPER_NAILGUN |
      IT_GRENADE_LAUNCHER |
      IT_ROCKET_LAUNCHER |
      IT_LAVA_NAILGUN |
      IT_LAVA_SUPER_NAILGUN |
      IT_MULTI_GRENADE |
      IT_MULTI_ROCKET |
      IT_PLASMA_GUN |
                IT_CLIGHTNING |
      IT_LIGHTNING;
         
   self.items = self.items | IT_KEY1 | IT_KEY2;      

   self.ammo_lava_nails = 200;
   self.ammo_multi_rockets = 100;
   self.ammo_plasma = 100;
   self.ammo_cells1 = 200;

   self.weapon = IT_ROCKET_LAUNCHER;
   self.impulse = 0;
   W_SetCurrentAmmo ();
};


Only added that 1 line. Now what happens when I use it is I ONLY get the Chain Lightning, Lightning Gun and Axe. All others end up saying "No weapon".
It's ammo is "ammo_cells1"

I've changed the order and all and still no luck. It's like any weapon after it on the list doesn't appear anymore. If I put it at the end - all weapons are removed.
I know it's likely something so basic, but I can't find out what lol.
ooppee
 
Posts: 70
Joined: Thu Oct 28, 2010 2:57 am

Postby c0burn » Mon Mar 21, 2011 6:33 pm

What are the numerical values of your IT_ variables?
c0burn
 
Posts: 208
Joined: Fri Nov 05, 2004 12:48 pm
Location: Liverpool, England

Postby ooppee » Mon Mar 21, 2011 7:45 pm

Code: Select all
// items
float   IT_AXE               = 2048;      // 1
float   IT_SHOTGUN            = 1;
float   IT_SUPER_SHOTGUN      = 2;
float   IT_NAILGUN            = 4;
float   IT_SUPER_NAILGUN      = 8;
float   IT_GRENADE_LAUNCHER      = 16;
float   IT_ROCKET_LAUNCHER      = 32;
float   IT_LIGHTNING         = 64;         // 8
float   IT_SHELLS            = 128;
float   IT_NAILS            = 256;
float   IT_ROCKETS            = 512;
float   IT_CELLS            = 1024;
float   IT_LAVA_NAILGUN         = 4096;      
float    IT_LAVA_SUPER_NAILGUN   = 8192;         
float    IT_MULTI_GRENADE      = 16384;      //15
float   IT_MULTI_ROCKET         = 32768;
float   IT_PLASMA_GUN         = 65536;   
float   IT_KEY1               = 131072;
float   IT_KEY2               = 262144;      
float   IT_INVISIBILITY         = 524288;
float   IT_INVULNERABILITY      = 1048576;
float   IT_SUIT               = 2097152;
float   IT_QUAD               = 4194304;      //23
//ZOID --
float   IT_GRAPPLE            = 8388608;      // grapple overload, hope it
//-- ZOID                              // doesn't mess things up!
float    IT_CLIGHTNING           = 16777216; //ooppee chainlightning
                                    

float   IT2_ARMOR1            = 1;         //24
float   IT2_ARMOR2            = 2;
float   IT2_ARMOR3            = 4;
float   IT2_LAVA_NAILS         = 8;
float   IT2_PLASMA_AMMO         = 16;
float   IT2_MULTI_ROCKETS      = 32;         //29
float    IT2_SHIELD            = 64;
float    IT2_ANTIGRAV         = 128;
float   IT2_SUPERHEALTH         = 256;         //32
float   IT2_EARTHQUAKE         = 512;         
float   IT2_V_SPHERE         = 1024;


Did the whole "doubling" as that appears to be required(?). I would of done something like 15 or whichever.
ooppee
 
Posts: 70
Joined: Thu Oct 28, 2010 2:57 am

Postby ooppee » Mon Mar 21, 2011 9:11 pm

Looking at the IT2_xxxx
Seems Mission Pack 2 added "IT2_" to bypass the limits?

In the id1 code - the armors were IT not IT2 and whenever they are called they care called through *other/targ*.items

In ID1 code it's: *other/targ*.items
In MP2 it's *other/targ*.items2
Think I may of been blind to a obvious way around this. I will give this a try and come back with the results.

[Edit]
Ok so yes that will indeed fix it. Seems the IT_GRAPPLE's value is the absolute MAX. I swapped their values (the IT_CLIGHTNING and IT_GRAPPLE) and everything worked. When I made it (impulse 9) give me the Grapple also - same bug came back. So "8388608" appears to be the absolute max you can have.
So when looking at that list - I can make the old ammo use IT2 to get more. So allows 24 options with IT_ maybe 24 options with IT2_? May just move the remaining powerups and ammo it IT2_ and edit their code to call *.items2 instead of *.items (leaving me at 21, Hipnotic adds in 3 more powerups - horn,wetsuit,empathy shield - meaning it *should* give me all it needs - they are too called with *.items2)
ooppee
 
Posts: 70
Joined: Thu Oct 28, 2010 2:57 am

Postby ooppee » Mon Mar 21, 2011 11:44 pm

http://www.inside3d.com/showtutorial.php?id=60

This tut adds in another weapon using:
IT_SNIPER = 17;

I did try this just with my IT_CLIGHTNING. It also fixes the error.

However, would this cause any errors or crashes - more based upon the engines. I wouldn't want to go this simple route of adding the weapons in with "odd numbers" only to eventually have it cause crashes.
ooppee
 
Posts: 70
Joined: Thu Oct 28, 2010 2:57 am

Postby mh » Mon Mar 21, 2011 11:56 pm

You can't use the extra bits because this field is stored internally as a float, and floating point representation limits how many items you can have. It sucks but it's a breaking change if you "fix" it.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby frag.machine » Tue Mar 22, 2011 12:07 am

mh is right: in QuakeC you can only do bitwise operations with the first 24 bits of a float, and 16777216 == 0x1000000 == 1 + 2^24.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby ooppee » Tue Mar 22, 2011 12:21 am

Yeah I was figuring as much with the whole 1,2,4,8,16,32,64,128,256,.....ect that using "17" like the tutorial said wouldn't be the ideal way. It "worked" (like all guns were in inventory, selectable, fire-able, pickupable ect) however I can imagine it can break other things.
What possible errors can come out of doing it?
ooppee
 
Posts: 70
Joined: Thu Oct 28, 2010 2:57 am

Postby mankrip » Tue Mar 22, 2011 12:25 am

mh wrote:floating point representation limits how many items you can have.

Plus, in some ports the amount of QC bits is even more limited - like in Titanium Studios' QuakeDC, that only supports half of them.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
User avatar
mankrip
 
Posts: 915
Joined: Fri Jul 04, 2008 3:02 am

Postby mankrip » Tue Mar 22, 2011 12:42 am

ooppee wrote:http://www.inside3d.com/showtutorial.php?id=60

This tut adds in another weapon using:
IT_SNIPER = 17;

Eew! That tutorial again.

Take a look at this introduction on how bitflags works, and then at this thread.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
User avatar
mankrip
 
Posts: 915
Joined: Fri Jul 04, 2008 3:02 am

Postby Jukki » Tue Mar 22, 2011 4:28 am

ummm i have coded fine with adding just next number, all my weapons works fine.
Jukki
 
Posts: 214
Joined: Wed Apr 07, 2010 4:59 am

Postby ooppee » Tue Mar 22, 2011 7:59 am

If you gave more testing, you would encounter some bugs.

I don't have the grappling hook available in any way aside from Impulse 9 currently.

However upon spawning, I have it.

I used "15" as it's value, tried again with 17,19,21,9 all gave off same effect.
When I made it back to 8388608 (double the Quad value).
I spawn without it and when I use impulse 9 - all is well.

I guess you could do this fine with many "if" statements in Class based mods (like if this class - remove this weapon/make it unselectable).
So just from these tests, I see why it's not recommended to use whichever number.
ooppee
 
Posts: 70
Joined: Thu Oct 28, 2010 2:57 am

Postby mh » Tue Mar 22, 2011 10:11 am

The core problem here is that QC just doesn't have any concept of data types. It treats everything as a float, and only casts to int at the very last moment for any operations that only work on integers (like bitwise), but the end result is stored directly back to a float.

The VM in the engine also doesn't know that you're bitwising self.items, all that it sees is something like this:
Code: Select all
c->_float = (int) a->_float | (int) b->_float;

So the crude fix would likely involve breaking every other floating point operation in order to get an extra weapon working. The more correct fix would require adding data types to QC.

Or alternatively you could just use .items2.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby Spike » Tue Mar 22, 2011 12:33 pm

even with a qcc+engine that does support ints, you need to make the engine incompatible if you want to actually make use of them for the items field.
realistically speaking, even doing that, you end up with only 11 more bits or so. you'll still run out eventually.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby ooppee » Wed Mar 23, 2011 5:24 pm

Partially on the same topic I did this tutorial.
http://qexpo2005.quakedev.com/booths/dr ... g/126.html
All appears to be fine with the weapon adding. I pick it up, it ONLY gives me that weapon. I have it selectable and all too.

The only issue is it's selectable only by impulse xx.
You can scroll to it with reverse/forward.

Code: Select all
else if (self.weapon == IT_MULTI_ROCKET)
      {
         self.weapon = IT_LIGHTNING;
         if (self.ammo_cells1 < 1)
            am = 1;
      }
      else if (self.weapon == IT_LIGHTNING)
      {
         self.weapon2 = IT3_CLIGHTNING; //ooppee chainlightning, make Lightning Gun go to Chainlighting and after this chain -> Plasma
         if (self.ammo_cells1 < 1)
            am = 1;
      }
      else if (self.weapon2 == IT3_CLIGHTNING) //ooppee chainlightning make it go to Plasma gun after
      {
         self.weapon = IT_PLASMA_GUN;
         if (self.ammo_plasma < 1)
            am = 1;
      }

      if ( (it & self.weapon | self.weapon2) && am == 0) //added weapon2
      {
         W_SetCurrentAmmo ();
         return;
      }
   }

};


This is inside CycleWeaponCommand

Doesn't work and when I impulse to the weapon and cycle to next - crashes.[/quote]
ooppee
 
Posts: 70
Joined: Thu Oct 28, 2010 2:57 am

Next

Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest