]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_weaponsystem.qc
Merge remote-tracking branch 'origin/master' into fruitiex/animations
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_weaponsystem.qc
index 616aee69dc0b435ad7f718db0c9cbacc2cce99fd..b18e1c847cbe8feef94c0f547c577ccadd3b48a5 100644 (file)
@@ -34,6 +34,10 @@ float W_WeaponRateFactor()
 
 void W_SwitchWeapon_Force(entity e, float w)
 {
+       // don't switch to another weapon if we're not allowed to
+       if(e.weapon_forbidchange)
+               return;
+
        e.cnt = e.switchweapon;
        e.switchweapon = w;
        e.selectweapon = w;
@@ -138,7 +142,7 @@ void W_SetupShot_Dir_ProjectileSize_Range(entity ent, vector s_forward, vector m
        local float oldsolid;
        vector vecs, dv;
        oldsolid = ent.dphitcontentsmask;
-       if(ent.weapon == WEP_SNIPERRIFLE)
+       if(ent.weapon == WEP_RIFLE)
                ent.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_CORPSE;
        else
                ent.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
@@ -824,33 +828,36 @@ void CL_ExteriorWeaponentity_Think()
        else
                self.alpha = 1;
 
-       ang_x = bound(sv_pitch_min, self.owner.v_angle_x, sv_pitch_max);
-       ang_y = 0;
-       ang_z = 0;
-
-       if(sv_pitch_fixyaw) // workaround for stupid player models that don't aim forward
-       {
-               ang_y = self.owner.v_angle_y;
-               makevectors(ang);
-               var vector v = v_forward;
-               var float t = self.tag_entity.frame1time;
-               var float f = self.tag_entity.frame;
-               self.tag_entity.frame1time = time;
-               self.tag_entity.frame = self.tag_entity.anim_idle_x;
-               gettaginfo(self.tag_entity, self.tag_index);
-               self.tag_entity.frame1time = t;
-               self.tag_entity.frame = f;
-               // untransform v according to this coordinate space
-               vector w;
-               w_x = v_forward * v;
-               w_y = -v_right * v;
-               w_z = v_up * v;
-               self.angles = vectoangles(w);
-       }
-       else
+       if (!intermission_running)
        {
-               ang_x = -/* don't ask */ang_x;
-               self.angles = ang;
+               ang_x = bound(sv_pitch_min, self.owner.v_angle_x, sv_pitch_max);
+               ang_y = 0;
+               ang_z = 0;
+
+               if(sv_pitch_fixyaw) // workaround for stupid player models that don't aim forward
+               {
+                       ang_y = self.owner.v_angle_y;
+                       makevectors(ang);
+                       var vector v = v_forward;
+                       var float t = self.tag_entity.frame1time;
+                       var float f = self.tag_entity.frame;
+                       self.tag_entity.frame1time = time;
+                       self.tag_entity.frame = self.tag_entity.anim_idle_x;
+                       gettaginfo(self.tag_entity, self.tag_index);
+                       self.tag_entity.frame1time = t;
+                       self.tag_entity.frame = f;
+                       // untransform v according to this coordinate space
+                       vector w;
+                       w_x = v_forward * v;
+                       w_y = -v_right * v;
+                       w_z = v_up * v;
+                       self.angles = vectoangles(w);
+               }
+               else
+               {
+                       ang_x = -/* don't ask */ang_x;
+                       self.angles = ang;
+               }
        }
 
        self.glowmod = self.owner.weaponentity_glowmod;
@@ -1253,14 +1260,25 @@ void weapon_thinkf(float fr, float t, void() func)
        self.weapon_think = func;
        //dprint("next ", ftos(self.weapon_nextthink), "\n");
 
+       // The shoot animation looks TERRIBLE without animation blending! Yay for moonwalking while shooting!
+       //anim = self.anim_shoot;
        if (restartanim)
        if (t)
        if (!self.crouch) // shoot anim stands up, this looks bad
        {
-               local vector anim;
-               anim = self.anim_shoot;
-               anim_z = anim_y / (t + sys_frametime);
-               setanim(self, anim, FALSE, TRUE, TRUE);
+               vector anim;
+               if(self.weapon == WEP_SHOTGUN && self.BUTTON_ATCK2)
+               {
+                       anim = self.anim_melee;
+                       anim_z = anim_y / (t + sys_frametime);
+                       setanim(self, anim, FALSE, TRUE, TRUE);
+               }
+               else if (self.animstate_startframe == self.anim_idle_x) // only allow shoot anim to override idle animation until we have animation blending
+               {
+                       anim = self.anim_shoot;
+                       anim_z = anim_y / (t + sys_frametime);
+                       setanim(self, anim, FALSE, TRUE, TRUE);
+               }
        }
 };
 
@@ -1614,7 +1632,7 @@ void W_SetupProjectileVelocity(entity missile, float pSpeed, float spread)
 
 void W_DecreaseAmmo(.float ammo_type, float ammo_use, float ammo_reload)
 {
-       if(self.items & IT_UNLIMITED_WEAPON_AMMO)
+       if((self.items & IT_UNLIMITED_WEAPON_AMMO) && !ammo_reload)
                return;
 
        // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
@@ -1633,8 +1651,43 @@ void W_DecreaseAmmo(.float ammo_type, float ammo_use, float ammo_reload)
 .float reload_complain;
 .string reload_sound;
 
-float W_ReloadCheck()
+void W_ReloadedAndReady()
+{
+       // finish the reloading process, and do the ammo transfer
+
+       self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
+
+       // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load
+       if(!self.reload_ammo_min || self.items & IT_UNLIMITED_WEAPON_AMMO)
+               self.clip_load = self.reload_ammo_amount;
+       else
+       {
+               while(self.clip_load < self.reload_ammo_amount && self.(self.current_ammo)) // make sure we don't add more ammo than we have
+               {
+                       self.clip_load += 1;
+                       self.(self.current_ammo) -= 1;
+               }
+       }
+       self.weapon_load[self.weapon] = self.clip_load;
+
+       // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
+       // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
+       // so your weapon is disabled for a few seconds without reason
+
+       //ATTACK_FINISHED(self) -= self.reload_time - 1;
+
+       w_ready();
+}
+
+void W_Reload(float sent_ammo_min, float sent_ammo_amount, float sent_time, string sent_sound)
 {
+       // set global values to work with
+
+       self.reload_ammo_min = sent_ammo_min;
+       self.reload_ammo_amount = sent_ammo_amount;
+       self.reload_time = sent_time;
+       self.reload_sound = sent_sound;
+
        // check if we meet the necessary conditions to reload
 
        entity e;
@@ -1644,19 +1697,20 @@ float W_ReloadCheck()
        if not(e.spawnflags & WEP_FLAG_RELOADABLE)
        {
                dprint("Warning: Attempted to reload a weapon that does not have the WEP_FLAG_RELOADABLE flag. Fix your code!\n");
-               return FALSE;
+               return;
        }
 
        // return if reloading is disabled for this weapon
        if(!self.reload_ammo_amount)
-               return FALSE;
+               return;
 
        // our weapon is fully loaded, no need to reload
        if (self.clip_load >= self.reload_ammo_amount)
-               return FALSE;
+               return;
 
        // no ammo, so nothing to load
        if(!self.(self.current_ammo) && self.reload_ammo_min)
+       if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
        {
                if(clienttype(self) == CLIENTTYPE_REAL && self.reload_complain < time)
                {
@@ -1670,60 +1724,18 @@ float W_ReloadCheck()
                        self.clip_load = -1; // reload later
                        W_SwitchToOtherWeapon(self);
                }
-               return FALSE;
+               return;
        }
 
        if (self.weaponentity)
        {
                if (self.weaponentity.wframe == WFRAME_RELOAD)
-                       return FALSE;
+                       return;
 
                // allow switching away while reloading, but this will cause a new reload!
                self.weaponentity.state = WS_READY;
        }
 
-       return TRUE;
-}
-
-void W_ReloadedAndReady()
-{
-       // finish the reloading process, and do the ammo transfer
-
-       self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
-
-       // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load
-       if(!self.reload_ammo_min)
-               self.clip_load = self.reload_ammo_amount;
-       else
-       {
-               while(self.clip_load < self.reload_ammo_amount && self.(self.current_ammo)) // make sure we don't add more ammo than we have
-               {
-                       self.clip_load += 1;
-                       self.(self.current_ammo) -= 1;
-               }
-       }
-       self.weapon_load[self.weapon] = self.clip_load;
-
-       // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
-       // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
-       // so your weapon is disabled for a few seconds without reason
-
-       //ATTACK_FINISHED(self) -= self.reload_time - 1;
-
-       w_ready();
-}
-
-void W_Reload(float sent_ammo_min, float sent_ammo_amount, float sent_time, string sent_sound)
-{
-       // set global values to work with
-       self.reload_ammo_min = sent_ammo_min;
-       self.reload_ammo_amount = sent_ammo_amount;
-       self.reload_time = sent_time;
-       self.reload_sound = sent_sound;
-
-       if(!W_ReloadCheck())
-               return;
-
        // now begin the reloading process
 
        sound (self, CHAN_WEAPON2, self.reload_sound, VOL_BASE, ATTN_NORM);
@@ -1736,7 +1748,8 @@ void W_Reload(float sent_ammo_min, float sent_ammo_amount, float sent_time, stri
 
        weapon_thinkf(WFRAME_RELOAD, self.reload_time, W_ReloadedAndReady);
 
-       if(self.clip_load >= 0)
-               self.old_clip_load = self.clip_load;
+       if(self.clip_load < 0)
+               self.clip_load = 0;
+       self.old_clip_load = self.clip_load;
        self.clip_load = self.weapon_load[self.weapon] = -1;
-}
\ No newline at end of file
+}