]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/weapons/weaponsystem.qc
Fix HMG
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / weaponsystem.qc
index ddf1424439d14e77008ff60580819bd73ecec595..762f9a0e3dc12b619b531128366b6d9f0c36506f 100644 (file)
@@ -14,6 +14,10 @@ float W_WeaponRateFactor()
        float t;
        t = 1.0 / g_weaponratefactor;
 
+       weapon_rate = t;
+       MUTATOR_CALLHOOK(WeaponRateFactor);
+       t = weapon_rate;
+
        return t;
 }
 
@@ -322,14 +326,12 @@ void CL_Weaponentity_Think()
        {
                entity newwep = get_weaponinfo(self.owner.switchweapon);
                f = f * g_weaponratefactor / max(f, newwep.switchdelay_raise);
-               //print(sprintf("CL_Weaponentity_Think(): cvar: %s, value: %f, nextthink: %f\n", sprintf("g_balance_%s_switchdelay_raise", newwep.netname), cvar(sprintf("g_balance_%s_switchdelay_raise", newwep.netname)), (self.owner.weapon_nextthink - time)));
                self.angles_x = -90 * f * f;
        }
        else if (self.state == WS_DROP && !intermission_running)
        {
                entity oldwep = get_weaponinfo(self.owner.weapon);
                f = 1 - f * g_weaponratefactor / max(f, oldwep.switchdelay_drop);
-               //print(sprintf("CL_Weaponentity_Think(): cvar: %s, value: %f, nextthink: %f\n", sprintf("g_balance_%s_switchdelay_drop", oldwep.netname), cvar(sprintf("g_balance_%s_switchdelay_drop", oldwep.netname)), (self.owner.weapon_nextthink - time)));
                self.angles_x = -90 * f * f;
        }
        else if (self.state == WS_CLEAR)
@@ -456,6 +458,10 @@ float weapon_prepareattack_checkammo(float secondary)
                for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
                        return FALSE;
 
+               if(self.weapon == WEP_SHOTGUN)
+               if(!secondary && WEP_CVAR(shotgun, secondary) == 1)
+                       return FALSE; // no clicking, just allow
+
                if(self.weapon == self.switchweapon && time - self.prevdryfire > 1) // only play once BEFORE starting to switch weapons
                {
                        sound (self, CH_WEAPON_A, "weapons/dryfire.wav", VOL_BASE, ATTEN_NORM);
@@ -613,7 +619,7 @@ void weapon_thinkf(float fr, float t, void() func)
 
        if((fr == WFRAME_FIRE1 || fr == WFRAME_FIRE2) && t)
        {
-               if(self.weapon == WEP_SHOTGUN && fr == WFRAME_FIRE2)
+               if((self.weapon == WEP_SHOCKWAVE || self.weapon == WEP_SHOTGUN) && fr == WFRAME_FIRE2)
                        animdecide_setaction(self, ANIMACTION_MELEE, restartanim);
                else
                        animdecide_setaction(self, ANIMACTION_SHOOT, restartanim);
@@ -633,7 +639,9 @@ float forbidWeaponUse()
                return 1;
        if(self.player_blocked)
                return 1;
-       if(self.freezetag_frozen)
+       if(self.frozen)
+               return 1;
+       if(self.weapon_blocked)
                return 1;
        return 0;
 }
@@ -661,7 +669,7 @@ void W_WeaponFrame()
                self.switchingweapon = 0;
                self.weaponentity.state = WS_CLEAR;
                self.weaponname = "";
-               self.items &= ~IT_AMMO;
+               //self.items &= ~IT_AMMO;
                return;
        }
 
@@ -679,13 +687,11 @@ void W_WeaponFrame()
                        self.switchingweapon = self.switchweapon;
                        entity newwep = get_weaponinfo(self.switchweapon);
 
-                       self.items &= ~IT_AMMO;
-                       self.items = self.items | (newwep.items & IT_AMMO);
-
                        // the two weapon entities will notice this has changed and update their models
                        self.weapon = self.switchweapon;
                        self.weaponname = newwep.mdl;
-                       self.bulletcounter = 0; // WEAPONTODO
+                       self.bulletcounter = 0;
+                       //self.ammo_field = newwep.ammo_field;
                        WEP_ACTION(self.switchweapon, WR_SETUP);
                        self.weaponentity.state = WS_RAISE;
 
@@ -698,10 +704,7 @@ void W_WeaponFrame()
                        else
                                self.clip_load = self.clip_size = 0;
 
-                       // VorteX: add player model weapon select frame here
-                       // setcustomframe(PlayerWeaponRaise);
                        weapon_thinkf(WFRAME_IDLE, newwep.switchdelay_raise, w_ready);
-                       //print(sprintf("W_WeaponFrame(): cvar: %s, value: %f\n", sprintf("g_balance_%s_switchdelay_raise", newwep.netname), cvar(sprintf("g_balance_%s_switchdelay_raise", newwep.netname))));
                }
                else if (self.weaponentity.state == WS_DROP)
                {
@@ -712,21 +715,19 @@ void W_WeaponFrame()
                {
                        // start switching!
                        self.switchingweapon = self.switchweapon;
-
                        entity oldwep = get_weaponinfo(self.weapon);
-                       
-#ifndef INDEPENDENT_ATTACK_FINISHED
+
+                       // set up weapon switch think in the future, and start drop anim
+                       #ifndef INDEPENDENT_ATTACK_FINISHED
                        if(ATTACK_FINISHED(self) <= time + self.weapon_frametime * 0.5)
                        {
-#endif
-                       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, oldwep.switchdelay_drop, w_clear);
-                       //print(sprintf("W_WeaponFrame(): cvar: %s, value: %f\n", sprintf("g_balance_%s_switchdelay_drop", oldwep.netname), cvar(sprintf("g_balance_%s_switchdelay_drop", oldwep.netname))));
-#ifndef INDEPENDENT_ATTACK_FINISHED
+                       #endif
+                               sound(self, CH_WEAPON_SINGLE, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
+                               self.weaponentity.state = WS_DROP;
+                               weapon_thinkf(WFRAME_DONTCHANGE, oldwep.switchdelay_drop, w_clear);
+                       #ifndef INDEPENDENT_ATTACK_FINISHED
                        }
-#endif
+                       #endif
                }
        }
 
