~richardson183/tremulous/trunk

Viewing all changes in revision 2097.

  • Committer: msk
  • Date: 2012-07-15 09:01:25 UTC
  • Revision ID: svn-v4:fa00571f-6d07-0410-8660-cfe97aa2585a:trunk:2270
Index: src/game/bg_misc.c
===================================================================
--- src/game/bg_misc.c  (revision 2269)
+++ src/game/bg_misc.c  (working copy)
@@ -3338,26 +3338,24 @@ Returns the credit value of a player
 */
 int BG_GetValueOfPlayer( playerState_t *ps )
 {
-  int i, worth = 0;
-  
+  int worth = 0;
+
   worth = BG_Class( ps->stats[ STAT_CLASS ] )->value;
 
   // Humans have worth from their equipment as well
   if( ps->stats[ STAT_TEAM ] == TEAM_HUMANS )
   {
+    upgrade_t i;
     for( i = UP_NONE + 1; i < UP_NUM_UPGRADES; i++ )
     {
       if( BG_InventoryContainsUpgrade( i, ps->stats ) )
         worth += BG_Upgrade( i )->price;
     }
 
-    for( i = WP_NONE + 1; i < WP_NUM_WEAPONS; i++ )
-    {
-      if( BG_InventoryContainsWeapon( i, ps->stats ) )
-        worth += BG_Weapon( i )->price;
-    }
+    if( ps->stats[ STAT_WEAPON ] != WP_NONE )
+      worth += BG_Weapon( ps->stats[ STAT_WEAPON ] )->price;
   }
-      
+
   return worth;
 }
 
@@ -3828,29 +3826,6 @@ qboolean BG_BuildableIsAllowed( buildable_t builda
 
 /*
 ============
-BG_PrimaryWeapon
-============
-*/
-weapon_t BG_PrimaryWeapon( int stats[ ] )
-{
-  int i;
-
-  for( i = WP_NONE; i < WP_NUM_WEAPONS; i++ )
-  {
-    if( BG_Weapon( i )->slots != SLOT_WEAPON )
-      continue;
-    if( BG_InventoryContainsWeapon( i, stats ) )
-      return i;
-  }
-
-  if( BG_InventoryContainsWeapon( WP_BLASTER, stats ) )
-    return WP_BLASTER;
-
-  return WP_NONE;
-}
-
-/*
-============
 BG_LoadEmoticons
 ============
 */
Index: src/game/g_client.c
===================================================================
--- src/game/g_client.c (revision 2269)
+++ src/game/g_client.c (working copy)
@@ -1484,18 +1484,7 @@ void ClientSpawn( gentity_t *ent, gentity_t *spawn
     if( !spawn )
       G_UseTargets( spawnPoint, ent );
 
-    // select the highest weapon number available, after any
-    // spawn given items have fired
-    client->ps.weapon = 1;
-
-    for( i = WP_NUM_WEAPONS - 1; i > 0 ; i-- )
-    {
-      if( BG_InventoryContainsWeapon( i, client->ps.stats ) )
-      {
-        client->ps.weapon = i;
-        break;
-      }
-    }
+    client->ps.weapon = client->ps.stats[ STAT_WEAPON ];
   }
 
   // run a client frame to drop exactly to the floor,
Index: src/game/g_cmds.c
===================================================================
--- src/game/g_cmds.c   (revision 2269)
+++ src/game/g_cmds.c   (working copy)
@@ -1089,7 +1089,7 @@ void Cmd_VSay_f( gentity_t *ent )
   weapon = WP_NONE;
   if( ent->client->sess.spectatorState == SPECTATOR_NOT )
   {
-    weapon = BG_PrimaryWeapon( ent->client->ps.stats );
+    weapon = ent->client->ps.stats[ STAT_WEAPON ];
   }
 
   track = BG_VoiceTrackFind( cmd->tracks, ent->client->pers.teamSelection,
@@ -2311,7 +2311,7 @@ void Cmd_Sell_f( gentity_t *ent )
 
     //if we have this weapon selected, force a new selection
     if( weapon == selected )
-      G_ForceWeaponChange( ent, WP_NONE );
+      G_ForceWeaponChange( ent, selected );
   }
   else if( upgrade != UP_NONE )
   {
@@ -2350,36 +2350,6 @@ void Cmd_Sell_f( gentity_t *ent )
       G_AddCreditToClient( ent->client, (short)BG_Upgrade( upgrade )->price, qfalse );
     }
   }
