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(Weapon thiswep, int deathtype, entity actor, .entity weaponentity)
18 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)));
19 if(!autocvar_g_norecoil)
21 actor.punchangle_x = random() - 0.5;
22 actor.punchangle_y = random() - 0.5;
24 int slot = weaponslot(weaponentity);
25 // this attack_finished just enforces a cooldown at the end of a burst
26 ATTACK_FINISHED(actor, slot) = time + WEP_CVAR(okmachinegun, first_refire) * W_WeaponRateFactor(actor);
28 if(actor.(weaponentity).misc_bulletcounter == 1)
29 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);
31 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);
33 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
35 W_MachineGun_MuzzleFlash(actor, weaponentity);
36 W_AttachToShotorg(actor, weaponentity, actor.(weaponentity).muzzle_flash, '5 0 0');
39 if(autocvar_g_casings >= 2)
41 makevectors(actor.v_angle); // for some reason, this is lost
42 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);
45 if(actor.(weaponentity).misc_bulletcounter == 1)
46 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(okmachinegun, first_ammo), weaponentity);
48 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(okmachinegun, sustained_ammo), weaponentity);
52 void W_OverkillMachineGun_Attack_Frame(Weapon thiswep, entity actor, .entity weaponentity, int fire)
54 if(actor.(weaponentity).m_weapon != actor.(weaponentity).m_switchweapon) // abort immediately if switching
56 w_ready(thiswep, actor, weaponentity, fire);
59 if(PHYS_INPUT_BUTTON_ATCK(actor))
61 if(!thiswep.wr_checkammo2(thiswep, actor, weaponentity))
62 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
64 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
65 w_ready(thiswep, actor, weaponentity, fire);
68 actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
69 W_OverkillMachineGun_Attack(WEP_OVERKILL_MACHINEGUN, WEP_OVERKILL_MACHINEGUN.m_id, actor, weaponentity);
70 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(okmachinegun, sustained_refire), W_OverkillMachineGun_Attack_Frame);
73 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(okmachinegun, sustained_refire), w_ready);
76 void W_OverkillMachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity, int fire)
78 float okmachinegun_spread;
82 w_ready(thiswep, actor, weaponentity, fire);
86 if(!thiswep.wr_checkammo1(thiswep, actor, weaponentity))
87 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
89 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
90 w_ready(thiswep, actor, weaponentity, fire);
94 W_DecreaseAmmo(WEP_OVERKILL_MACHINEGUN, actor, WEP_CVAR(okmachinegun, sustained_ammo), weaponentity);
96 W_SetupShot(actor, weaponentity, true, 0, SND_UZI_FIRE, CH_WEAPON_A, WEP_CVAR(okmachinegun, sustained_damage));
97 if(!autocvar_g_norecoil)
99 actor.punchangle_x = random() - 0.5;
100 actor.punchangle_y = random() - 0.5;
103 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));
104 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);
106 actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
108 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
110 W_MachineGun_MuzzleFlash(actor, weaponentity);
111 W_AttachToShotorg(actor, weaponentity, actor.(weaponentity).muzzle_flash, '5 0 0');
113 if(autocvar_g_casings >= 2) // casing code
115 makevectors(actor.v_angle); // for some reason, this is lost
116 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);
119 int slot = weaponslot(weaponentity);
120 ATTACK_FINISHED(actor, slot) = time + WEP_CVAR(okmachinegun, first_refire) * W_WeaponRateFactor(actor);
121 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(okmachinegun, sustained_refire), W_OverkillMachineGun_Attack_Auto);
124 METHOD(OverkillMachineGun, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
126 if(vdist(actor.origin - actor.enemy.origin, <, 3000 - bound(0, skill, 10) * 200))
127 PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
129 PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
132 METHOD(OverkillMachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
134 if ((WEP_CVAR_SEC(okmachinegun, refire_type) == 1) && (fire & 2) && (time >= actor.jump_interval))
136 // Secondary uses it's own refire timer if refire_type is 1.
137 actor.jump_interval = time + WEP_CVAR_SEC(okmachinegun, refire) * W_WeaponRateFactor(actor);
138 // Ugly hack to reuse the fire mode of the blaster.
139 makevectors(actor.v_angle);
140 Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
141 actor.(weaponentity).m_weapon = WEP_BLASTER;
145 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
146 WEP_CVAR_SEC(okmachinegun, shotangle),
147 WEP_CVAR_SEC(okmachinegun, damage),
148 WEP_CVAR_SEC(okmachinegun, edgedamage),
149 WEP_CVAR_SEC(okmachinegun, radius),
150 WEP_CVAR_SEC(okmachinegun, force),
151 WEP_CVAR_SEC(okmachinegun, speed),
152 WEP_CVAR_SEC(okmachinegun, spread),
153 WEP_CVAR_SEC(okmachinegun, delay),
154 WEP_CVAR_SEC(okmachinegun, lifetime)
156 actor.(weaponentity).m_weapon = oldwep;
158 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)))
161 thiswep.wr_reload(thiswep, actor, weaponentity);
164 if (WEP_CVAR(okmachinegun, mode) == 1)
166 if(fire & 1) // Primary attack
168 if (!weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
172 actor.(weaponentity).misc_bulletcounter = 0;
173 W_OverkillMachineGun_Attack_Auto(thiswep, actor, weaponentity, fire);
176 if ((fire & 2) && (WEP_CVAR_SEC(okmachinegun, refire_type) == 0)) // Secondary attack
178 if (!weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(okmachinegun, refire)))
182 // ugly instagib hack to reuse the fire mode of the laser
183 makevectors(actor.v_angle);
184 Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
185 actor.(weaponentity).m_weapon = WEP_BLASTER;
189 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
190 WEP_CVAR_SEC(okmachinegun, shotangle),
191 WEP_CVAR_SEC(okmachinegun, damage),
192 WEP_CVAR_SEC(okmachinegun, edgedamage),
193 WEP_CVAR_SEC(okmachinegun, radius),
194 WEP_CVAR_SEC(okmachinegun, force),
195 WEP_CVAR_SEC(okmachinegun, speed),
196 WEP_CVAR_SEC(okmachinegun, spread),
197 WEP_CVAR_SEC(okmachinegun, delay),
198 WEP_CVAR_SEC(okmachinegun, lifetime)
200 actor.(weaponentity).m_weapon = oldwep;
201 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(okmachinegun, animtime), w_ready);
206 if (fire & 1) // Primary attack
208 if (!weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
212 actor.(weaponentity).misc_bulletcounter = 1;
213 W_OverkillMachineGun_Attack(WEP_OVERKILL_MACHINEGUN, WEP_OVERKILL_MACHINEGUN.m_id, actor, weaponentity); // sets attack_finished
214 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(okmachinegun, sustained_refire), W_OverkillMachineGun_Attack_Frame);
217 if ((fire & 2) && (WEP_CVAR_SEC(okmachinegun, refire_type) == 0)) // Secondary attack
219 if (!weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(okmachinegun, refire)))
223 // ugly instagib hack to reuse the fire mode of the laser
224 makevectors(actor.v_angle);
225 Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
226 actor.(weaponentity).m_weapon = WEP_BLASTER;
230 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
231 WEP_CVAR_SEC(okmachinegun, shotangle),
232 WEP_CVAR_SEC(okmachinegun, damage),
233 WEP_CVAR_SEC(okmachinegun, edgedamage),
234 WEP_CVAR_SEC(okmachinegun, radius),
235 WEP_CVAR_SEC(okmachinegun, force),
236 WEP_CVAR_SEC(okmachinegun, speed),
237 WEP_CVAR_SEC(okmachinegun, spread),
238 WEP_CVAR_SEC(okmachinegun, delay),
239 WEP_CVAR_SEC(okmachinegun, lifetime)
241 actor.(weaponentity).m_weapon = oldwep;
242 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(okmachinegun, animtime), w_ready);
247 METHOD(OverkillMachineGun, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
250 if(WEP_CVAR(okmachinegun, mode) == 1)
251 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, sustained_ammo);
253 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, first_ammo);
255 if(WEP_CVAR(okmachinegun, reload_ammo))
257 if(WEP_CVAR(okmachinegun, mode) == 1)
258 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, sustained_ammo);
260 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, first_ammo);
265 METHOD(OverkillMachineGun, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
268 if(WEP_CVAR(okmachinegun, mode) == 1)
269 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, burst_ammo);
271 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, first_ammo);
273 if(WEP_CVAR(okmachinegun, reload_ammo))
275 if(WEP_CVAR(okmachinegun, mode) == 1)
276 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, burst_ammo);
278 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, first_ammo);
283 METHOD(OverkillMachineGun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
285 W_Reload(actor, weaponentity, min(max(WEP_CVAR(okmachinegun, sustained_ammo), WEP_CVAR(okmachinegun, first_ammo)), WEP_CVAR(okmachinegun, burst_ammo)), SND_RELOAD);
288 METHOD(OverkillMachineGun, wr_suicidemessage, Notification(entity thiswep))
290 return WEAPON_THINKING_WITH_PORTALS;
293 METHOD(OverkillMachineGun, wr_killmessage, Notification(entity thiswep))
295 if(w_deathtype & HITTYPE_SECONDARY)
296 return WEAPON_MACHINEGUN_MURDER_SNIPE;
298 return WEAPON_MACHINEGUN_MURDER_SPRAY;
304 METHOD(OverkillMachineGun, wr_impacteffect, void(entity thiswep, entity actor))
307 org2 = w_org + w_backoff * 2;
308 pointparticles(EFFECT_MACHINEGUN_IMPACT, org2, w_backoff * 1000, 1);
310 sound(actor, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTN_NORM);