]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/weapon/rifle.qc
Weapons: pass weaponentity field instead of slot
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / rifle.qc
index 63d77d80fb4404d54d4cfc13c193be3f91c1c09c..5aed6a7d473fff31f1a2208c7061a78f66839365 100644 (file)
@@ -90,32 +90,33 @@ void W_Rifle_Attack2(void)
 .float rifle_bullethail_frame;
 .float rifle_bullethail_animtime;
 .float rifle_bullethail_refire;
-void W_Rifle_BulletHail_Continue(Weapon thiswep, entity actor, int slot, int fire)
+void W_Rifle_BulletHail_Continue(Weapon thiswep, entity actor, .entity weaponentity, int fire)
 {
        float r, sw, af;
 
        sw = actor.switchweapon; // make it not detect weapon changes as reason to abort firing
+       int slot = weaponslot(weaponentity);
        af = ATTACK_FINISHED(actor, slot);
        actor.switchweapon = actor.weapon;
        ATTACK_FINISHED(actor, slot) = time;
        LOG_INFO(ftos(actor.WEP_AMMO(RIFLE)), "\n");
-       r = weapon_prepareattack(thiswep, actor, slot, actor.rifle_bullethail_frame == WFRAME_FIRE2, actor.rifle_bullethail_refire);
+       r = weapon_prepareattack(thiswep, actor, weaponentity, actor.rifle_bullethail_frame == WFRAME_FIRE2, actor.rifle_bullethail_refire);
        if(actor.switchweapon == actor.weapon)
                actor.switchweapon = sw;
        if(r)
        {
                actor.rifle_bullethail_attackfunc();
-               weapon_thinkf(actor, slot, actor.rifle_bullethail_frame, actor.rifle_bullethail_animtime, W_Rifle_BulletHail_Continue);
+               weapon_thinkf(actor, weaponentity, actor.rifle_bullethail_frame, actor.rifle_bullethail_animtime, W_Rifle_BulletHail_Continue);
                LOG_INFO("thinkf set\n");
        }
        else
        {
                ATTACK_FINISHED(actor, slot) = af; // reset attack_finished if we didn't fire, so the last shot enforces the refire time
-               LOG_INFO("out of ammo... ", ftos(actor.weaponentity[slot].state), "\n");
+               LOG_INFO("out of ammo... ", ftos(actor.(weaponentity).state), "\n");
        }
 }
 
-void W_Rifle_BulletHail(int slot, float mode, void(void) AttackFunc, float fr, float animtime, float refire)
+void W_Rifle_BulletHail(.entity weaponentity, float mode, void(void) AttackFunc, float fr, float animtime, float refire)
 {SELFPARAM();
        // if we get here, we have at least one bullet to fire
        AttackFunc();
@@ -126,12 +127,12 @@ void W_Rifle_BulletHail(int slot, float mode, void(void) AttackFunc, float fr, f
                self.rifle_bullethail_frame = fr;
                self.rifle_bullethail_animtime = animtime;
                self.rifle_bullethail_refire = refire;
-               weapon_thinkf(self, slot, fr, animtime, W_Rifle_BulletHail_Continue);
+               weapon_thinkf(self, weaponentity, fr, animtime, W_Rifle_BulletHail_Continue);
        }
        else
        {
                // just one shot
-               weapon_thinkf(self, slot, fr, animtime, w_ready);
+               weapon_thinkf(self, weaponentity, fr, animtime, w_ready);
        }
 }
 
@@ -160,7 +161,7 @@ void W_Rifle_BulletHail(int slot, float mode, void(void) AttackFunc, float fr, f
                                }
                        }
                }
-               METHOD(Rifle, wr_think, void(entity thiswep, entity actor, int slot, int fire))
+               METHOD(Rifle, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
                {
                        if(autocvar_g_balance_rifle_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(rifle, ammo), WEP_CVAR_SEC(rifle, ammo))) { // forced reload
                                Weapon w = get_weaponinfo(actor.weapon);
@@ -169,11 +170,11 @@ void W_Rifle_BulletHail(int slot, float mode, void(void) AttackFunc, float fr, f
                        {
                                actor.rifle_accumulator = bound(time - WEP_CVAR(rifle, bursttime), actor.rifle_accumulator, time);
                                if(fire & 1)
-                               if(weapon_prepareattack_check(thiswep, actor, slot, false, WEP_CVAR_PRI(rifle, refire)))
+                               if(weapon_prepareattack_check(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(rifle, refire)))
                                if(time >= actor.rifle_accumulator + WEP_CVAR_PRI(rifle, burstcost))
                                {
-                                       weapon_prepareattack_do(actor, slot, false, WEP_CVAR_PRI(rifle, refire));
-                                       W_Rifle_BulletHail(slot, WEP_CVAR_PRI(rifle, bullethail), W_Rifle_Attack, WFRAME_FIRE1, WEP_CVAR_PRI(rifle, animtime), WEP_CVAR_PRI(rifle, refire));
+                                       weapon_prepareattack_do(actor, weaponentity, false, WEP_CVAR_PRI(rifle, refire));
+                                       W_Rifle_BulletHail(weaponentity, WEP_CVAR_PRI(rifle, bullethail), W_Rifle_Attack, WFRAME_FIRE1, WEP_CVAR_PRI(rifle, animtime), WEP_CVAR_PRI(rifle, refire));
                                        actor.rifle_accumulator += WEP_CVAR_PRI(rifle, burstcost);
                                }
                                if(fire & 2)
@@ -185,11 +186,11 @@ void W_Rifle_BulletHail(int slot, float mode, void(void) AttackFunc, float fr, f
                                                        w.wr_reload(w);
                                                } else
                                                {
-                                                       if(weapon_prepareattack_check(thiswep, actor, slot, true, WEP_CVAR_SEC(rifle, refire)))
+                                                       if(weapon_prepareattack_check(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(rifle, refire)))
                                                        if(time >= actor.rifle_accumulator + WEP_CVAR_SEC(rifle, burstcost))
                                                        {
-                                                               weapon_prepareattack_do(actor, slot, true, WEP_CVAR_SEC(rifle, refire));
-                                                               W_Rifle_BulletHail(slot, WEP_CVAR_SEC(rifle, bullethail), W_Rifle_Attack2, WFRAME_FIRE2, WEP_CVAR_SEC(rifle, animtime), WEP_CVAR_PRI(rifle, refire));
+                                                               weapon_prepareattack_do(actor, weaponentity, true, WEP_CVAR_SEC(rifle, refire));
+                                                               W_Rifle_BulletHail(weaponentity, WEP_CVAR_SEC(rifle, bullethail), W_Rifle_Attack2, WFRAME_FIRE2, WEP_CVAR_SEC(rifle, animtime), WEP_CVAR_PRI(rifle, refire));
                                                                actor.rifle_accumulator += WEP_CVAR_SEC(rifle, burstcost);
                                                        }
                                                }