]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_weaponsystem.qc
sv_cmd gettaginfo: print more info
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_weaponsystem.qc
index e17c346d283373e2c96de40c34ab709685806872..15898759ede6b82578b755a365ecebcda5a1cc36 100644 (file)
@@ -1031,29 +1031,39 @@ void weapon_setup(float windex)
 };
 
 // perform weapon to attack (weaponstate and attack_finished check is here)
+void W_SwitchToOtherWeapon(entity pl)
+{
+       // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway)
+       float w, ww;
+       w = W_WeaponBit(pl.weapon);
+       pl.weapons &~= w;
+       ww = w_getbestweapon(pl);
+       pl.weapons |= w;
+       if(ww)
+               W_SwitchWeapon_Force(pl, ww);
+}
+float weapon_prepareattack_checkammo(float secondary)
+{
+       if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
+       if (!weapon_action(self.weapon, WR_CHECKAMMO1 + secondary))
+       {
+               W_SwitchToOtherWeapon(self);
+               return FALSE;
+       }
+       return TRUE;
+}
 .float race_penalty;
-float weapon_prepareattack(float secondary, float attacktime)
+float weapon_prepareattack_check(float secondary, float attacktime)
 {
+       if(!weapon_prepareattack_checkammo(secondary))
+               return FALSE;
+
        //if sv_ready_restart_after_countdown is set, don't allow the player to shoot
        //if all players readied up and the countdown is running
        if(time < game_starttime || time < self.race_penalty) {
                return FALSE;
        }
 
-       if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
-       if (!weapon_action(self.weapon, WR_CHECKAMMO1 + secondary))
-       {
-               // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway)
-               float w, ww;
-               w = W_WeaponBit(self.weapon);
-               self.weapons &~= w;
-               ww = w_getbestweapon(self);
-               self.weapons |= w;
-               if(ww)
-                       W_SwitchWeapon_Force(self, ww);
-               return FALSE;
-       }
-
        if (timeoutStatus == 2) //don't allow the player to shoot while game is paused
                return FALSE;
 
@@ -1070,6 +1080,11 @@ float weapon_prepareattack(float secondary, float attacktime)
                if (self.weaponentity.state != WS_READY)
                        return FALSE;
        }
+
+       return TRUE;
+}
+float weapon_prepareattack_do(float secondary, float attacktime)
+{
        self.weaponentity.state = WS_INUSE;
 
        self.spawnshieldtime = min(self.spawnshieldtime, time); // kill spawn shield when you fire
@@ -1087,7 +1102,17 @@ float weapon_prepareattack(float secondary, float attacktime)
        self.bulletcounter += 1;
        //dprint("attack finished ", ftos(ATTACK_FINISHED(self)), "\n");
        return TRUE;
-};
+}
+float weapon_prepareattack(float secondary, float attacktime)
+{
+       if(weapon_prepareattack_check(secondary, attacktime))
+       {
+               weapon_prepareattack_do(secondary, attacktime);
+               return TRUE;
+       }
+       else
+               return FALSE;
+}
 
 void weapon_thinkf(float fr, float t, void() func)
 {