-  else if( !Q_stricmp( s, "weapons" ) )
-  {
-    weapon_t selected = BG_GetPlayerWeapon( &ent->client->ps );
-
-    if( !BG_PlayerCanChangeWeapon( &ent->client->ps ) )
-      return;
-
-    for( i = WP_NONE + 1; i < WP_NUM_WEAPONS; i++ )
-    {
-      //guard against selling the HBUILD weapons exploit
-      if( i == WP_HBUILD && ent->client->ps.stats[ STAT_MISC ] > 0 )
-      {
-        G_TriggerMenu( ent->client->ps.clientNum, MN_H_ARMOURYBUILDTIMER );
-        continue;
-      }
-
-      if( BG_InventoryContainsWeapon( i, ent->client->ps.stats ) &&
-          BG_Weapon( i )->purchasable )
-      {
-        ent->client->ps.stats[ STAT_WEAPON ] = WP_NONE;
-
-        //add to funds
-        G_AddCreditToClient( ent->client, (short)BG_Weapon( i )->price, qfalse );
-      }
-
-      //if we have this weapon selected, force a new selection
-      if( i == selected )
-        G_ForceWeaponChange( ent, WP_NONE );
-    }
-  }
   else if( !Q_stricmp( s, "upgrades" ) )
   {
     for( i = UP_NONE + 1; i < UP_NUM_UPGRADES; i++ )
Index: src/game/g_trigger.c
===================================================================
--- src/game/g_trigger.c        (revision 2269)
+++ src/game/g_trigger.c        (working copy)
@@ -1097,7 +1097,7 @@ void trigger_ammo_touch( gentity_t *self, gentity_
   if( other->client->ps.weaponstate != WEAPON_READY )
     return;
 
-  weapon = BG_PrimaryWeapon( other->client->ps.stats );
+  weapon = other->client->ps.stats[ STAT_WEAPON ];
   if( BG_Weapon( weapon )->usesEnergy && self->spawnflags & 2 )
     return;
 
Index: src/game/g_active.c
===================================================================
--- src/game/g_active.c (revision 2269)
+++ src/game/g_active.c (working copy)
@@ -606,7 +606,7 @@ void ClientTimerActions( gentity_t *ent, int msec
       client->ps.stats[ STAT_STAMINA ] = -STAMINA_MAX;
 
     if( weapon == WP_ABUILD || weapon == WP_ABUILD2 ||
-        BG_InventoryContainsWeapon( WP_HBUILD, client->ps.stats ) )
+        client->ps.stats[ STAT_WEAPON ] == WP_HBUILD )
     {
         // Update build timer
         if( client->ps.stats[ STAT_MISC ] > 0 )
Index: src/game/bg_public.h
===================================================================
--- src/game/bg_public.h        (revision 2269)
+++ src/game/bg_public.h        (working copy)
@@ -1242,7 +1242,6 @@ qboolean BG_WeaponIsAllowed( weapon_t weapon );
 qboolean BG_UpgradeIsAllowed( upgrade_t upgrade );
 qboolean BG_ClassIsAllowed( class_t class );
 qboolean BG_BuildableIsAllowed( buildable_t buildable );
-weapon_t BG_PrimaryWeapon( int stats[ ] );
 
 // Friendly Fire Flags
 #define FFF_HUMANS         1
Index: src/game/g_weapon.c
===================================================================
--- src/game/g_weapon.c (revision 2269)
+++ src/game/g_weapon.c (working copy)
@@ -45,17 +45,10 @@ void G_ForceWeaponChange( gentity_t *ent, weapon_t
     ps->weaponTime = 250;
     ps->weaponstate = WEAPON_READY;
   }
-  
-  if( weapon == WP_NONE ||
-      !BG_InventoryContainsWeapon( weapon, ps->stats ) )
-  {
-    // switch to the first non blaster weapon
-    ps->persistant[ PERS_NEWWEAPON ] =
-      BG_PrimaryWeapon( ent->client->ps.stats );
-  }
-  else
-    ps->persistant[ PERS_NEWWEAPON ] = weapon;
 
+  ps->persistant[ PERS_NEWWEAPON ] = ( weapon == WP_BLASTER ) ?
+    WP_BLASTER : ps->stats[ STAT_WEAPON ];
+
   // force this here to prevent flamer effect from continuing
   ps->generic1 = WPM_NOTFIRING;
 
@@ -70,42 +63,34 @@ G_GiveClientMaxAmmo
 */
 void G_GiveClientMaxAmmo( gentity_t *ent, qboolean buyingEnergyAmmo )
 {
-  int i, maxAmmo, maxClips;
-  qboolean restoredAmmo = qfalse, restoredEnergy = qfalse;
+  int maxAmmo;
+  weapon_t weapon = ent->client->ps.stats[ STAT_WEAPON ];
 
-  for( i = WP_NONE + 1; i < WP_NUM_WEAPONS; i++ )
-  {
-    qboolean energyWeapon;
-  
-    energyWeapon = BG_Weapon( i )->usesEnergy;
-    if( !BG_InventoryContainsWeapon( i, ent->client->ps.stats ) ||
-        BG_Weapon( i )->infiniteAmmo ||
-        BG_WeaponIsFull( i, ent->client->ps.stats,
-                         ent->client->ps.ammo, ent->client->ps.clips ) ||
-        ( buyingEnergyAmmo && !energyWeapon ) )
-      continue;
-      
-    maxAmmo = BG_Weapon( i )->maxAmmo;
-    maxClips = BG_Weapon( i )->maxClips;
-    
-    // Apply battery pack modifier
-    if( energyWeapon &&
-        BG_InventoryContainsUpgrade( UP_BATTPACK, ent->client->ps.stats ) )
-    {
-      maxAmmo *= BATTPACK_MODIFIER;
-      restoredEnergy = qtrue;
-    }
+  if( BG_Weapon( weapon )->infiniteAmmo )
+    return;
 
-    ent->client->ps.ammo = maxAmmo;
-    ent->client->ps.clips = maxClips;
+  if( buyingEnergyAmmo && !BG_Weapon( weapon )->usesEnergy )
+    return;
 
-    restoredAmmo = qtrue;
+  if( BG_WeaponIsFull( weapon, ent->client->ps.stats, ent->client->ps.ammo,
+                       ent->client->ps.clips ) )
+    return;
+
+  maxAmmo = BG_Weapon( weapon )->maxAmmo;
+
+  // Apply battery pack modifier
+  if( BG_Weapon( weapon )->usesEnergy &&
+      BG_InventoryContainsUpgrade( UP_BATTPACK, ent->client->ps.stats ) )
+  {
+    maxAmmo *= BATTPACK_MODIFIER;
   }
 
-  if( restoredAmmo )
-    G_ForceWeaponChange( ent, ent->client->ps.weapon );
+  ent->client->ps.ammo = maxAmmo;
+  ent->client->ps.clips = BG_Weapon( weapon )->maxClips;
 
-  if( restoredEnergy )
+  G_ForceWeaponChange( ent, ent->client->ps.weapon );
+
+  if( BG_Weapon( weapon )->usesEnergy )
     G_AddEvent( ent, EV_RPTUSE_SOUND, 0 );
 }
 
Index: src/cgame/cg_draw.c
===================================================================
--- src/cgame/cg_draw.c (revision 2269)
+++ src/cgame/cg_draw.c (working copy)
@@ -636,7 +636,7 @@ static void CG_DrawPlayerAmmoValue( rectDef_t *rec
   int valueMarked = -1;
   qboolean bp = qfalse;
 
-  switch( BG_PrimaryWeapon( cg.snap->ps.stats ) )
+  switch( cg.snap->ps.stats[ STAT_WEAPON ] )
   {
     case WP_NONE:
     case WP_BLASTER:
@@ -776,7 +776,7 @@ static void CG_DrawPlayerBuildTimer( rectDef_t *re
   if( ps->stats[ STAT_MISC ] <= 0 )
     return;
 
-  switch( BG_PrimaryWeapon( ps->stats ) )
+  switch( ps->stats[ STAT_WEAPON ] )
   {
     case WP_ABUILD:
     case WP_ABUILD2:
@@ -812,7 +812,7 @@ static void CG_DrawPlayerClipsValue( rectDef_t *re
   int           value;
   playerState_t *ps = &cg.snap->ps;
 
-  switch( BG_PrimaryWeapon( ps->stats ) )
+  switch( ps->stats[ STAT_WEAPON ] )
   {
     case WP_NONE:
     case WP_BLASTER:
Index: src/cgame/cg_weapons.c
===================================================================
--- src/cgame/cg_weapons.c      (revision 2269)
+++ src/cgame/cg_weapons.c      (working copy)
@@ -1353,10 +1353,7 @@ CG_WeaponSelectable
 */
 static qboolean CG_WeaponSelectable( weapon_t weapon )
 {
-  if( !BG_InventoryContainsWeapon( weapon, cg.snap->ps.stats ) )
-    return qfalse;
-
-  return qtrue;
+  return BG_InventoryContainsWeapon( weapon, cg.snap->ps.stats );
 }
 
 
Index: src/cgame/cg_main.c
===================================================================
--- src/cgame/cg_main.c (revision 2269)
+++ src/cgame/cg_main.c (working copy)
@@ -400,12 +400,9 @@ static void CG_SetUIVars( void )
   *carriageCvar = 0;
 
   //determine what the player is carrying
-  for( i = WP_NONE + 1; i < WP_NUM_WEAPONS; i++ )
-  {
-    if( BG_InventoryContainsWeapon( i, cg.snap->ps.stats ) &&
-        BG_Weapon( i )->purchasable )
-      strcat( carriageCvar, va( "W%d ", i ) );
-  }
+  if( BG_Weapon( cg.snap->ps.stats[ STAT_WEAPON ] )->purchasable )
+    strcat( carriageCvar, va( "W%d ", cg.snap->ps.stats[ STAT_WEAPON ] ) );
+
   for( i = UP_NONE + 1; i < UP_NUM_UPGRADES; i++ )
   {
     if( BG_InventoryContainsUpgrade( i, cg.snap->ps.stats ) &&

expand all expand all

Show diffs side-by-side

added added

removed removed

Lines of Context: