]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/weapons/weaponsystem.qc
Add weaponentity parameter to ammo checking
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / weaponsystem.qc
index 3b8047efa19184abedfa0da26394ec0fdb0797f9..a37462eae8ed1d40de3365e2785680422d882625 100644 (file)
@@ -60,7 +60,6 @@ vector CL_Weapon_GetShotOrg(int wpn)
        return ret;
 }
 
-..entity weaponentity_fld;
 .float m_alpha;
 .string w_weaponname;
 .int w_dmg;
@@ -159,7 +158,7 @@ void CL_ExteriorWeaponentity_Think(entity this)
        else this.alpha = 1;
 
     Weapon wep = this.owner.(weaponentity).m_weapon;
-       if (wep) this.glowmod = weaponentity_glowmod(wep, this.owner, this.owner.clientcolors);
+       if (wep) this.glowmod = weaponentity_glowmod(wep, this.owner, this.owner.clientcolors, this.owner.(weaponentity));
        this.colormap = this.owner.colormap;
 
        CSQCMODEL_AUTOUPDATE(this);
@@ -221,8 +220,8 @@ bool weapon_prepareattack_checkammo(Weapon thiswep, entity actor, bool secondary
 {
        if ((actor.items & IT_UNLIMITED_WEAPON_AMMO)) return true;
        bool ammo = false;
-       if (secondary) ammo = thiswep.wr_checkammo2(thiswep, actor);
-       else ammo = thiswep.wr_checkammo1(thiswep, actor);
+       if (secondary) ammo = thiswep.wr_checkammo2(thiswep, actor, weaponentity);
+       else ammo = thiswep.wr_checkammo1(thiswep, actor, weaponentity);
        if (ammo) return true;
        // always keep the Mine Layer if we placed mines, so that we can detonate them
        if (thiswep == WEP_MINE_LAYER)
@@ -244,8 +243,8 @@ bool weapon_prepareattack_checkammo(Weapon thiswep, entity actor, bool secondary
 
        // check if the other firing mode has enough ammo
        bool ammo_other = false;
-       if (secondary) ammo_other = thiswep.wr_checkammo1(thiswep, actor);
-       else ammo_other = thiswep.wr_checkammo2(thiswep, actor);
+       if (secondary) ammo_other = thiswep.wr_checkammo1(thiswep, actor, weaponentity);
+       else ammo_other = thiswep.wr_checkammo2(thiswep, actor, weaponentity);
        if (ammo_other)
        {
                if (time - actor.prevwarntime > 1)
@@ -290,7 +289,7 @@ bool weapon_prepareattack_check(Weapon thiswep, entity actor, .entity weaponenti
        {
                int slot = weaponslot(weaponentity);
                // don't fire if previous attack is not finished
-               if (ATTACK_FINISHED(actor, slot) > time + actor.weapon_frametime * 0.5) return false;
+               if (ATTACK_FINISHED(actor, slot) > time + actor.(weaponentity).weapon_frametime * 0.5) return false;
                entity this = actor.(weaponentity);
                // don't fire while changing weapon
                if (this.state != WS_READY) return false;
@@ -310,14 +309,14 @@ void weapon_prepareattack_do(entity actor, .entity weaponentity, bool secondary,
        if (attacktime >= 0)
        {
                int slot = weaponslot(weaponentity);
-               if (ATTACK_FINISHED(actor, slot) < time - actor.weapon_frametime * 1.5)
+               if (ATTACK_FINISHED(actor, slot) < time - this.weapon_frametime * 1.5)
                {
                        ATTACK_FINISHED(actor, slot) = time;
                        // dprint("resetting attack finished to ", ftos(time), "\n");
                }
                ATTACK_FINISHED(actor, slot) = ATTACK_FINISHED(actor, slot) + attacktime * W_WeaponRateFactor(actor);
        }
-       actor.bulletcounter += 1;
+       this.bulletcounter += 1;
        // dprint("attack finished ", ftos(ATTACK_FINISHED(actor, slot)), "\n");
 }
 
@@ -381,8 +380,8 @@ void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void(
                this.weapon_nextthink = time;
                // dprint("started firing at ", ftos(time), "\n");
        }
-       if (this.weapon_nextthink < time - actor.weapon_frametime * 1.5
-           || this.weapon_nextthink > time + actor.weapon_frametime * 1.5)
+       if (this.weapon_nextthink < time - this.weapon_frametime * 1.5
+           || this.weapon_nextthink > time + this.weapon_frametime * 1.5)
        {
                this.weapon_nextthink = time;
                // dprint("reset weapon animation timer at ", ftos(time), "\n");
@@ -401,8 +400,8 @@ void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void(
 
        if ((fr == WFRAME_FIRE1 || fr == WFRAME_FIRE2) && t)
        {
-               bool primary_melee = boolean(fr == WFRAME_FIRE1 && (actor.(weaponentity).m_weapon.spawnflags & WEP_TYPE_MELEE_PRI));
-               bool secondary_melee = boolean(fr == WFRAME_FIRE2 && (actor.(weaponentity).m_weapon.spawnflags & WEP_TYPE_MELEE_SEC));
+               bool primary_melee = boolean(fr == WFRAME_FIRE1 && (this.m_weapon.spawnflags & WEP_TYPE_MELEE_PRI));
+               bool secondary_melee = boolean(fr == WFRAME_FIRE2 && (this.m_weapon.spawnflags & WEP_TYPE_MELEE_SEC));
                int act = (primary_melee || secondary_melee)
                        ? ANIMACTION_MELEE
                        : ANIMACTION_SHOOT
@@ -434,14 +433,14 @@ void W_WeaponFrame(Player actor, .entity weaponentity)
     TC(Player, actor);
     TC(PlayerState, PS(actor));
        entity this = actor.(weaponentity);
-       if (frametime) actor.weapon_frametime = frametime;
+       if (frametime) this.weapon_frametime = frametime;
 
        if (!this || actor.health < 1) return;  // Dead player can't use weapons and injure impulse commands
 
 
        if (forbidWeaponUse(actor))
        {
-               if (actor.(weaponentity).state != WS_CLEAR)
+               if (this.state != WS_CLEAR)
                {
                        Weapon wpn = this.m_weapon;
                        w_ready(wpn, actor, weaponentity, PHYS_INPUT_BUTTON_ATCK(actor) | (PHYS_INPUT_BUTTON_ATCK2(actor) << 1));
@@ -484,7 +483,7 @@ void W_WeaponFrame(Player actor, .entity weaponentity)
                                // the two weapon entities will notice this has changed and update their models
                                this.m_weapon = newwep;
                                this.weaponname = newwep.mdl;
-                               actor.bulletcounter = 0;
+                               this.bulletcounter = 0;
                                actor.ammo_field = newwep.ammo_field;
                                newwep.wr_setup(newwep, actor);
                                this.state = WS_RAISE;
@@ -516,7 +515,7 @@ void W_WeaponFrame(Player actor, .entity weaponentity)
                                entity oldwep = this.m_weapon;
 
                                // set up weapon switch think in the future, and start drop anim
-                               if (INDEPENDENT_ATTACK_FINISHED || ATTACK_FINISHED(actor, weaponslot(weaponentity)) <= time + actor.weapon_frametime * 0.5)
+                               if (INDEPENDENT_ATTACK_FINISHED || ATTACK_FINISHED(actor, weaponslot(weaponentity)) <= time + this.weapon_frametime * 0.5)
                                {
                                        sound(actor, CH_WEAPON_SINGLE, SND_WEAPON_SWITCH, VOL_BASE, ATTN_NORM);
                                        this.state = WS_DROP;
@@ -585,7 +584,7 @@ void W_WeaponFrame(Player actor, .entity weaponentity)
                        }
                }
 
-               if (time + actor.weapon_frametime * 0.5 >= this.weapon_nextthink)
+               if (time + this.weapon_frametime * 0.5 >= this.weapon_nextthink)
                {
                        if (this.weapon_think)
                        {
@@ -743,7 +742,7 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen
                                }
                                // 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) + w.wr_checkammo2(w, actor)))
+                               if (!(w.wr_checkammo1(w, actor, weaponentity) + w.wr_checkammo2(w, actor, weaponentity)))
                                {
                                        actor.clip_load = -1;  // reload later
                                        W_SwitchToOtherWeapon(actor, weaponentity);
@@ -779,9 +778,9 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen
        actor.clip_load = actor.(weapon_load[actor.(weaponentity).m_weapon.m_id]) = -1;
 }
 
-void W_DropEvent(.void(Weapon, entity actor) event, entity player, float weapon_type, entity weapon_item)
+void W_DropEvent(.void(Weapon, entity actor, .entity) event, entity player, float weapon_type, entity weapon_item, .entity weaponentity)
 {
        Weapon w = Weapons_from(weapon_type);
        weapon_dropevent_item = weapon_item;
-       w.event(w, player);
+       w.event(w, player, weaponentity);
 }