@@ -774,19 +775,6 @@ void W_WeaponFrame()
                                bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n");
                }
        }
-
-#if 0
-       if (self.items & IT_CELLS)
-               self.currentammo = self.ammo_cells;
-       else if (self.items & IT_ROCKETS)
-               self.currentammo = self.ammo_rockets;
-       else if (self.items & IT_NAILS)
-               self.currentammo = self.ammo_nails;
-       else if (self.items & IT_SHELLS)
-               self.currentammo = self.ammo_shells;
-       else
-               self.currentammo = 1;
-#endif
 }
 
 void W_AttachToShotorg(entity flash, vector offset)
@@ -821,19 +809,42 @@ void W_AttachToShotorg(entity flash, vector offset)
        }
 }
 
-void W_DecreaseAmmo(.float ammo_type, float ammo_use, float ammo_reload) // WEAPONTODO: why does this have ammo_type?
+void W_DecreaseAmmo(float ammo_use)
 {
-       if((self.items & IT_UNLIMITED_WEAPON_AMMO) && !ammo_reload)
+       entity wep = get_weaponinfo(self.weapon);
+
+       if(cvar("g_overkill"))
+       if(self.ok_use_ammocharge)
+       {
+               ok_DecreaseCharge(self, self.weapon);
+               return; // TODO
+       }
+
+       if((self.items & IT_UNLIMITED_WEAPON_AMMO) && !wep.reloading_ammo)
                return;
 
        // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
-       if(ammo_reload)
+       if(wep.reloading_ammo)
        {
                self.clip_load -= ammo_use;
                self.(weapon_load[self.weapon]) = self.clip_load;
        }
-       else
-               self.(self.current_ammo) -= ammo_use;
+       else if(wep.ammo_field != ammo_none)
+       {
+               self.(wep.ammo_field) -= ammo_use;
+               if(self.(wep.ammo_field) < 0)
+               {
+                       backtrace(sprintf(
+                               "W_DecreaseAmmo(%.2f): '%s' subtracted too much %s from '%s', resulting with '%.2f' left... "
+                               "Please notify Samual immediately with a copy of this backtrace!\n",
+                               ammo_use,
+                               wep.netname,
+                               GetAmmoPicture(wep.ammo_field),
+                               self.netname,
+                               self.(wep.ammo_field)
+                       ));
+               }
+       }
 }
 
 // weapon reloading code
@@ -849,14 +860,14 @@ void W_ReloadedAndReady()
        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)
+       if(!self.reload_ammo_min || self.items & IT_UNLIMITED_WEAPON_AMMO || self.ammo_field == ammo_none)
                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
+               while(self.clip_load < self.reload_ammo_amount && self.(self.ammo_field)) // make sure we don't add more ammo than we have
                {
                        self.clip_load += 1;
-                       self.(self.current_ammo) -= 1;
+                       self.(self.ammo_field) -= 1;
                }
        }
        self.(weapon_load[self.weapon]) = self.clip_load;
@@ -876,6 +887,10 @@ void W_Reload(float sent_ammo_min, string sent_sound)
        entity e;
        e = get_weaponinfo(self.weapon);
 
+       if(cvar("g_overkill"))
+       if(self.ok_use_ammocharge)
+               return; // TODO
+
        self.reload_ammo_min = sent_ammo_min;
        self.reload_ammo_amount = e.reloading_ammo;;
        self.reload_time = e.reloading_time;
@@ -897,13 +912,14 @@ void W_Reload(float sent_ammo_min, string sent_sound)
                return;
 
        // no ammo, so nothing to load
-       if(!self.(self.current_ammo) && self.reload_ammo_min)
+       if(self.ammo_field != ammo_none)
+       if(!self.(self.ammo_field) && self.reload_ammo_min)
        if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
        {
                if(IS_REAL_CLIENT(self) && self.reload_complain < time)
                {
                        play2(self, "weapons/unavailable.wav");
-                       sprint(self, strcat("You don't have enough ammo to reload the ^2", W_Name(self.weapon), "\n"));
+                       sprint(self, strcat("You don't have enough ammo to reload the ^2", WEP_NAME(self.weapon), "\n"));
                        self.reload_complain = time + 1;
                }
                // switch away if the amount of ammo is not enough to keep using this weapon
@@ -941,3 +957,13 @@ void W_Reload(float sent_ammo_min, string sent_sound)
        self.old_clip_load = self.clip_load;
        self.clip_load = self.(weapon_load[self.weapon]) = -1;
 }
+
+entity weapon_dropevent_item;
+void W_DropEvent(float event, entity player, float weapon_type, entity weapon_item)
+{
+       entity oldself = self;
+       self = player;
+       weapon_dropevent_item = weapon_item;
+       WEP_ACTION(weapon_type, event);
+       self = oldself;
+}