]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/weapons/weaponsystem.qc
Merge branch 'sev/lumaIcons' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / weaponsystem.qc
index f8949b15601919e1b863084a1e5653ab3f94d9c2..2017e65a760792fd3d8f0db24603729a139e4cc5 100644 (file)
@@ -3,8 +3,9 @@
 #include "selection.qh"
 
 #include "../command/common.qh"
-#include "../mutators/_mod.qh"
+#include <server/mutators/_mod.qh>
 #include "../round_handler.qh"
+#include <server/resources.qh>
 #include <common/t_items.qh>
 #include <common/animdecide.qh>
 #include <common/constants.qh>
@@ -331,8 +332,6 @@ bool weapon_prepareattack(Weapon thiswep, entity actor, .entity weaponentity, bo
        return false;
 }
 
-void wframe_send(entity actor, entity weaponentity, vector a, bool restartanim);
-
 /**
  * @param t defer thinking until time + t
  * @param func next think function
@@ -417,7 +416,7 @@ void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void(
 
 bool forbidWeaponUse(entity player)
 {
-       if (time < game_starttime && !autocvar_sv_ready_restart_after_countdown) return true;
+       if (time < game_starttime && !sv_ready_restart_after_countdown) return true;
        if (player.player_blocked) return true;
        if (game_stopped) return true;
        if (STAT(FROZEN, player)) return true;
@@ -429,12 +428,12 @@ bool forbidWeaponUse(entity player)
 
 void W_WeaponFrame(Player actor, .entity weaponentity)
 {
-    TC(Player, actor);
-    TC(PlayerState, PS(actor));
+       TC(Player, actor);
+       TC(PlayerState, PS(actor));
        entity this = actor.(weaponentity);
        if (frametime) this.weapon_frametime = frametime;
 
-       if (!this || actor.health < 1) return;  // Dead player can't use weapons and injure impulse commands
+       if (!this || GetResourceAmount(actor, RESOURCE_HEALTH) < 1) return;  // Dead player can't use weapons and injure impulse commands
 
        int button_atck = PHYS_INPUT_BUTTON_ATCK(actor);
        int button_atck2 = PHYS_INPUT_BUTTON_ATCK2(actor);
@@ -471,6 +470,8 @@ void W_WeaponFrame(Player actor, .entity weaponentity)
 
        if (this.m_switchweapon == WEP_Null)
        {
+               if (this.state != WS_CLEAR)
+                       w_ready(this.m_weapon, actor, weaponentity, button_atck | (button_atck2 << 1));
                this.m_weapon = WEP_Null;
                this.m_switchingweapon = WEP_Null;
                this.state = WS_CLEAR;
@@ -556,7 +557,7 @@ void W_WeaponFrame(Player actor, .entity weaponentity)
        // server framerate is very low and the weapon fire rate very high
        for (int c = 0; c < W_TICSPERFRAME; ++c)
        {
-               if (w != WEP_Null && !(actor.weapons & WepSet_FromWeapon(w)))
+               if (w != WEP_Null && !(STAT(WEAPONS, actor) & WepSet_FromWeapon(w)))
                {
                        if (this.m_weapon == this.m_switchweapon) W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
                        w = WEP_Null;
@@ -573,7 +574,7 @@ void W_WeaponFrame(Player actor, .entity weaponentity)
                                key_pressed = false;
 
                        Weapon off = actor.offhand;
-                       if (off && !(actor.weapons & WEPSET(HOOK)))
+                       if (off && (!(STAT(WEAPONS, actor) & WEPSET(HOOK)) || off != OFFHAND_HOOK))
                        {
                                if (off.offhand_think) off.offhand_think(off, actor, key_pressed);
                        }
@@ -594,8 +595,8 @@ void W_WeaponFrame(Player actor, .entity weaponentity)
 
                if (!block_weapon)
                {
-            Weapon e = this.m_weapon;
-            TC(Weapon, e);
+                       Weapon e = this.m_weapon;
+                       TC(Weapon, e);
                        if (w != WEP_Null)
                        {
                                e.wr_think(e, actor, weaponentity, button_atck | (button_atck2 << 1));
@@ -657,9 +658,11 @@ void W_AttachToShotorg(entity actor, .entity weaponentity, entity flash, vector
 
 void W_DecreaseAmmo(Weapon wep, entity actor, float ammo_use, .entity weaponentity)
 {
-       if (MUTATOR_CALLHOOK(W_DecreaseAmmo, actor, actor.(weaponentity))) return;
+       if (MUTATOR_CALLHOOK(W_DecreaseAmmo, actor, actor.(weaponentity), ammo_use)) return;
        if ((actor.items & IT_UNLIMITED_WEAPON_AMMO) && !wep.reloading_ammo) return;
 
+       ammo_use = M_ARGV(2, float);
+
        entity w_ent = actor.(weaponentity);
 
        // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
@@ -668,21 +671,22 @@ void W_DecreaseAmmo(Weapon wep, entity actor, float ammo_use, .entity weaponenti
                w_ent.clip_load -= ammo_use;
                w_ent.(weapon_load[w_ent.m_weapon.m_id]) = w_ent.clip_load;
        }
-       else if (wep.ammo_field != ammo_none)
+       else if (wep.ammo_type != RESOURCE_NONE)
        {
-               actor.(wep.ammo_field) -= ammo_use;
-               if (actor.(wep.ammo_field) < 0)
+               float ammo = GetResourceAmount(actor, wep.ammo_type);
+               if (ammo < ammo_use)
                {
                        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),
+                               GetAmmoPicture(wep.ammo_type),
                                actor.netname,
-                               actor.(wep.ammo_field)
+                               ammo
                                             ));
                }
+               SetResourceAmount(actor, wep.ammo_type, ammo - ammo_use);
        }
 }
 
@@ -702,16 +706,17 @@ void W_ReloadedAndReady(Weapon thiswep, entity actor, .entity weaponentity, int
        w_ent.clip_load = w_ent.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 (!w_ent.reload_ammo_min || (actor.items & IT_UNLIMITED_WEAPON_AMMO) || wpn.ammo_field == ammo_none)
+       if (!w_ent.reload_ammo_min || (actor.items & IT_UNLIMITED_WEAPON_AMMO) || wpn.ammo_type == RESOURCE_NONE)
        {
                w_ent.clip_load = w_ent.reload_ammo_amount;
        }
        else
        {
                // make sure we don't add more ammo than we have
-               float load = min(w_ent.reload_ammo_amount - w_ent.clip_load, actor.(wpn.ammo_field));
+               float ammo = GetResourceAmount(actor, wpn.ammo_type);
+               float load = min(w_ent.reload_ammo_amount - w_ent.clip_load, ammo);
                w_ent.clip_load += load;
-               actor.(wpn.ammo_field) -= load;
+               SetResourceAmount(actor, wpn.ammo_type, ammo - load);
        }
        w_ent.(weapon_load[w_ent.m_weapon.m_id]) = w_ent.clip_load;
 
@@ -726,7 +731,7 @@ void W_ReloadedAndReady(Weapon thiswep, entity actor, .entity weaponentity, int
 
 void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sent_sound)
 {
-    TC(Sound, sent_sound);
+       TC(Sound, sent_sound);
        // set global values to work with
        entity this = actor.(weaponentity);
        Weapon e = this.m_weapon;
@@ -736,8 +741,7 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen
        this.reload_ammo_min = sent_ammo_min;
        this.reload_ammo_amount = e.reloading_ammo;
        this.reload_time = e.reloading_time;
-       if (actor.reload_sound) strunzone(actor.reload_sound);
-       actor.reload_sound = strzone(Sound_fixpath(sent_sound));
+       strcpy(actor.reload_sound, Sound_fixpath(sent_sound));
 
        // don't reload weapons that don't have the RELOADABLE flag
        if (!(e.spawnflags & WEP_FLAG_RELOADABLE))
@@ -754,9 +758,9 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen
        if (this.clip_load >= this.reload_ammo_amount) return;
 
        // no ammo, so nothing to load
-       if (e.ammo_field != ammo_none)
+       if (e.ammo_type != RESOURCE_NONE)
        {
-               if (!actor.(e.ammo_field) && this.reload_ammo_min)
+               if (!GetResourceAmount(actor, e.ammo_type) && this.reload_ammo_min)
                {
                        if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
                        {