XSeth2kX Posted January 7, 2003 Share Posted January 7, 2003 Ive found a q3 tutorial on breakign the 16 weapon limit bot it has reffrences to the macchinegun and other q3 weapons. Does anyone know a way around it? Breaking the 16 weapon limit The weapon system in baseq3 works using an index in the ent->client->ps.stats array - STAT_WEAPONS. This is a bit list of weapons that the client currently holds, corresponding to the weapon_t enumeration. The maximum weapons count is limited to 16 since only 16 bits of an int are communicated across the network via the stats array. Using lots of bitwise operators, it's relatively straight forward to remove this limit. Add another indice to the statIndex_t enumeration called STAT_WEAPONS2. This will simply serve as an extenstion of STAT_WEAPONS raising the weapon limit to 32. Use the following functions (placed in bg_misc.c) to alter and query these two STAT_ indices: code: -------------------------------------------------------------------------------- //TA: pack weapons into the arrayvoid BG_packWeapon( int weapon, int stats[ ] ){ int weaponList; weaponList = ( stats[ STAT_WEAPONS ] & 0x0000FFFF ) | ( ( stats[ STAT_WEAPONS2 ] << 16 ) & 0xFFFF0000 ); weaponList |= ( 1 << weapon ); stats[ STAT_WEAPONS ] = weaponList & 0x0000FFFF; stats[ STAT_WEAPONS2 ] = ( weaponList & 0xFFFF0000 ) >> 16;}//TA: remove weapons from the arrayvoid BG_removeWeapon( int weapon, int stats[ ] ){ int weaponList; weaponList = ( stats[ STAT_WEAPONS ] & 0x0000FFFF ) | ( ( stats[ STAT_WEAPONS2 ] << 16 ) & 0xFFFF0000 ); weaponList &= ~( 1 << weapon ); stats[ STAT_WEAPONS ] = weaponList & 0x0000FFFF; stats[ STAT_WEAPONS2 ] = ( weaponList & 0xFFFF0000 ) >> 16;}//TA: check whether array contains weaponqboolean BG_gotWeapon( int weapon, int stats[ ] ){ int weaponList; weaponList = ( stats[ STAT_WEAPONS ] & 0x0000FFFF ) | ( ( stats[ STAT_WEAPONS2 ] << 16 ) & 0xFFFF0000 ); return( weaponList & ( 1 << weapon ) );} -------------------------------------------------------------------------------- You must then trawl through the codebase changing each modification or check of weapons with the equivalent function call above. For example: code: -------------------------------------------------------------------------------- client->ps.stats[sTAT_WEAPONS] = ( 1 << WP_MACHINEGUN ); -------------------------------------------------------------------------------- in g_client.c becomes code: -------------------------------------------------------------------------------- BG_packWeapon( WP_MACHINEGUN, client->ps.stats ); -------------------------------------------------------------------------------- and code: -------------------------------------------------------------------------------- if ( client->ps.stats[sTAT_WEAPONS] & ( 1 << i ) ) { -------------------------------------------------------------------------------- also in g_client.c becomes code: -------------------------------------------------------------------------------- if( BG_gotWeapon( i, client->ps.stats ) ) { -------------------------------------------------------------------------------- You get the idea. That is not the end of the problems however. You must also store ammo for each weapon. This varies from modification to modification however, depending on whether many weapons share ammo and clip based systems. This is a solution which uses the powerups array as well as the ammo array to store ammo quantities using bit packing to store clips (if the weapons are clip based): code: -------------------------------------------------------------------------------- //TA: extract the ammo quantity from the arrayvoid BG_unpackAmmoArray( int weapon, int ammo[ ], int ammo2[ ], int *quan, int *clips, int *maxclips ){ int ammoarray[32]; int i; for( i = 0; i <= 15; i++ ) ammoarray[ i ] = ammo[ i ]; for( i = 16; i <= 31; i++ ) ammoarray[ i ] = ammo2[ i - 16 ]; if( quan != NULL ) *quan = ammoarray[ weapon ] & 0x03FF; if( clips != NULL ) *clips = ( ammoarray[ weapon ] >> 10 ) & 0x07; if( maxclips != NULL ) *maxclips = ( ammoarray[ weapon ] >> 13 ) & 0x07;} //TA: pack the ammo quantity into the arrayvoid BG_packAmmoArray( int weapon, int ammo[ ], int ammo2[ ], int quan, int clips, int maxclips ){ int weaponvalue; weaponvalue = quan | ( clips << 10 ) | ( maxclips << 13 ); if( weapon <= 15 ) ammo[ weapon ] = weaponvalue; else if( weapon >= 16 ) ammo2[ weapon - 16 ] = weaponvalue;} -------------------------------------------------------------------------------- Please bear in mind you must sacrifice the powerups array (and hence all powerups) to use this method. An alternative is to split each indice of the ammo array into two 8 bit numbers, so that the ammo array stores 32 numbers total. This limits your maximum ammo value to 255 however. Link to comment Share on other sites More sharing options...
gw_leader Posted January 8, 2003 Share Posted January 8, 2003 half the fun in using a tutorial is interpretting it to the engine your using, (ex. hl to q3), or using the basic concepts of it to create something of your own. By the way, all I did to break the 16 weapon limit was change the defines and that seemed to work. Link to comment Share on other sites More sharing options...
XSeth2kX Posted January 8, 2003 Author Share Posted January 8, 2003 which defines and where? Link to comment Share on other sites More sharing options...
Chandler Posted January 8, 2003 Share Posted January 8, 2003 Hey, gw_leader, I'm curious as to what your new limit for weapons is (I assume there is one). Link to comment Share on other sites More sharing options...
Wudan Posted January 8, 2003 Share Posted January 8, 2003 Beta tests went okay after changing the defines around? Certainly would be nicer that going crazy with bit-wise operators. Link to comment Share on other sites More sharing options...
gw_leader Posted January 8, 2003 Share Posted January 8, 2003 the MAX_WEAPONS define and MAX_POWERUPS I subtracted how many powerups for how many weapons I wanted to add to the limit. I only tested it for a bit when I did it, but it seemed to work. I'll test it a bit later when I reimplement it into my mod. Oh yeah I set the powerups to 8 and weapons to 24 Link to comment Share on other sites More sharing options...
Wudan Posted January 8, 2003 Share Posted January 8, 2003 I don't know if that will work either - it compiles and runs, so, at least it doesn't seem to screw too many things up. Link to comment Share on other sites More sharing options...
Chandler Posted January 8, 2003 Share Posted January 8, 2003 Oh okay. I'm told there is some other way to do it to get weapons plus ammo up to around 200 (which should be fine for us), but I was just wondering if you had gotten it higher. Link to comment Share on other sites More sharing options...
Emon Posted January 9, 2003 Share Posted January 9, 2003 For JK, when you ran out of weapon slots, you bound a key to an alternate mode for a weapon that would basically switch the model, change the firing rates and projectiles, etc., all done in one weapon COG. And since COG is peanuts to C, you could always use that method if you needed to. E.g. press an alternate button to switch from M-16 to M4. Link to comment Share on other sites More sharing options...
recombinant Posted January 9, 2003 Share Posted January 9, 2003 Originally posted by Emon For JK, when you ran out of weapon slots, you bound a key to an alternate mode for a weapon that would basically switch the model, change the firing rates and projectiles, etc., all done in one weapon COG. And since COG is peanuts to C, you could always use that method if you needed to. E.g. press an alternate button to switch from M-16 to M4. So what you're saying here is that you don't actually add any more weapon types, but you create separate "modes" for each weapon that swaps different weapons in and out? ...and what does "COG" refer to? [Edit (1/9/2003, 1:00 PST):] I just reread your post and read some info up on Massasi.net, and see that you're referring to Jedi Knight, not Jedi Knight II, and that COG refers to the scripting language used by that engine. Good suggestion... might prove useful. The problem is that we're limited by a value that was predetermined by Q3, so that network bandwith would be optimized. Unfortunately this number does not allow for much growth (thus gw's suggestion of robbing from one place to add to another). Thanks for the suggestion! It would be very cool if we can make it work! [/Edit] Link to comment Share on other sites More sharing options...
Takeoffyouhoser Posted January 9, 2003 Share Posted January 9, 2003 So would this be like cycling the weapons every time you hit the 3 or 7 key, like in SOF2? Link to comment Share on other sites More sharing options...
Chandler Posted January 9, 2003 Share Posted January 9, 2003 I would imagine that those weapons would have to use the same ammo though, wouldn't they? Link to comment Share on other sites More sharing options...
Emon Posted January 9, 2003 Share Posted January 9, 2003 I don't know how the weapons work in JO, but in JK, the ammo, firing rate, weapon models, all defined in the COG. Mods like SS3 made it so if you pressed a button while selecting a weapon, it would swap the models, change the firing rate and ammo types, etc. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.