Wirehead Studios

Wirehead Modifications => General Development ('Laced Neptune') => Topic started by: Orbital-S2D on 2016-03-18, 04:00



Title: Ammo count on weapon select
Post by: Orbital-S2D on 2016-03-18, 04:00
I added this... i didnt come up on this on my own but i put my own twist on it :) this is handy...

Code: (cg_weapons.c)
/*
===================
CG_DrawWeaponSelect
===================
*/
void
CG_DrawWeaponSelect(void)
{
  int i;
  int bits;
  int count;
  int x, y, w;
  char *name;
  float *color;
  char ammo[4];         // ReQW
  int yammo, yname;     // ReQW

  // don't display if dead
  if (cg.predictedPlayerState.stats[STAT_HEALTH] <= 0)
  {
    return;
  }

  color = CG_FadeColor(cg.weaponSelectTime, WEAPON_SELECT_TIME);
  if (!color)
  {
    return;
  }
  trap_R_SetColor(color);

  // showing weapon select clears pickup item display, but not the blend blob
  cg.itemPickupTime = 0;

  // count the number of weapons owned
  bits = cg.snap->ps.stats[STAT_WEAPONS];
  count = 0;
  for (i = 1; i < MAX_WEAPONS; i++)
  {
    if (bits & (1 << i))
    {
      count++;
    }
  }

  x = 320 - count * 20;
 // ReQW y = 380;
        yname = 366;

// ReQW draw ammo count above/below weapon icon
  if ( cg_hAmmo.integer == 1 ) // bottom
        {       
                y = yname + 22;
                yammo = y + 36;
        }
        else
        if ( cg_hAmmo.integer == 2 ) // top
        {
                yammo = yname + 18;
                y = yammo + 12;
        }
        else // no ammo count
        {
                y = yname + 22;
                yammo = 0;
        }
  for (i = 1; i < MAX_WEAPONS; i++)
  {
    if (!(bits & (1 << i)))
    {
      continue;
    }

    CG_RegisterWeapon(i);

    // draw weapon icon
    CG_DrawPic(x, y, 32, 32, cg_weapons[i].weaponIcon);

        // begin ReQw - draw ammo count above/below weapon icon
                if ( cg_hAmmo.integer )
                        if ( i != WP_GAUNTLET ) // gauntlet has -1 ammo
                        {
                                Com_sprintf( ammo, 4, "%i", cg.snap->ps.ammo[i]);
                                w = CG_DrawStrlen( ammo );
                                CG_DrawStringExt( x + (16 - w * TINYCHAR_WIDTH / 2 ) , yammo,
                                                ammo, colorWhite, qfalse, qfalse,
                                                TINYCHAR_WIDTH, TINYCHAR_HEIGHT, 0 );
                        }
        // end ReQW
 
 // draw selection marker
    if (i == cg.weaponSelect)
    {
      CG_DrawPic(x - 4, y - 4, 40, 40, cgs.media.selectShader);
    }

    // no ammo cross on top
    if (!cg.snap->ps.ammo[i])
    {
      CG_DrawPic(x, y, 32, 32, cgs.media.noammoShader);
    }

    x += 40;
  }

  // draw the selected name
  if (cg_weapons[cg.weaponSelect].item)
  {
    name = cg_weapons[cg.weaponSelect].item->pickup_name;
    if (name)
    {
      w = CG_DrawStrlen(name) * BIGCHAR_WIDTH;
      x = (SCREEN_WIDTH - w) / 2;
          // ReQW CG_DrawBigStringColor(x, y - 22, name, color);
          CG_DrawBigStringColor(x, yname, name, color); // ReQW
    }
  }

  trap_R_SetColor(NULL);
}


then of course add your cvar for cg_hAmmo

i thought i would share :)