Author Topic: Unknown code - STAT_WEAPONS3  (Read 3322 times)

rotacak

  • Posts: 761
  • Turrets: +39/-64
Unknown code - STAT_WEAPONS3
« on: March 01, 2010, 10:46:31 pm »
This will be another unaswered thread ;D

Can anyone explain me this code? Or tell me how to write in understable form? This code seems to be limited to maximum number of weapons. If is more weapons avaiable, then this will probably overflow. I need to expand it to more weapons, but I dont understand this code :-(

Code: [Select]
void BG_AddWeaponToInventory( 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;

  if( stats[ STAT_SLOTS ] & BG_FindSlotsForWeapon( weapon ) )
    Com_Printf( S_COLOR_YELLOW "WARNING: Held items conflict with weapon %d\n", weapon );

  stats[ STAT_SLOTS ] |= BG_FindSlotsForWeapon( weapon );
}

Anyone know how to extend it? Probably how to add STAT_WEAPONS3 to this?:

Code: [Select]
  stats[ STAT_WEAPONS ] = weaponList & 0x0000FFFF;
  stats[ STAT_WEAPONS2 ] = ( weaponList & 0xFFFF0000 ) >> 16;

gimhael

  • Posts: 546
  • Turrets: +70/-16
Re: Unknown code - STAT_WEAPONS3
« Reply #1 on: March 01, 2010, 11:18:56 pm »
I guess this is a leftover from old quake code where you could carry many weapons, so the weapons in your inventory are stored in a bitfield, one bit per weapon. This bitfield is split over 2 16-bit ints, so you can have max 32 weapons. The code just combines the two 16-bit fields into a 32-bit field, adds the bit for the new weapon and splits it again into two 16-bit fields. Then it adds any bits to the STAT_SLOTS required for the weapon. The STAT_SLOTS are used to make certain combinations impossible, like BSUIT+HELMET, but in Trem all weapons except blaster use the same slot, so the bit field stuff is really not needed and has been removed in 1.2.

If you need more weapons, there are a few numbers (like 4 or 5) left in enum weapon_t. If this isn't enough I would think about reusing identical numbers for alien and human weapons. That would require a game and cgame change, but adding another stat slot means you need a new client and server or you have to remove one of the other stats.


rotacak

  • Posts: 761
  • Turrets: +39/-64
Re: Unknown code - STAT_WEAPONS3
« Reply #2 on: March 03, 2010, 12:43:10 pm »
And is possible to port solution from 1.2?

gimhael

  • Posts: 546
  • Turrets: +70/-16
Re: Unknown code - STAT_WEAPONS3
« Reply #3 on: March 03, 2010, 01:55:42 pm »
Only if you also switch to the 1.2 network protocol, which means your players need to switch to the gpp client...

rotacak

  • Posts: 761
  • Turrets: +39/-64
Re: Unknown code - STAT_WEAPONS3
« Reply #4 on: March 03, 2010, 10:07:59 pm »
Damn...
Then there is only one solution - "reusing identical numbers for alien and human weapons". If I udesrtand correctly, then I have to use for example WP_HIVE for aliens like hive, but for humans WP_HIVE like new weapon. Yes?