From 935e92488028bdbb96c7fa20c5a44c1248e12a86 Mon Sep 17 00:00:00 2001 From: Lyberta Date: Sat, 11 Mar 2017 16:40:09 +0300 Subject: [PATCH] Reduce code duplication in shotgun. --- .../mutators/mutator/overkill/okshotgun.qc | 35 +++------------ qcsrc/common/weapons/weapon/shotgun.qc | 45 ++++++++++++++----- 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/qcsrc/common/mutators/mutator/overkill/okshotgun.qc b/qcsrc/common/mutators/mutator/overkill/okshotgun.qc index b232c56ab..1e34e41a5 100644 --- a/qcsrc/common/mutators/mutator/overkill/okshotgun.qc +++ b/qcsrc/common/mutators/mutator/overkill/okshotgun.qc @@ -3,33 +3,6 @@ #ifdef SVQC spawnfunc(weapon_okshotgun) { weapon_defaultspawnfunc(this, WEP_OVERKILL_SHOTGUN); } -void W_OverkillShotgun_Attack(Weapon thiswep, entity actor, .entity weaponentity, float isprimary) -{ - W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(okshotgun, ammo), weaponentity); - - W_SetupShot(actor, weaponentity, true, 5, SND_SHOTGUN_FIRE, ((isprimary) ? CH_WEAPON_A : CH_WEAPON_SINGLE), WEP_CVAR_PRI(okshotgun, damage) * WEP_CVAR_PRI(okshotgun, bullets)); - for(int sc = 0;sc < WEP_CVAR_PRI(okshotgun, bullets);sc = sc + 1) - fireBullet(actor, weaponentity, w_shotorg, w_shotdir, WEP_CVAR_PRI(okshotgun, spread), WEP_CVAR_PRI(okshotgun, solidpenetration), WEP_CVAR_PRI(okshotgun, damage), WEP_CVAR_PRI(okshotgun, force), WEP_OVERKILL_SHOTGUN.m_id, 0); - - Send_Effect(EFFECT_SHOTGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, WEP_CVAR_PRI(okshotgun, ammo)); - - // casing code - if(autocvar_g_casings >= 1) - { - makevectors(actor.v_angle); // for some reason, this is lost - //for(int sc = 0;sc < WEP_CVAR_PRI(shotgun, ammo);sc = sc + 1) - SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 30) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 1, actor, weaponentity); - } - - // muzzle flash for 1st person view - entity flash = spawn(); - setmodel(flash, MDL_SHOTGUN_MUZZLEFLASH); // precision set below - setthink(flash, SUB_Remove); - flash.nextthink = time + 0.06; - flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION; - W_AttachToShotorg(actor, weaponentity, flash, '5 0 0'); -} - .float okshotgun_primarytime; METHOD(OverkillShotgun, wr_aim, void(entity thiswep, entity actor, .entity weaponentity)) @@ -57,7 +30,13 @@ METHOD(OverkillShotgun, wr_think, void(entity thiswep, entity actor, .entity wea { if (weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(okshotgun, animtime))) { - W_OverkillShotgun_Attack(thiswep, actor, weaponentity, true); + W_Shotgun_Attack(thiswep, actor, weaponentity, true, + WEP_CVAR_PRI(okshotgun, ammo), + WEP_CVAR_PRI(okshotgun, damage), + WEP_CVAR_PRI(okshotgun, bullets), + WEP_CVAR_PRI(okshotgun, spread), + WEP_CVAR_PRI(okshotgun, solidpenetration), + WEP_CVAR_PRI(okshotgun, force)); actor.(weaponentity).okshotgun_primarytime = time + WEP_CVAR_PRI(okshotgun, refire) * W_WeaponRateFactor(actor); weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(okshotgun, animtime), w_ready); } diff --git a/qcsrc/common/weapons/weapon/shotgun.qc b/qcsrc/common/weapons/weapon/shotgun.qc index e597665c5..b873a9aeb 100644 --- a/qcsrc/common/weapons/weapon/shotgun.qc +++ b/qcsrc/common/weapons/weapon/shotgun.qc @@ -59,15 +59,15 @@ REGISTER_WEAPON(SHOTGUN, shotgun, NEW(Shotgun)); #ifdef SVQC spawnfunc(weapon_shotgun) { weapon_defaultspawnfunc(this, WEP_SHOTGUN); } -void W_Shotgun_Attack(Weapon thiswep, entity actor, .entity weaponentity, float isprimary) +void W_Shotgun_Attack(Weapon thiswep, entity actor, .entity weaponentity, float isprimary, float ammocount, float damage, float bullets, float spread, float solidpenetration, float force) { - W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(shotgun, ammo), weaponentity); + W_DecreaseAmmo(thiswep, actor, ammocount, weaponentity); - W_SetupShot(actor, weaponentity, true, 5, SND_SHOTGUN_FIRE, ((isprimary) ? CH_WEAPON_A : CH_WEAPON_SINGLE), WEP_CVAR_PRI(shotgun, damage) * WEP_CVAR_PRI(shotgun, bullets)); - for(int sc = 0;sc < WEP_CVAR_PRI(shotgun, bullets);sc = sc + 1) - fireBullet(actor, weaponentity, w_shotorg, w_shotdir, WEP_CVAR_PRI(shotgun, spread), WEP_CVAR_PRI(shotgun, solidpenetration), WEP_CVAR_PRI(shotgun, damage), WEP_CVAR_PRI(shotgun, force), WEP_SHOTGUN.m_id, 0); + W_SetupShot(actor, weaponentity, true, 5, SND_SHOTGUN_FIRE, ((isprimary) ? CH_WEAPON_A : CH_WEAPON_SINGLE), damage * bullets); + for(int sc = 0;sc < bullets;sc = sc + 1) + fireBullet(actor, weaponentity, w_shotorg, w_shotdir, spread, solidpenetration, damage, force, WEP_SHOTGUN.m_id, 0); - Send_Effect(EFFECT_SHOTGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, WEP_CVAR_PRI(shotgun, ammo)); + Send_Effect(EFFECT_SHOTGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, ammocount); // casing code if(autocvar_g_casings >= 1) @@ -208,7 +208,13 @@ void W_Shotgun_Attack3_Frame2(Weapon thiswep, entity actor, .entity weaponentity } sound(actor, CH_WEAPON_SINGLE, SND_Null, VOL_BASE, ATTN_NORM); // kill previous sound - W_Shotgun_Attack(WEP_SHOTGUN, actor, weaponentity, true); // actually is secondary, but we trick the last shot into playing full reload sound + W_Shotgun_Attack(WEP_SHOTGUN, actor, weaponentity, true, + WEP_CVAR_PRI(shotgun, ammo), + WEP_CVAR_PRI(shotgun, damage), + WEP_CVAR_PRI(shotgun, bullets), + WEP_CVAR_PRI(shotgun, spread), + WEP_CVAR_PRI(shotgun, solidpenetration), + WEP_CVAR_PRI(shotgun, force)); // actually is secondary, but we trick the last shot into playing full reload sound weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(shotgun, alt_animtime), w_ready); } void W_Shotgun_Attack3_Frame1(Weapon thiswep, entity actor, .entity weaponentity, int fire) @@ -221,7 +227,13 @@ void W_Shotgun_Attack3_Frame1(Weapon thiswep, entity actor, .entity weaponentity return; } - W_Shotgun_Attack(WEP_SHOTGUN, actor, weaponentity, false); + W_Shotgun_Attack(WEP_SHOTGUN, actor, weaponentity, false, + WEP_CVAR_PRI(shotgun, ammo), + WEP_CVAR_PRI(shotgun, damage), + WEP_CVAR_PRI(shotgun, bullets), + WEP_CVAR_PRI(shotgun, spread), + WEP_CVAR_PRI(shotgun, solidpenetration), + WEP_CVAR_PRI(shotgun, force)); weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(shotgun, alt_animtime), W_Shotgun_Attack3_Frame2); } @@ -234,6 +246,7 @@ METHOD(Shotgun, wr_aim, void(entity thiswep, entity actor, .entity weaponentity) else PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false); } + METHOD(Shotgun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { if(WEP_CVAR(shotgun, reload_ammo) && actor.(weaponentity).clip_load < WEP_CVAR_PRI(shotgun, ammo)) // forced reload @@ -251,7 +264,13 @@ METHOD(Shotgun, wr_think, void(entity thiswep, entity actor, .entity weaponentit { if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(shotgun, animtime))) { - W_Shotgun_Attack(thiswep, actor, weaponentity, true); + W_Shotgun_Attack(thiswep, actor, weaponentity, true, + WEP_CVAR_PRI(shotgun, ammo), + WEP_CVAR_PRI(shotgun, damage), + WEP_CVAR_PRI(shotgun, bullets), + WEP_CVAR_PRI(shotgun, spread), + WEP_CVAR_PRI(shotgun, solidpenetration), + WEP_CVAR_PRI(shotgun, force)); actor.(weaponentity).shotgun_primarytime = time + WEP_CVAR_PRI(shotgun, refire) * W_WeaponRateFactor(actor); weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(shotgun, animtime), w_ready); } @@ -263,7 +282,13 @@ METHOD(Shotgun, wr_think, void(entity thiswep, entity actor, .entity weaponentit { if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(shotgun, alt_animtime))) { - W_Shotgun_Attack(thiswep, actor, weaponentity, false); + W_Shotgun_Attack(thiswep, actor, weaponentity, false, + WEP_CVAR_PRI(shotgun, ammo), + WEP_CVAR_PRI(shotgun, damage), + WEP_CVAR_PRI(shotgun, bullets), + WEP_CVAR_PRI(shotgun, spread), + WEP_CVAR_PRI(shotgun, solidpenetration), + WEP_CVAR_PRI(shotgun, force)); actor.(weaponentity).shotgun_primarytime = time + WEP_CVAR_SEC(shotgun, alt_refire) * W_WeaponRateFactor(actor); weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(shotgun, alt_animtime), W_Shotgun_Attack3_Frame1); } -- 2.39.2