1 #include "okmachinegun.qh"
5 spawnfunc(weapon_okmachinegun)
7 if(autocvar_sv_q3acompat_machineshotgunswap)
8 if(this.classname != "droppedweapon")
10 weapon_defaultspawnfunc(this, WEP_SHOCKWAVE);
13 weapon_defaultspawnfunc(this, WEP_OVERKILL_MACHINEGUN);
16 void W_OverkillMachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity, int fire)
18 float okmachinegun_spread;
22 w_ready(thiswep, actor, weaponentity, fire);
26 if(!thiswep.wr_checkammo1(thiswep, actor, weaponentity))
27 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
29 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
30 w_ready(thiswep, actor, weaponentity, fire);
34 W_DecreaseAmmo(WEP_OVERKILL_MACHINEGUN, actor, WEP_CVAR_PRI(okmachinegun, ammo), weaponentity);
36 W_SetupShot(actor, weaponentity, true, 0, SND_UZI_FIRE, CH_WEAPON_A, WEP_CVAR_PRI(okmachinegun, damage));
37 if(!autocvar_g_norecoil)
39 actor.punchangle_x = random() - 0.5;
40 actor.punchangle_y = random() - 0.5;
43 okmachinegun_spread = bound(WEP_CVAR_PRI(okmachinegun, spread_min), WEP_CVAR_PRI(okmachinegun, spread_min) + (WEP_CVAR_PRI(okmachinegun, spread_add) * actor.(weaponentity).misc_bulletcounter), WEP_CVAR_PRI(okmachinegun, spread_max));
44 fireBullet(actor, weaponentity, w_shotorg, w_shotdir, okmachinegun_spread, WEP_CVAR_PRI(okmachinegun, solidpenetration), WEP_CVAR_PRI(okmachinegun, damage), WEP_CVAR_PRI(okmachinegun, force), WEP_OVERKILL_MACHINEGUN.m_id, 0);
46 actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
48 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
50 W_MachineGun_MuzzleFlash(actor, weaponentity);
51 W_AttachToShotorg(actor, weaponentity, actor.(weaponentity).muzzle_flash, '5 0 0');
53 if(autocvar_g_casings >= 2) // casing code
55 makevectors(actor.v_angle); // for some reason, this is lost
56 SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3, actor, weaponentity);
59 int slot = weaponslot(weaponentity);
60 ATTACK_FINISHED(actor, slot) = time + WEP_CVAR_PRI(okmachinegun, refire) * W_WeaponRateFactor(actor);
61 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(okmachinegun, refire), W_OverkillMachineGun_Attack_Auto);
64 METHOD(OverkillMachineGun, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
66 if(vdist(actor.origin - actor.enemy.origin, <, 3000 - bound(0, skill, 10) * 200))
67 PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
69 PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
72 METHOD(OverkillMachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
74 if ((WEP_CVAR_SEC(okmachinegun, refire_type) == 1) && (fire & 2) && (time >= actor.jump_interval))
76 // Secondary uses it's own refire timer if refire_type is 1.
77 actor.jump_interval = time + WEP_CVAR_SEC(okmachinegun, refire) * W_WeaponRateFactor(actor);
78 // Ugly hack to reuse the fire mode of the blaster.
79 makevectors(actor.v_angle);
80 Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
81 actor.(weaponentity).m_weapon = WEP_BLASTER;
85 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
86 WEP_CVAR_SEC(okmachinegun, shotangle),
87 WEP_CVAR_SEC(okmachinegun, damage),
88 WEP_CVAR_SEC(okmachinegun, edgedamage),
89 WEP_CVAR_SEC(okmachinegun, radius),
90 WEP_CVAR_SEC(okmachinegun, force),
91 WEP_CVAR_SEC(okmachinegun, speed),
92 WEP_CVAR_SEC(okmachinegun, spread),
93 WEP_CVAR_SEC(okmachinegun, delay),
94 WEP_CVAR_SEC(okmachinegun, lifetime)
96 actor.(weaponentity).m_weapon = oldwep;
97 if ((actor.(weaponentity).wframe == WFRAME_IDLE) ||
98 (actor.(weaponentity).wframe == WFRAME_FIRE2))
100 // Set secondary fire animation.
102 actor.(weaponentity).wframe = WFRAME_FIRE2;
103 a = actor.(weaponentity).anim_fire2;
104 a.z *= g_weaponratefactor;
105 FOREACH_CLIENT(true, LAMBDA(
106 if (it == actor || (IS_SPEC(it) && it.enemy == actor))
108 wframe_send(it, actor.(weaponentity), a, true);
111 animdecide_setaction(actor, ANIMACTION_SHOOT, true);
114 if (WEP_CVAR(okmachinegun, reload_ammo) && actor.(weaponentity).clip_load < WEP_CVAR_PRI(okmachinegun, ammo))
117 thiswep.wr_reload(thiswep, actor, weaponentity);
120 if (fire & 1) // Primary attack
122 if (!weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
126 actor.(weaponentity).misc_bulletcounter = 0;
127 W_OverkillMachineGun_Attack_Auto(thiswep, actor, weaponentity, fire);
130 if ((fire & 2) && (WEP_CVAR_SEC(okmachinegun, refire_type) == 0)) // Secondary attack
132 if (!weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(okmachinegun, refire)))
136 // Ugly hack to reuse the fire mode of the blaster.
137 makevectors(actor.v_angle);
138 Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
139 actor.(weaponentity).m_weapon = WEP_BLASTER;
143 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
144 WEP_CVAR_SEC(okmachinegun, shotangle),
145 WEP_CVAR_SEC(okmachinegun, damage),
146 WEP_CVAR_SEC(okmachinegun, edgedamage),
147 WEP_CVAR_SEC(okmachinegun, radius),
148 WEP_CVAR_SEC(okmachinegun, force),
149 WEP_CVAR_SEC(okmachinegun, speed),
150 WEP_CVAR_SEC(okmachinegun, spread),
151 WEP_CVAR_SEC(okmachinegun, delay),
152 WEP_CVAR_SEC(okmachinegun, lifetime)
154 actor.(weaponentity).m_weapon = oldwep;
155 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(okmachinegun, animtime), w_ready);
159 METHOD(OverkillMachineGun, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
162 ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(okmachinegun, ammo);
163 if (WEP_CVAR(okmachinegun, reload_ammo))
165 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR_PRI(okmachinegun, ammo);
170 METHOD(OverkillMachineGun, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
172 return true; // Blaster secondary is unlimited.
175 METHOD(OverkillMachineGun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
177 W_Reload(actor, weaponentity, WEP_CVAR_PRI(okmachinegun, ammo), SND_RELOAD);
180 METHOD(OverkillMachineGun, wr_suicidemessage, Notification(entity thiswep))
182 return WEAPON_THINKING_WITH_PORTALS;
185 METHOD(OverkillMachineGun, wr_killmessage, Notification(entity thiswep))
187 if(w_deathtype & HITTYPE_SECONDARY)
188 return WEAPON_MACHINEGUN_MURDER_SNIPE;
190 return WEAPON_MACHINEGUN_MURDER_SPRAY;
196 METHOD(OverkillMachineGun, wr_impacteffect, void(entity thiswep, entity actor))
199 org2 = w_org + w_backoff * 2;
200 pointparticles(EFFECT_MACHINEGUN_IMPACT, org2, w_backoff * 1000, 1);
202 sound(actor, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTN_NORM);