by Sajt » Thu Mar 18, 2010 9:16 pm
No, you can't use an "odd" number. Due to the nature of bitwise math, the number 11 for example is actually 1 + 2 + 8, so it refers to three flags. If you need to know more about bitwise math, I'm sure there are plenty of resources out there, but to summarize, yes, a bit flag must be a power of two.
The highest bitflag you can store in a float is actually, if I remember correctly, 2^23 (8388608). Therefore, the maximum value of all bits being used is 2^24-1 (16777215). Above that, there is not enough precision in a 32-bit float to maintain the integer portion of the number.
You can't use 256 because you're encroaching on other bitflags which are also stored in .items. You'll see in defs.qc that IT_SHELLS uses 256.
If you want to store more items, you should create a second field by adding this to the bottom defs.qc:
.float items2;
And then store your new items in that field rather than .items. There is probably a lot of annoying work involved in getting this all working, and after all that you will still have to deal with the .weapon field. It's not a lot of fun especially if you aren't familiar with how it works. I can only suggest that you take it slowly, make sure you know exactly what something does before you change it, and if something unexpected ever happens when you test your changes, figure out exactly why that is happening before you move on. And of course come back here whenever you have questions.
The tutorial you linked to seems to be very evil. "Since we don't want any bit fields", the author says... well, maybe he doesn't want any bit fields. Anyway, I really doubt that that tutorial will actually work. For one thing, the bottom of W_ChangeWeapon() does do a bitwise AND to check whether the weapon 'fl' is contained in self.items. That won't work as expected when the item flag is not a power of two. (For example, if IT_SNIPER is 17, that is 1 + 16, so you will only be able to switch to the weapon when you are holding either the shotgun or the grenade launcher. Only because you are always holding the shotgun, that will work, but I doubt even the author is aware of his ignorance.)
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.