]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_weapons.qc
Merge branch 'tzork/gm_nexball' of git://de.git.xonotic.org/xonotic/xonotic-data...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_weapons.qc
index 9e59a4c5554edb9205d74ea6549893aff2641b06..dc827c9a21d019d833d97c2722d76fed77306b9a 100644 (file)
@@ -17,7 +17,7 @@ void W_SwitchWeapon(float imp)
        {
                W_TriggerReload();
        }
-};
+}
 
 .float weaponcomplainindex;
 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing)
@@ -137,17 +137,26 @@ 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);
-};
+}
 
 // generic weapons table
 // TODO should they be macros instead?
 float weapon_action(float wpn, float wrequest)
 {
        return (get_weaponinfo(wpn)).weapon_func(wrequest);
-};
+}
 
 string W_Name(float weaponid)
 {
@@ -161,7 +170,7 @@ float W_WeaponBit(float wpn)
 
 float W_AmmoItemCode(float wpn)
 {
-       return (get_weaponinfo(wpn)).items;
+       return (get_weaponinfo(wpn)).items & IT_AMMO;
 }
 
 void thrown_wep_think()
@@ -189,7 +198,7 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto
        wep.colormap = own.colormap;
 
        wa = W_AmmoItemCode(wpn);
-       if(wa == IT_SUPERWEAPON || wa == 0)
+       if(wa == 0)
        {
                oldself = self;
                self = wep;
@@ -211,7 +220,25 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto
                self = oldself;
                if(startitem_failed)
                        return string_null;
-               if(doreduce)
+               if(doreduce && g_weapon_stay == 2)
+               {
+                       for(i = 0, j = 1; i < 24; ++i, j *= 2)
+                       {
+                               if(wa & j)
+                               {
+                                       ammofield = Item_CounterField(j);
+                                       wep.ammofield = 0;
+
+                                       // if our weapon is loaded, give its load back to the player
+                                       if(self.(weapon_load[self.weapon]) > 0)
+                                       {
+                                               own.ammofield += self.(weapon_load[self.weapon]);
+                                               self.(weapon_load[self.weapon]) = -1; // schedule the weapon for reloading
+                                       }
+                               }
+                       }
+               }
+               else if(doreduce)
                {
                        for(i = 0, j = 1; i < 24; ++i, j *= 2)
                        {
@@ -224,10 +251,10 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto
                                        s = strcat(s, " and ", ftos(thisammo), " ", Item_CounterFieldName(j));
 
                                        // if our weapon is loaded, give its load back to the player
-                                       if(self.weapon_load[self.weapon] > 0)
+                                       if(self.(weapon_load[self.weapon]) > 0)
                                        {
-                                               own.ammofield += self.weapon_load[self.weapon];
-                                               self.weapon_load[self.weapon] = -1; // schedule the weapon for reloading
+                                               own.ammofield += self.(weapon_load[self.weapon]);
+                                               self.(weapon_load[self.weapon]) = -1; // schedule the weapon for reloading
                                        }
                                }
                        }
@@ -236,6 +263,7 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto
                wep.glowmod = own.weaponentity_glowmod;
                wep.think = thrown_wep_think;
                wep.nextthink = time + 0.5;
+               wep.pickup_anyway = TRUE; // these are ALWAYS pickable
                return s;
        }
 }
@@ -254,20 +282,18 @@ float W_IsWeaponThrowable(float w)
                return 0;
        if (g_cts)
                return 0;
-       if (g_nexball && w == WEP_GRENADE_LAUNCHER)
-               return 0;
 
        wb = W_WeaponBit(w);
        if(!wb)
                return 0;
+       if(wb & WEPBIT_SUPERWEAPONS) // can't throw a superweapon, they don't work
+               return 0;
        wa = W_AmmoItemCode(w);
        if(start_weapons & wb)
        {
-               if(wa == IT_SUPERWEAPON && start_items & IT_UNLIMITED_SUPERWEAPONS)
-                       return 0;
-               if(wa != IT_SUPERWEAPON && start_items & IT_UNLIMITED_WEAPON_AMMO)
-                       return 0;
                // start weapons that take no ammo can't be dropped (this prevents dropping the laser, as long as it continues to use no ammo)
+               if(start_items & IT_UNLIMITED_WEAPON_AMMO)
+                       return 0;
                if(wa == 0)
                        return 0;
        }
