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_MuzzleFlash_Think(entity this)
21 this.nextthink = time + 0.05;
25 setthink(this, SUB_Remove);
26 this.nextthink = time;
27 this.realowner.muzzle_flash = NULL;
33 void W_OverkillMachineGun_MuzzleFlash(entity actor, .entity weaponentity)
35 entity wepent = actor.(weaponentity);
37 if(wepent.muzzle_flash == NULL)
38 wepent.muzzle_flash = spawn();
40 // muzzle flash for 1st person view
41 setmodel(wepent.muzzle_flash, MDL_MACHINEGUN_MUZZLEFLASH); // precision set below
43 wepent.muzzle_flash.scale = 0.75;
44 setthink(wepent.muzzle_flash, W_OverkillMachineGun_MuzzleFlash_Think);
45 wepent.muzzle_flash.nextthink = time + 0.02;
46 wepent.muzzle_flash.frame = 2;
47 wepent.muzzle_flash.alpha = 0.75;
48 wepent.muzzle_flash.angles_z = random() * 180;
49 wepent.muzzle_flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
50 wepent.muzzle_flash.owner = wepent.muzzle_flash.realowner = wepent;
53 void W_OverkillMachineGun_Attack(Weapon thiswep, int deathtype, entity actor, .entity weaponentity)
55 W_SetupShot(actor, weaponentity, true, 0, SND_UZI_FIRE, CH_WEAPON_A, ((actor.(weaponentity).misc_bulletcounter == 1) ? WEP_CVAR(okmachinegun, first_damage) : WEP_CVAR(okmachinegun, sustained_damage)));
56 if(!autocvar_g_norecoil)
58 actor.punchangle_x = random() - 0.5;
59 actor.punchangle_y = random() - 0.5;
61 int slot = weaponslot(weaponentity);
62 // this attack_finished just enforces a cooldown at the end of a burst
63 ATTACK_FINISHED(actor, slot) = time + WEP_CVAR(okmachinegun, first_refire) * W_WeaponRateFactor(actor);
65 if(actor.(weaponentity).misc_bulletcounter == 1)
66 fireBullet(actor, weaponentity, w_shotorg, w_shotdir, WEP_CVAR(okmachinegun, first_spread), WEP_CVAR(okmachinegun, solidpenetration), WEP_CVAR(okmachinegun, first_damage), WEP_CVAR(okmachinegun, first_force), deathtype, 0);
68 fireBullet(actor, weaponentity, w_shotorg, w_shotdir, WEP_CVAR(okmachinegun, sustained_spread), WEP_CVAR(okmachinegun, solidpenetration), WEP_CVAR(okmachinegun, sustained_damage), WEP_CVAR(okmachinegun, sustained_force), deathtype, 0);
70 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
72 W_OverkillMachineGun_MuzzleFlash(actor, weaponentity);
73 W_AttachToShotorg(actor, weaponentity, actor.(weaponentity).muzzle_flash, '5 0 0');
76 if(autocvar_g_casings >= 2)
78 makevectors(actor.v_angle); // for some reason, this is lost
79 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);
82 if(actor.(weaponentity).misc_bulletcounter == 1)
83 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(okmachinegun, first_ammo), weaponentity);
85 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(okmachinegun, sustained_ammo), weaponentity);
89 void W_OverkillMachineGun_Attack_Frame(Weapon thiswep, entity actor, .entity weaponentity, int fire)
91 if(actor.(weaponentity).m_weapon != actor.(weaponentity).m_switchweapon) // abort immediately if switching
93 w_ready(thiswep, actor, weaponentity, fire);
96 if(PHYS_INPUT_BUTTON_ATCK(actor))
98 if(!thiswep.wr_checkammo2(thiswep, actor, weaponentity))
99 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
101 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
102 w_ready(thiswep, actor, weaponentity, fire);
105 actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
106 W_OverkillMachineGun_Attack(WEP_OVERKILL_MACHINEGUN, WEP_OVERKILL_MACHINEGUN.m_id, actor, weaponentity);
107 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(okmachinegun, sustained_refire), W_OverkillMachineGun_Attack_Frame);
110 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(okmachinegun, sustained_refire), w_ready);
113 void W_OverkillMachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity, int fire)
115 float okmachinegun_spread;
119 w_ready(thiswep, actor, weaponentity, fire);
123 if(!thiswep.wr_checkammo1(thiswep, actor, weaponentity))
124 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
126 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
127 w_ready(thiswep, actor, weaponentity, fire);
131 W_DecreaseAmmo(WEP_OVERKILL_MACHINEGUN, actor, WEP_CVAR(okmachinegun, sustained_ammo), weaponentity);
133 W_SetupShot(actor, weaponentity, true, 0, SND_UZI_FIRE, CH_WEAPON_A, WEP_CVAR(okmachinegun, sustained_damage));
134 if(!autocvar_g_norecoil)
136 actor.punchangle_x = random() - 0.5;
137 actor.punchangle_y = random() - 0.5;
140 okmachinegun_spread = bound(WEP_CVAR(okmachinegun, spread_min), WEP_CVAR(okmachinegun, spread_min) + (WEP_CVAR(okmachinegun, spread_add) * actor.(weaponentity).misc_bulletcounter), WEP_CVAR(okmachinegun, spread_max));
141 fireBullet(actor, weaponentity, w_shotorg, w_shotdir, okmachinegun_spread, WEP_CVAR(okmachinegun, solidpenetration), WEP_CVAR(okmachinegun, sustained_damage), WEP_CVAR(okmachinegun, sustained_force), WEP_OVERKILL_MACHINEGUN.m_id, 0);
143 actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
145 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
147 W_OverkillMachineGun_MuzzleFlash(actor, weaponentity);
148 W_AttachToShotorg(actor, weaponentity, actor.(weaponentity).muzzle_flash, '5 0 0');
150 if(autocvar_g_casings >= 2) // casing code
152 makevectors(actor.v_angle); // for some reason, this is lost
153 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);
156 int slot = weaponslot(weaponentity);
157 ATTACK_FINISHED(actor, slot) = time + WEP_CVAR(okmachinegun, first_refire) * W_WeaponRateFactor(actor);
158 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(okmachinegun, sustained_refire), W_OverkillMachineGun_Attack_Auto);
161 void W_OverkillMachineGun_Attack_Burst(Weapon thiswep, entity actor, .entity weaponentity, int fire)
163 W_SetupShot(actor, weaponentity, true, 0, SND_UZI_FIRE, CH_WEAPON_A, WEP_CVAR(okmachinegun, sustained_damage));
164 if(!autocvar_g_norecoil)
166 actor.punchangle_x = random() - 0.5;
167 actor.punchangle_y = random() - 0.5;
170 fireBullet(actor, weaponentity, w_shotorg, w_shotdir, WEP_CVAR(okmachinegun, burst_speed), WEP_CVAR(okmachinegun, solidpenetration), WEP_CVAR(okmachinegun, sustained_damage), WEP_CVAR(okmachinegun, sustained_force), WEP_OVERKILL_MACHINEGUN.m_id, 0);
172 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
174 W_OverkillMachineGun_MuzzleFlash(actor, weaponentity);
175 W_AttachToShotorg(actor, weaponentity, actor.(weaponentity).muzzle_flash, '5 0 0');
177 if(autocvar_g_casings >= 2) // casing code
179 makevectors(actor.v_angle); // for some reason, this is lost
180 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);
183 actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
184 if(actor.(weaponentity).misc_bulletcounter == 0)
186 int slot = weaponslot(weaponentity);
187 ATTACK_FINISHED(actor, slot) = time + WEP_CVAR(okmachinegun, burst_refire2) * W_WeaponRateFactor(actor);
188 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(okmachinegun, burst_animtime), w_ready);
192 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(okmachinegun, burst_refire), W_OverkillMachineGun_Attack_Burst);
197 METHOD(OverkillMachineGun, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
199 if(vdist(actor.origin - actor.enemy.origin, <, 3000 - bound(0, skill, 10) * 200))
200 PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
202 PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
205 METHOD(OverkillMachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
207 if (WEP_CVAR(okmachinegun, reload_ammo) && actor.(weaponentity).clip_load < min(max(WEP_CVAR(okmachinegun, sustained_ammo), WEP_CVAR(okmachinegun, first_ammo)), WEP_CVAR(okmachinegun, burst_ammo)))
209 thiswep.wr_reload(thiswep, actor, weaponentity);
211 else if (WEP_CVAR(okmachinegun, mode) == 1)
214 if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
216 actor.(weaponentity).misc_bulletcounter = 0;
217 W_OverkillMachineGun_Attack_Auto(thiswep, actor, weaponentity, fire);
222 if (WEP_CVAR_SEC(okmachinegun, type) == 1)
224 if (weapon_prepareattack(thiswep, actor, weaponentity, true, 0))
226 if (!thiswep.wr_checkammo2(thiswep, actor, weaponentity))
227 if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
229 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
230 w_ready(thiswep, actor, weaponentity, fire);
234 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(okmachinegun, burst_ammo), weaponentity);
236 actor.(weaponentity).misc_bulletcounter = WEP_CVAR(okmachinegun, burst) * -1;
237 W_OverkillMachineGun_Attack_Burst(thiswep, actor, weaponentity, fire);
242 if (!weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(okmachinegun, refire)))
246 // ugly instagib hack to reuse the fire mode of the laser
247 makevectors(actor.v_angle);
248 Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
249 actor.(weaponentity).m_weapon = WEP_BLASTER;
253 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
254 WEP_CVAR_SEC(okmachinegun, shotangle),
255 WEP_CVAR_SEC(okmachinegun, damage),
256 WEP_CVAR_SEC(okmachinegun, edgedamage),
257 WEP_CVAR_SEC(okmachinegun, radius),
258 WEP_CVAR_SEC(okmachinegun, force),
259 WEP_CVAR_SEC(okmachinegun, speed),
260 WEP_CVAR_SEC(okmachinegun, spread),
261 WEP_CVAR_SEC(okmachinegun, delay),
262 WEP_CVAR_SEC(okmachinegun, lifetime)
264 actor.(weaponentity).m_weapon = oldwep;
265 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(okmachinegun, animtime), w_ready);
272 if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
274 actor.(weaponentity).misc_bulletcounter = 1;
275 W_OverkillMachineGun_Attack(WEP_OVERKILL_MACHINEGUN, WEP_OVERKILL_MACHINEGUN.m_id, actor, weaponentity); // sets attack_finished
276 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(okmachinegun, sustained_refire), W_OverkillMachineGun_Attack_Frame);
281 if (WEP_CVAR_SEC(okmachinegun, type) == 1)
283 if (WEP_CVAR(okmachinegun, first))
285 if (weapon_prepareattack(thiswep, actor, weaponentity, true, 0))
287 actor.(weaponentity).misc_bulletcounter = 1;
288 W_OverkillMachineGun_Attack(WEP_OVERKILL_MACHINEGUN, WEP_OVERKILL_MACHINEGUN.m_id | HITTYPE_SECONDARY, actor, weaponentity); // sets attack_finished
289 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(okmachinegun, first_refire), w_ready);
295 if (!weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(okmachinegun, refire)))
299 // ugly instagib hack to reuse the fire mode of the laser
300 makevectors(actor.v_angle);
301 Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
302 actor.(weaponentity).m_weapon = WEP_BLASTER;
306 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
307 WEP_CVAR_SEC(okmachinegun, shotangle),
308 WEP_CVAR_SEC(okmachinegun, damage),
309 WEP_CVAR_SEC(okmachinegun, edgedamage),
310 WEP_CVAR_SEC(okmachinegun, radius),
311 WEP_CVAR_SEC(okmachinegun, force),
312 WEP_CVAR_SEC(okmachinegun, speed),
313 WEP_CVAR_SEC(okmachinegun, spread),
314 WEP_CVAR_SEC(okmachinegun, delay),
315 WEP_CVAR_SEC(okmachinegun, lifetime)
317 actor.(weaponentity).m_weapon = oldwep;
318 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(okmachinegun, animtime), w_ready);
324 METHOD(OverkillMachineGun, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
327 if(WEP_CVAR(okmachinegun, mode) == 1)
328 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, sustained_ammo);
330 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, first_ammo);
332 if(WEP_CVAR(okmachinegun, reload_ammo))
334 if(WEP_CVAR(okmachinegun, mode) == 1)
335 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, sustained_ammo);
337 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, first_ammo);
342 METHOD(OverkillMachineGun, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
345 if(WEP_CVAR(okmachinegun, mode) == 1)
346 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, burst_ammo);
348 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, first_ammo);
350 if(WEP_CVAR(okmachinegun, reload_ammo))
352 if(WEP_CVAR(okmachinegun, mode) == 1)
353 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, burst_ammo);
355 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, first_ammo);
360 METHOD(OverkillMachineGun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
362 W_Reload(actor, weaponentity, min(max(WEP_CVAR(okmachinegun, sustained_ammo), WEP_CVAR(okmachinegun, first_ammo)), WEP_CVAR(okmachinegun, burst_ammo)), SND_RELOAD);
365 METHOD(OverkillMachineGun, wr_suicidemessage, Notification(entity thiswep))
367 return WEAPON_THINKING_WITH_PORTALS;
370 METHOD(OverkillMachineGun, wr_killmessage, Notification(entity thiswep))
372 if(w_deathtype & HITTYPE_SECONDARY)
373 return WEAPON_MACHINEGUN_MURDER_SNIPE;
375 return WEAPON_MACHINEGUN_MURDER_SPRAY;
381 METHOD(OverkillMachineGun, wr_impacteffect, void(entity thiswep, entity actor))
384 org2 = w_org + w_backoff * 2;
385 pointparticles(EFFECT_MACHINEGUN_IMPACT, org2, w_backoff * 1000, 1);
387 sound(actor, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTN_NORM);