1 #include "machinegun.qh"
5 METHOD(MachineGun, m_spawnfunc_hookreplace, Weapon(MachineGun this, entity e))
7 if(autocvar_sv_q3acompat_machineshotgunswap)
8 if(e.classname != "droppedweapon")
15 void W_MachineGun_MuzzleFlash_Think(entity this)
20 this.nextthink = time + 0.05;
24 setthink(this, SUB_Remove);
25 this.nextthink = time;
26 this.realowner.muzzle_flash = NULL;
32 void W_MachineGun_MuzzleFlash(entity actor, .entity weaponentity)
34 entity wepent = actor.(weaponentity);
36 if(wepent.muzzle_flash == NULL)
37 wepent.muzzle_flash = spawn();
39 // muzzle flash for 1st person view
40 setmodel(wepent.muzzle_flash, MDL_MACHINEGUN_MUZZLEFLASH); // precision set below
42 wepent.muzzle_flash.scale = 0.75;
43 setthink(wepent.muzzle_flash, W_MachineGun_MuzzleFlash_Think);
44 wepent.muzzle_flash.nextthink = time + 0.02;
45 wepent.muzzle_flash.frame = 2;
46 wepent.muzzle_flash.alpha = 0.75;
47 wepent.muzzle_flash.angles_z = random() * 180;
48 wepent.muzzle_flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
49 wepent.muzzle_flash.owner = wepent.muzzle_flash.realowner = wepent;
52 void W_MachineGun_Attack(Weapon thiswep, int deathtype, entity actor, .entity weaponentity)
54 W_SetupShot(actor, weaponentity, true, 0, SND_UZI_FIRE, CH_WEAPON_A, ((actor.(weaponentity).misc_bulletcounter == 1) ? WEP_CVAR(machinegun, first_damage) : WEP_CVAR(machinegun, sustained_damage)));
55 if(!autocvar_g_norecoil)
57 actor.punchangle_x = random() - 0.5;
58 actor.punchangle_y = random() - 0.5;
60 int slot = weaponslot(weaponentity);
61 // this attack_finished just enforces a cooldown at the end of a burst
62 ATTACK_FINISHED(actor, slot) = time + WEP_CVAR(machinegun, first_refire) * W_WeaponRateFactor(actor);
64 if(actor.(weaponentity).misc_bulletcounter == 1)
65 fireBullet(actor, weaponentity, w_shotorg, w_shotdir, WEP_CVAR(machinegun, first_spread), WEP_CVAR(machinegun, solidpenetration), WEP_CVAR(machinegun, first_damage), WEP_CVAR(machinegun, first_force), deathtype, 0);
67 fireBullet(actor, weaponentity, w_shotorg, w_shotdir, WEP_CVAR(machinegun, sustained_spread), WEP_CVAR(machinegun, solidpenetration), WEP_CVAR(machinegun, sustained_damage), WEP_CVAR(machinegun, sustained_force), deathtype, 0);
69 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
71 W_MachineGun_MuzzleFlash(actor, weaponentity);
72 W_AttachToShotorg(actor, weaponentity, actor.(weaponentity).muzzle_flash, '5 0 0');
75 if(autocvar_g_casings >= 2)
77 makevectors(actor.v_angle); // for some reason, this is lost
78 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);
81 if(actor.(weaponentity).misc_bulletcounter == 1)
82 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(machinegun, first_ammo), weaponentity);
84 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(machinegun, sustained_ammo), weaponentity);
88 void W_MachineGun_Attack_Frame(Weapon thiswep, entity actor, .entity weaponentity, int fire)
90 if(actor.(weaponentity).m_weapon != actor.(weaponentity).m_switchweapon) // abort immediately if switching
92 w_ready(thiswep, actor, weaponentity, fire);
95 if(PHYS_INPUT_BUTTON_ATCK(actor))
97 if(!thiswep.wr_checkammo2(thiswep, actor, weaponentity))
98 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
100 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
101 w_ready(thiswep, actor, weaponentity, fire);
104 actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
105 W_MachineGun_Attack(WEP_MACHINEGUN, WEP_MACHINEGUN.m_id, actor, weaponentity);
106 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), W_MachineGun_Attack_Frame);
109 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), w_ready);
113 void W_MachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity, int fire)
115 float machinegun_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_MACHINEGUN, actor, WEP_CVAR(machinegun, sustained_ammo), weaponentity);
133 W_SetupShot(actor, weaponentity, true, 0, SND_UZI_FIRE, CH_WEAPON_A, WEP_CVAR(machinegun, sustained_damage));
134 if(!autocvar_g_norecoil)
136 actor.punchangle_x = random() - 0.5;
137 actor.punchangle_y = random() - 0.5;
140 machinegun_spread = bound(WEP_CVAR(machinegun, spread_min), WEP_CVAR(machinegun, spread_min) + (WEP_CVAR(machinegun, spread_add) * actor.(weaponentity).misc_bulletcounter), WEP_CVAR(machinegun, spread_max));
141 fireBullet(actor, weaponentity, w_shotorg, w_shotdir, machinegun_spread, WEP_CVAR(machinegun, solidpenetration), WEP_CVAR(machinegun, sustained_damage), WEP_CVAR(machinegun, sustained_force), WEP_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_MachineGun_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(machinegun, first_refire) * W_WeaponRateFactor(actor);
158 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), W_MachineGun_Attack_Auto);
161 void W_MachineGun_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(machinegun, 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(machinegun, burst_speed), WEP_CVAR(machinegun, solidpenetration), WEP_CVAR(machinegun, sustained_damage), WEP_CVAR(machinegun, sustained_force), WEP_MACHINEGUN.m_id, 0);
172 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
174 W_MachineGun_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(machinegun, burst_refire2) * W_WeaponRateFactor(actor);
188 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(machinegun, burst_animtime), w_ready);
192 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(machinegun, burst_refire), W_MachineGun_Attack_Burst);
197 METHOD(MachineGun, 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);
204 METHOD(MachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
206 if(WEP_CVAR(machinegun, reload_ammo) && actor.(weaponentity).clip_load < min(max(WEP_CVAR(machinegun, sustained_ammo), WEP_CVAR(machinegun, first_ammo)), WEP_CVAR(machinegun, burst_ammo))) { // forced reload
207 thiswep.wr_reload(thiswep, actor, weaponentity);
209 if(WEP_CVAR(machinegun, mode) == 1)
212 if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
214 actor.(weaponentity).misc_bulletcounter = 0;
215 W_MachineGun_Attack_Auto(thiswep, actor, weaponentity, fire);
219 if(weapon_prepareattack(thiswep, actor, weaponentity, true, 0))
221 if(!thiswep.wr_checkammo2(thiswep, actor, weaponentity))
222 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
224 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
225 w_ready(thiswep, actor, weaponentity, fire);
229 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(machinegun, burst_ammo), weaponentity);
231 actor.(weaponentity).misc_bulletcounter = WEP_CVAR(machinegun, burst) * -1;
232 W_MachineGun_Attack_Burst(thiswep, actor, weaponentity, fire);
239 if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
241 actor.(weaponentity).misc_bulletcounter = 1;
242 W_MachineGun_Attack(WEP_MACHINEGUN, WEP_MACHINEGUN.m_id, actor, weaponentity); // sets attack_finished
243 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), W_MachineGun_Attack_Frame);
246 if((fire & 2) && WEP_CVAR(machinegun, first))
247 if(weapon_prepareattack(thiswep, actor, weaponentity, true, 0))
249 actor.(weaponentity).misc_bulletcounter = 1;
250 W_MachineGun_Attack(WEP_MACHINEGUN, WEP_MACHINEGUN.m_id | HITTYPE_SECONDARY, actor, weaponentity); // sets attack_finished
251 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(machinegun, first_refire), w_ready);
255 METHOD(MachineGun, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
258 if(WEP_CVAR(machinegun, mode) == 1)
259 ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR(machinegun, sustained_ammo);
261 ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR(machinegun, first_ammo);
263 if(WEP_CVAR(machinegun, reload_ammo))
265 if(WEP_CVAR(machinegun, mode) == 1)
266 ammo_amount += actor.(weaponentity).(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, sustained_ammo);
268 ammo_amount += actor.(weaponentity).(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, first_ammo);
272 METHOD(MachineGun, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
275 if(WEP_CVAR(machinegun, mode) == 1)
276 ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR(machinegun, burst_ammo);
278 ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR(machinegun, first_ammo);
280 if(WEP_CVAR(machinegun, reload_ammo))
282 if(WEP_CVAR(machinegun, mode) == 1)
283 ammo_amount += actor.(weaponentity).(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, burst_ammo);
285 ammo_amount += actor.(weaponentity).(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, first_ammo);
289 METHOD(MachineGun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
291 W_Reload(actor, weaponentity, min(max(WEP_CVAR(machinegun, sustained_ammo), WEP_CVAR(machinegun, first_ammo)), WEP_CVAR(machinegun, burst_ammo)), SND_RELOAD);
293 METHOD(MachineGun, wr_suicidemessage, Notification(entity thiswep))
295 return WEAPON_THINKING_WITH_PORTALS;
297 METHOD(MachineGun, wr_killmessage, Notification(entity thiswep))
299 if(w_deathtype & HITTYPE_SECONDARY)
300 return WEAPON_MACHINEGUN_MURDER_SNIPE;
302 return WEAPON_MACHINEGUN_MURDER_SPRAY;
308 METHOD(MachineGun, wr_impacteffect, void(entity thiswep, entity actor))
311 org2 = w_org + w_backoff * 2;
312 pointparticles(EFFECT_MACHINEGUN_IMPACT, org2, w_backoff * 1000, 1);
314 sound(actor, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTN_NORM);