@@ -278,20 +304,16 @@ float W_IsWeaponThrowable(float w)
 // toss current weapon
 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
 {
-       local float w, wb;
+       float w, wb;
        string a;
 
        w = self.weapon;
        if (w == 0)
                return; // just in case
-       if(self.weapon_forbidchange)
-               return;
        if(MUTATOR_CALLHOOK(ForbidThrowCurrentWeapon))
                return;
        if(!autocvar_g_weapon_throwable)
                return;
-       if(autocvar_g_weapon_stay == 1)
-               return;
        if(self.weaponentity.state != WS_READY)
                return;
        if(!W_IsWeaponThrowable(w))
@@ -310,7 +332,7 @@ void W_ThrowWeapon(vector velo, vector delta, float doreduce)
                sprint(self, strcat("You dropped the ^2", W_Name(w), "\n"));
        else
                sprint(self, strcat("You dropped the ^2", W_Name(w), " with ", a, "\n"));
-};
+}
 
 // Bringed back weapon frame
 void W_WeaponFrame()
@@ -332,6 +354,7 @@ void W_WeaponFrame()
        if(!self.switchweapon)
        {
                self.weapon = 0;
+               self.switchingweapon = 0;
                self.weaponentity.state = WS_CLEAR;
                self.weaponname = "";
                self.items &~= IT_AMMO;
@@ -348,6 +371,9 @@ void W_WeaponFrame()
        {
                if (self.weaponentity.state == WS_CLEAR)
                {
+                       // end switching!
+                       self.switchingweapon = self.switchweapon;
+
                        //setanim(self, self.anim_draw, FALSE, TRUE, TRUE);
                        self.weaponentity.state = WS_RAISE;
                        weapon_action(self.switchweapon, WR_SETUP);
@@ -357,7 +383,7 @@ void W_WeaponFrame()
                        e = get_weaponinfo(self.switchweapon);
                        if(e.spawnflags & WEP_FLAG_RELOADABLE && cvar(strcat("g_balance_", e.netname, "_reload_ammo"))) // prevent accessing undefined cvars
                        {
-                               self.clip_load = self.weapon_load[self.switchweapon];
+                               self.clip_load = self.(weapon_load[self.switchweapon]);
                                self.clip_size = cvar(strcat("g_balance_", e.netname, "_reload_ammo"));
                        }
                        else
@@ -368,14 +394,21 @@ void W_WeaponFrame()
                        weapon_thinkf(WFRAME_IDLE, autocvar_g_balance_weaponswitchdelay, w_ready);
                        weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
                }
+               else if (self.weaponentity.state == WS_DROP)
+               {
+                       // in dropping phase we can switch at any time
+                       self.switchingweapon = self.switchweapon;
+               }
                else if (self.weaponentity.state == WS_READY)
                {
+                       // start switching!
+                       self.switchingweapon = self.switchweapon;
+
 #ifndef INDEPENDENT_ATTACK_FINISHED
                        if(ATTACK_FINISHED(self) <= time + self.weapon_frametime * 0.5)
                        {
 #endif
-                       // UGLY WORKAROUND: play this on CH_WEAPON_B so it can't cut off fire sounds
-                       sound (self, CH_WEAPON_B, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
+                       sound (self, CH_WEAPON_SINGLE, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
                        self.weaponentity.state = WS_DROP;
                        // set up weapon switch think in the future, and start drop anim
                        weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_weaponswitchdelay, w_clear);
@@ -396,23 +429,27 @@ void W_WeaponFrame()
        // call the think code which may fire the weapon
        // and do so multiple times to resolve framerate dependency issues if the
        // server framerate is very low and the weapon fire rate very high
-       local float c;
+       float c;
        c = 0;
        while (c < W_TICSPERFRAME)
        {
                c = c + 1;
                if(wb && ((self.weapons & wb) == 0))
                {
-                       W_SwitchWeapon_Force(self, w_getbestweapon(self));
+                       if(self.weapon == self.switchweapon)
+                               W_SwitchWeapon_Force(self, w_getbestweapon(self));
                        wb = 0;
                }
+
+               v_forward = fo;
+               v_right = ri;
+               v_up = up;
+
                if(wb)
-               {
-                       v_forward = fo;
-                       v_right = ri;
-                       v_up = up;
                        weapon_action(self.weapon, WR_THINK);
-               }
+               else
+                       weapon_action(self.weapon, WR_GONETHINK);
+
                if (time + self.weapon_frametime * 0.5 >= self.weapon_nextthink)
                {
                        if(self.weapon_think)
@@ -447,4 +484,4 @@ void W_WeaponFrame()
        else
                self.currentammo = 1;
 #endif
-};
+}