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(okmachinegun, reload_ammo) && actor.(weaponentity).clip_load < min(max(WEP_CVAR(okmachinegun, sustained_ammo), WEP_CVAR(okmachinegun, first_ammo)), WEP_CVAR(okmachinegun, burst_ammo)))
136 thiswep.wr_reload(thiswep, actor, weaponentity);
138 else if (WEP_CVAR(okmachinegun, mode) == 1)
140 if(fire & 1) // Primary attack
141 if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
143 actor.(weaponentity).misc_bulletcounter = 0;
144 W_OverkillMachineGun_Attack_Auto(thiswep, actor, weaponentity, fire);
147 if (fire & 2) // Secondary attack
149 if (!weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(okmachinegun, refire)))
153 // ugly instagib hack to reuse the fire mode of the laser
154 makevectors(actor.v_angle);
155 Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
156 actor.(weaponentity).m_weapon = WEP_BLASTER;
160 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
161 WEP_CVAR_SEC(okmachinegun, shotangle),
162 WEP_CVAR_SEC(okmachinegun, damage),
163 WEP_CVAR_SEC(okmachinegun, edgedamage),
164 WEP_CVAR_SEC(okmachinegun, radius),
165 WEP_CVAR_SEC(okmachinegun, force),
166 WEP_CVAR_SEC(okmachinegun, speed),
167 WEP_CVAR_SEC(okmachinegun, spread),
168 WEP_CVAR_SEC(okmachinegun, delay),
169 WEP_CVAR_SEC(okmachinegun, lifetime)
171 actor.(weaponentity).m_weapon = oldwep;
172 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(okmachinegun, animtime), w_ready);
177 if(fire & 1) // Primary attack
178 if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
180 actor.(weaponentity).misc_bulletcounter = 1;
181 W_OverkillMachineGun_Attack(WEP_OVERKILL_MACHINEGUN, WEP_OVERKILL_MACHINEGUN.m_id, actor, weaponentity); // sets attack_finished
182 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(okmachinegun, sustained_refire), W_OverkillMachineGun_Attack_Frame);
185 if (fire & 2) // Secondary attack
187 if (!weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(okmachinegun, refire)))
191 // ugly instagib hack to reuse the fire mode of the laser
192 makevectors(actor.v_angle);
193 Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
194 actor.(weaponentity).m_weapon = WEP_BLASTER;
198 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
199 WEP_CVAR_SEC(okmachinegun, shotangle),
200 WEP_CVAR_SEC(okmachinegun, damage),
201 WEP_CVAR_SEC(okmachinegun, edgedamage),
202 WEP_CVAR_SEC(okmachinegun, radius),
203 WEP_CVAR_SEC(okmachinegun, force),
204 WEP_CVAR_SEC(okmachinegun, speed),
205 WEP_CVAR_SEC(okmachinegun, spread),
206 WEP_CVAR_SEC(okmachinegun, delay),
207 WEP_CVAR_SEC(okmachinegun, lifetime)
209 actor.(weaponentity).m_weapon = oldwep;
210 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(okmachinegun, animtime), w_ready);
215 METHOD(OverkillMachineGun, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
218 if(WEP_CVAR(okmachinegun, mode) == 1)
219 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, sustained_ammo);
221 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, first_ammo);
223 if(WEP_CVAR(okmachinegun, reload_ammo))
225 if(WEP_CVAR(okmachinegun, mode) == 1)
226 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, sustained_ammo);
228 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, first_ammo);
233 METHOD(OverkillMachineGun, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
236 if(WEP_CVAR(okmachinegun, mode) == 1)
237 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, burst_ammo);
239 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, first_ammo);
241 if(WEP_CVAR(okmachinegun, reload_ammo))
243 if(WEP_CVAR(okmachinegun, mode) == 1)
244 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, burst_ammo);
246 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, first_ammo);
251 METHOD(OverkillMachineGun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
253 W_Reload(actor, weaponentity, min(max(WEP_CVAR(okmachinegun, sustained_ammo), WEP_CVAR(okmachinegun, first_ammo)), WEP_CVAR(okmachinegun, burst_ammo)), SND_RELOAD);
256 METHOD(OverkillMachineGun, wr_suicidemessage, Notification(entity thiswep))
258 return WEAPON_THINKING_WITH_PORTALS;
261 METHOD(OverkillMachineGun, wr_killmessage, Notification(entity thiswep))
263 if(w_deathtype & HITTYPE_SECONDARY)
264 return WEAPON_MACHINEGUN_MURDER_SNIPE;
266 return WEAPON_MACHINEGUN_MURDER_SPRAY;
272 METHOD(OverkillMachineGun, wr_impacteffect, void(entity thiswep, entity actor))
275 org2 = w_org + w_backoff * 2;
276 pointparticles(EFFECT_MACHINEGUN_IMPACT, org2, w_backoff * 1000, 1);
278 sound(actor, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTN_NORM);