]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/weapons/weaponsystem.qc
Merge branch 'master' into Mario/wepent_experimental
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / weaponsystem.qc
index 3b3e1b0e01892bed75eb766bff52783610ec16cd..6139f2879cbf8e04718e18f7fc7848710c654532 100644 (file)
@@ -8,12 +8,14 @@
 #include <common/t_items.qh>
 #include <common/animdecide.qh>
 #include <common/constants.qh>
+#include <common/net_linked.qh>
 #include <common/monsters/_mod.qh>
 #include <common/notifications/all.qh>
 #include <common/util.qh>
 #include <common/weapons/_all.qh>
 #include <common/state.qh>
 #include <lib/csqcmodel/sv_model.qh>
+#include <common/wepent.qh>
 
 .int state;
 
@@ -107,15 +109,13 @@ void CL_Weaponentity_Think(entity this)
                this.weaponchild.alpha = this.alpha;
                this.weaponchild.effects = this.effects;
        }
-
-       wepent_update(this);
 }
 
 void CL_ExteriorWeaponentity_Think(entity this)
 {
        this.nextthink = time;
        .entity weaponentity = this.weaponentity_fld;
-       entity wepent = this.owner.(weaponentity);
+       entity w_ent = this.owner.(weaponentity);
        if (this.owner.exteriorweaponentity != this)
        {
                delete(this);
@@ -126,15 +126,15 @@ void CL_ExteriorWeaponentity_Think(entity this)
                this.model = "";
                return;
        }
-       if (this.weaponname != wepent.weaponname || this.dmg != wepent.modelindex
-           || this.deadflag != wepent.deadflag)
+       if (this.weaponname != w_ent.weaponname || this.dmg != w_ent.modelindex
+           || this.deadflag != w_ent.deadflag)
        {
-               this.weaponname = wepent.weaponname;
-               this.dmg = wepent.modelindex;
-               this.deadflag = wepent.deadflag;
-               if (wepent.weaponname != "")
+               this.weaponname = w_ent.weaponname;
+               this.dmg = w_ent.modelindex;
+               this.deadflag = w_ent.deadflag;
+               if (w_ent.weaponname != "")
                {
-                       _setmodel(this, W_Model(strcat("v_", wepent.weaponname, ".md3")));
+                       _setmodel(this, W_Model(strcat("v_", w_ent.weaponname, ".md3")));
                        setsize(this, '0 0 0', '0 0 0');
                }
                else this.model = "";
@@ -226,7 +226,7 @@ bool weapon_prepareattack_checkammo(Weapon thiswep, entity actor, bool secondary
        // always keep the Mine Layer if we placed mines, so that we can detonate them
        if (thiswep == WEP_MINE_LAYER)
        {
-               IL_EACH(g_mines, it.owner == actor,
+               IL_EACH(g_mines, it.owner == actor && it.weaponentity_fld == weaponentity,
                {
                        return false;
                });
@@ -484,14 +484,13 @@ void W_WeaponFrame(Player actor, .entity weaponentity)
                                this.m_weapon = newwep;
                                this.weaponname = newwep.mdl;
                                this.bulletcounter = 0;
-                               actor.ammo_field = newwep.ammo_field;
-                               newwep.wr_setup(newwep, actor);
+                               newwep.wr_setup(newwep, actor, weaponentity);
                                this.state = WS_RAISE;
 
                                // set our clip load to the load of the weapon we switched to, if it's reloadable
                                if ((newwep.spawnflags & WEP_FLAG_RELOADABLE) && newwep.reloading_ammo)  // prevent accessing undefined cvars
                                {
-                                       this.clip_load = actor.(weapon_load[this.m_switchweapon.m_id]);
+                                       this.clip_load = this.(weapon_load[this.m_switchweapon.m_id]);
                                        this.clip_size = newwep.reloading_ammo;
                                }
                                else
@@ -635,7 +634,7 @@ 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)) return;
+       if (MUTATOR_CALLHOOK(W_DecreaseAmmo, actor, actor.(weaponentity))) return;
 
        if ((actor.items & IT_UNLIMITED_WEAPON_AMMO) && !wep.reloading_ammo) return;
 
@@ -643,7 +642,7 @@ void W_DecreaseAmmo(Weapon wep, entity actor, float ammo_use, .entity weaponenti
        if (wep.reloading_ammo)
        {
                actor.(weaponentity).clip_load -= ammo_use;
-               actor.(weapon_load[actor.(weaponentity).m_weapon.m_id]) = actor.(weaponentity).clip_load;
+               actor.(weaponentity).(weapon_load[actor.(weaponentity).m_weapon.m_id]) = actor.(weaponentity).clip_load;
        }
        else if (wep.ammo_field != ammo_none)
        {
@@ -673,21 +672,23 @@ void W_ReloadedAndReady(Weapon thiswep, entity actor, .entity weaponentity, int
 {
        // finish the reloading process, and do the ammo transfer
 
+       Weapon wpn = actor.(weaponentity).m_weapon;
+
        actor.(weaponentity).clip_load = actor.(weaponentity).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 (!actor.(weaponentity).reload_ammo_min || (actor.items & IT_UNLIMITED_WEAPON_AMMO) || actor.ammo_field == ammo_none)
+       if (!actor.(weaponentity).reload_ammo_min || (actor.items & IT_UNLIMITED_WEAPON_AMMO) || wpn.ammo_field == ammo_none)
        {
                actor.(weaponentity).clip_load = actor.(weaponentity).reload_ammo_amount;
        }
        else
        {
                // make sure we don't add more ammo than we have
-               float load = min(actor.(weaponentity).reload_ammo_amount - actor.(weaponentity).clip_load, actor.(actor.ammo_field));
+               float load = min(actor.(weaponentity).reload_ammo_amount - actor.(weaponentity).clip_load, actor.(wpn.ammo_field));
                actor.(weaponentity).clip_load += load;
-               actor.(actor.ammo_field) -= load;
+               actor.(wpn.ammo_field) -= load;
        }
-       actor.(weapon_load[actor.(weaponentity).m_weapon.m_id]) = actor.(weaponentity).clip_load;
+       actor.(weaponentity).(weapon_load[actor.(weaponentity).m_weapon.m_id]) = actor.(weaponentity).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,
@@ -695,7 +696,6 @@ void W_ReloadedAndReady(Weapon thiswep, entity actor, .entity weaponentity, int
 
        // ATTACK_FINISHED(actor, slot) -= actor.(weaponentity).reload_time - 1;
 
-       Weapon wpn = Weapons_from(actor.(weaponentity).m_weapon.m_id);
        w_ready(wpn, actor, weaponentity, PHYS_INPUT_BUTTON_ATCK(actor) | (PHYS_INPUT_BUTTON_ATCK2(actor) << 1));
 }
 
@@ -728,9 +728,9 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen
        if (actor.(weaponentity).clip_load >= actor.(weaponentity).reload_ammo_amount) return;
 
        // no ammo, so nothing to load
-       if (actor.ammo_field != ammo_none)
+       if (e.ammo_field != ammo_none)
        {
-               if (!actor.(actor.ammo_field) && actor.(weaponentity).reload_ammo_min)
+               if (!actor.(e.ammo_field) && actor.(weaponentity).reload_ammo_min)
                {
                        if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
                        {
@@ -741,8 +741,7 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen
                                        actor.reload_complain = time + 1;
                                }
                                // switch away if the amount of ammo is not enough to keep using this weapon
-                               Weapon w = actor.(weaponentity).m_weapon;
-                               if (!(w.wr_checkammo1(w, actor, weaponentity) + w.wr_checkammo2(w, actor, weaponentity)))
+                               if (!(e.wr_checkammo1(e, actor, weaponentity) + e.wr_checkammo2(e, actor, weaponentity)))
                                {
                                        actor.(weaponentity).clip_load = -1;  // reload later
                                        W_SwitchToOtherWeapon(actor, weaponentity);
@@ -771,11 +770,11 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen
 
        // ATTACK_FINISHED(actor, slot) = max(time, ATTACK_FINISHED(actor, slot)) + actor.(weaponentity).reload_time + 1;
 
-       weapon_thinkf(actor, weaponentity, WFRAME_RELOAD, actor.(weaponentity).reload_time, W_ReloadedAndReady);
+       weapon_thinkf(actor, weaponentity, WFRAME_RELOAD, this.reload_time, W_ReloadedAndReady);
 
        if (this.clip_load < 0) this.clip_load = 0;
        this.old_clip_load = this.clip_load;
-       this.clip_load = actor.(weapon_load[actor.(weaponentity).m_weapon.m_id]) = -1;
+       this.clip_load = this.(weapon_load[this.m_weapon.m_id]) = -1;
 }
 
 void W_DropEvent(.void(Weapon, entity actor, .entity) event, entity player, float weapon_type, entity weapon_item, .entity weaponentity)