X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fcommon%2Fweapons%2Fweapon%2Fmachinegun.qc;h=94128ea44d17c52b0ef472a71c8d9bbef655cc94;hp=2d88a9deb29fc65189487f9006d34ee6fcba2751;hb=90d9f7c775306324957323d53d5a4ad995d999e3;hpb=af43b181a15f348a4de2045b716ebc7765ce8f9f diff --git a/qcsrc/common/weapons/weapon/machinegun.qc b/qcsrc/common/weapons/weapon/machinegun.qc index 2d88a9deb..94128ea44 100644 --- a/qcsrc/common/weapons/weapon/machinegun.qc +++ b/qcsrc/common/weapons/weapon/machinegun.qc @@ -2,15 +2,6 @@ #ifdef SVQC -METHOD(MachineGun, m_spawnfunc_hookreplace, Weapon(MachineGun this, entity e)) -{ - if (autocvar_sv_q3acompat_machineshotgunswap && !Item_IsLoot(e)) - { - return WEP_SHOCKWAVE; - } - return this; -} - void W_MachineGun_MuzzleFlash_Think(entity this) { this.frame += 2; @@ -64,7 +55,7 @@ void W_MachineGun_Attack(Weapon thiswep, int deathtype, entity actor, .entity we else fireBullet(actor, weaponentity, w_shotorg, w_shotdir, WEP_CVAR(machinegun, sustained_spread), WEP_CVAR(machinegun, solidpenetration), WEP_CVAR(machinegun, sustained_damage), WEP_CVAR(machinegun, sustained_force), deathtype, EFFECT_BULLET); - Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1); + W_MuzzleFlash(actor, weaponentity, EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000); W_MachineGun_MuzzleFlash(actor, weaponentity); W_AttachToShotorg(actor, weaponentity, actor.(weaponentity).muzzle_flash, '5 0 0'); @@ -93,7 +84,7 @@ void W_MachineGun_Attack_Frame(Weapon thiswep, entity actor, .entity weaponentit if(PHYS_INPUT_BUTTON_ATCK(actor)) { if(!thiswep.wr_checkammo2(thiswep, actor, weaponentity)) - if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO)) + if(!(actor.items & IT_UNLIMITED_AMMO)) { W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity); w_ready(thiswep, actor, weaponentity, fire); @@ -119,7 +110,7 @@ void W_MachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity } if(!thiswep.wr_checkammo1(thiswep, actor, weaponentity)) - if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO)) + if(!(actor.items & IT_UNLIMITED_AMMO)) { W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity); w_ready(thiswep, actor, weaponentity, fire); @@ -140,7 +131,7 @@ void W_MachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1; - Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1); + W_MuzzleFlash(actor, weaponentity, EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000); W_MachineGun_MuzzleFlash(actor, weaponentity); W_AttachToShotorg(actor, weaponentity, actor.(weaponentity).muzzle_flash, '5 0 0'); @@ -166,7 +157,7 @@ void W_MachineGun_Attack_Burst(Weapon thiswep, entity actor, .entity weaponentit fireBullet(actor, weaponentity, w_shotorg, w_shotdir, WEP_CVAR(machinegun, burst_spread), WEP_CVAR(machinegun, solidpenetration), WEP_CVAR(machinegun, sustained_damage), WEP_CVAR(machinegun, sustained_force), thiswep.m_id, EFFECT_BULLET); - Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1); + W_MuzzleFlash(actor, weaponentity, EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000); W_MachineGun_MuzzleFlash(actor, weaponentity); W_AttachToShotorg(actor, weaponentity, actor.(weaponentity).muzzle_flash, '5 0 0'); @@ -199,10 +190,14 @@ METHOD(MachineGun, wr_aim, void(entity thiswep, entity actor, .entity weaponenti } METHOD(MachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { - if(WEP_CVAR(machinegun, reload_ammo) && actor.(weaponentity).clip_load < min(max(WEP_CVAR(machinegun, sustained_ammo), WEP_CVAR(machinegun, first_ammo)), WEP_CVAR(machinegun, burst_ammo))) { // forced reload + // forced reload - wait until the bulletcounter is 0 so a burst loop can finish + if(WEP_CVAR(machinegun, reload_ammo) + && actor.(weaponentity).clip_load < min(max(WEP_CVAR(machinegun, sustained_ammo), WEP_CVAR(machinegun, first_ammo)), WEP_CVAR(machinegun, burst_ammo)) + && actor.(weaponentity).misc_bulletcounter >= 0) + { thiswep.wr_reload(thiswep, actor, weaponentity); - } else - if(WEP_CVAR(machinegun, mode) == 1) + } + else if(WEP_CVAR(machinegun, mode) == 1) { if(fire & 1) if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0)) @@ -211,20 +206,39 @@ METHOD(MachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponen W_MachineGun_Attack_Auto(thiswep, actor, weaponentity, fire); } + // You can "shoot" more rounds than what's "used", and vice versa. if(fire & 2) if(weapon_prepareattack(thiswep, actor, weaponentity, true, 0)) { if(!thiswep.wr_checkammo2(thiswep, actor, weaponentity)) - if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO)) + if(!(actor.items & IT_UNLIMITED_AMMO)) { W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity); w_ready(thiswep, actor, weaponentity, fire); return; } - W_DecreaseAmmo(thiswep, actor, WEP_CVAR(machinegun, burst_ammo), weaponentity); + float ammo_available; + if (WEP_CVAR(machinegun, reload_ammo) > 0) + { + ammo_available = actor.(weaponentity).clip_load; + } + else + { + ammo_available = GetResource(actor, thiswep.ammo_type); + } - actor.(weaponentity).misc_bulletcounter = WEP_CVAR(machinegun, burst) * -1; + // We don't want to shoot 3 rounds if there's 2 left in the mag, so we'll use a fraction. + // Also keep the fraction <= 1 otherwise we'd mag dump in one burst. + float burst_fraction = min(1, ammo_available / WEP_CVAR(machinegun, burst_ammo)); + int to_shoot = floor(WEP_CVAR(machinegun, burst) * burst_fraction); + + // We also don't want to use 3 rounds if there's only 2 left. + int to_use = min(WEP_CVAR(machinegun, burst_ammo), ammo_available); + W_DecreaseAmmo(thiswep, actor, to_use, weaponentity); + + // Bursting counts up to 0 from a negative. + actor.(weaponentity).misc_bulletcounter = -to_shoot; W_MachineGun_Attack_Burst(thiswep, actor, weaponentity, fire); } } @@ -268,15 +282,16 @@ METHOD(MachineGun, wr_checkammo1, bool(entity thiswep, entity actor, .entity wea METHOD(MachineGun, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity)) { float ammo_amount; + float burst_ammo_per_shot = WEP_CVAR(machinegun, burst_ammo) / WEP_CVAR(machinegun, burst); if(WEP_CVAR(machinegun, mode) == 1) - ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR(machinegun, burst_ammo); + ammo_amount = GetResource(actor, thiswep.ammo_type) >= burst_ammo_per_shot; else ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR(machinegun, first_ammo); if(WEP_CVAR(machinegun, reload_ammo)) { if(WEP_CVAR(machinegun, mode) == 1) - ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR(machinegun, burst_ammo); + ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= burst_ammo_per_shot; else ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR(machinegun, first_ammo); } @@ -284,6 +299,8 @@ METHOD(MachineGun, wr_checkammo2, bool(entity thiswep, entity actor, .entity wea } METHOD(MachineGun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity)) { + if(actor.(weaponentity).misc_bulletcounter < 0) + return; W_Reload(actor, weaponentity, min(max(WEP_CVAR(machinegun, sustained_ammo), WEP_CVAR(machinegun, first_ammo)), WEP_CVAR(machinegun, burst_ammo)), SND_RELOAD); } METHOD(MachineGun, wr_suicidemessage, Notification(entity thiswep))