]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
make weaplast and laser secondary use the best other weapon if previous is unusable
authorMrBougo <mrbougo@xonotic.org>
Sun, 18 Sep 2011 12:09:51 +0000 (14:09 +0200)
committerMrBougo <mrbougo@xonotic.org>
Sun, 18 Sep 2011 12:09:51 +0000 (14:09 +0200)
this also makes weaplast use the second best weapon on spawn

qcsrc/server/cl_client.qc
qcsrc/server/cl_impulse.qc
qcsrc/server/cl_weapons.qc
qcsrc/server/w_laser.qc

index ef05663e5c58d5c2d4a01b2128acf036beb14642..dde6a26ab47255a067dbc3a06cf35f00589f7cb8 100644 (file)
@@ -1109,7 +1109,7 @@ void PutClientInServer (void)
                MUTATOR_CALLHOOK(PlayerSpawn);
 
                self.switchweapon = w_getbestweapon(self);
-               self.cnt = self.switchweapon;
+               self.cnt = -1; // W_LastWeapon will not complain
                self.weapon = 0;
                self.switchingweapon = 0;
 
index 939b6d2580b67a98b00b4cd3cf1590024922d2e6..9e211e5f504086be15b3c2bd7361262b946349fc 100644 (file)
@@ -70,7 +70,7 @@ void ImpulseCommands (void)
                                        W_NextWeapon (0);
                                        break;
                                case 11:
-                                       W_SwitchWeapon (self.cnt); // previously used
+                                       W_LastWeapon();
                                        break;
                                case 12:
                                        W_PreviousWeapon (0);
index fe678961848c54692bfc3e51250402b155cca1be..f0981f5e29cac8bc88e73893d7cf3579b3c2de63 100644 (file)
@@ -137,6 +137,15 @@ void W_PreviousWeapon(float list)
                W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
 }
 
+// previously used if exists and has ammo, (second) best otherwise
+void W_LastWeapon()
+{
+       if(client_hasweapon(self, self.cnt, TRUE, FALSE))
+               W_SwitchWeapon(self.cnt);
+       else
+               W_SwitchToOtherWeapon(self);
+}
+
 float w_getbestweapon(entity e)
 {
        return W_GetCycleWeapon(e, e.cvar_cl_weaponpriority, 0, -1, FALSE, TRUE);
index 5e034acb908f9bfe6b1b9a085b8c4dd10dd17a24..fa52a6e0dfb6ad2f7877538874af8333eefb2621 100644 (file)
@@ -3,6 +3,7 @@ REGISTER_WEAPON(LASER, w_laser, 0, 1, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WE
 #else
 #ifdef SVQC
 void(float imp) W_SwitchWeapon;
+void() W_LastWeapon;
 
 void W_Laser_Touch (void)
 {
@@ -259,7 +260,7 @@ float w_laser(float req)
                        else
                        {
                                if(self.switchweapon == WEP_LASER) // don't do this if already switching
-                                       W_SwitchWeapon (self.cnt);
+                                       W_LastWeapon();
                        }
                }
        }