1 #include "machinegun.qh"
5 spawnfunc(weapon_machinegun)
7 if(autocvar_sv_q3acompat_machineshotgunswap)
8 if(this.classname != "droppedweapon")
10 weapon_defaultspawnfunc(this, WEP_SHOCKWAVE);
13 weapon_defaultspawnfunc(this, WEP_MACHINEGUN);
15 spawnfunc(weapon_uzi) { spawnfunc_weapon_machinegun(this); }
17 void W_MachineGun_MuzzleFlash_Think(entity this)
22 this.nextthink = time + 0.05;
26 setthink(this, SUB_Remove);
27 this.nextthink = time;
28 this.realowner.muzzle_flash = NULL;
34 void W_MachineGun_MuzzleFlash(entity actor, .entity weaponentity)
36 entity wepent = actor.(weaponentity);
38 if(wepent.muzzle_flash == NULL)
39 wepent.muzzle_flash = spawn();
41 // muzzle flash for 1st person view
42 setmodel(wepent.muzzle_flash, MDL_MACHINEGUN_MUZZLEFLASH); // precision set below
44 wepent.muzzle_flash.scale = 0.75;
45 setthink(wepent.muzzle_flash, W_MachineGun_MuzzleFlash_Think);
46 wepent.muzzle_flash.nextthink = time + 0.02;
47 wepent.muzzle_flash.frame = 2;
48 wepent.muzzle_flash.alpha = 0.75;
49 wepent.muzzle_flash.angles_z = random() * 180;
50 wepent.muzzle_flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
51 wepent.muzzle_flash.owner = wepent.muzzle_flash.realowner = wepent;
54 void W_MachineGun_Attack(Weapon thiswep, int deathtype, entity actor, .entity weaponentity)
56 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)));
57 if(!autocvar_g_norecoil)
59 actor.punchangle_x = random() - 0.5;
60 actor.punchangle_y = random() - 0.5;
62 int slot = weaponslot(weaponentity);
63 // this attack_finished just enforces a cooldown at the end of a burst
64 ATTACK_FINISHED(actor, slot) = time + WEP_CVAR(machinegun, first_refire) * W_WeaponRateFactor(actor);
66 if(actor.(weaponentity).misc_bulletcounter == 1)
67 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);
69 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);
71 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
73 W_MachineGun_MuzzleFlash(actor, weaponentity);
74 W_AttachToShotorg(actor, weaponentity, actor.(weaponentity).muzzle_flash, '5 0 0');
77 if(autocvar_g_casings >= 2)
79 makevectors(actor.v_angle); // for some reason, this is lost
80 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);
83 if(actor.(weaponentity).misc_bulletcounter == 1)
84 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(machinegun, first_ammo), weaponentity);
86 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(machinegun, sustained_ammo), weaponentity);
90 void W_MachineGun_Attack_Frame(Weapon thiswep, entity actor, .entity weaponentity, int fire)
92 if(actor.(weaponentity).m_weapon != actor.(weaponentity).m_switchweapon) // abort immediately if switching
94 w_ready(thiswep, actor, weaponentity, fire);
97 if(PHYS_INPUT_BUTTON_ATCK(actor))
99 if(!thiswep.wr_checkammo2(thiswep, actor, weaponentity))
100 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
102 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
103 w_ready(thiswep, actor, weaponentity, fire);
106 actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
107 W_MachineGun_Attack(WEP_MACHINEGUN, WEP_MACHINEGUN.m_id, actor, weaponentity);
108 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), W_MachineGun_Attack_Frame);
111 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), w_ready);
115 void W_MachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity, int fire)
117 float machinegun_spread;
121 w_ready(thiswep, actor, weaponentity, fire);
125 if(!thiswep.wr_checkammo1(thiswep, actor, weaponentity))
126 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
128 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
129 w_ready(thiswep, actor, weaponentity, fire);
133 W_DecreaseAmmo(WEP_MACHINEGUN, actor, WEP_CVAR(machinegun, sustained_ammo), weaponentity);
135 W_SetupShot(actor, weaponentity, true, 0, SND_UZI_FIRE, CH_WEAPON_A, WEP_CVAR(machinegun, sustained_damage));
136 if(!autocvar_g_norecoil)
138 actor.punchangle_x = random() - 0.5;
139 actor.punchangle_y = random() - 0.5;
142 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));
143 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);
145 actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
147 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
149 W_MachineGun_MuzzleFlash(actor, weaponentity);
150 W_AttachToShotorg(actor, weaponentity, actor.(weaponentity).muzzle_flash, '5 0 0');
152 if(autocvar_g_casings >= 2) // casing code
154 makevectors(actor.v_angle); // for some reason, this is lost
155 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);
158 int slot = weaponslot(weaponentity);
159 ATTACK_FINISHED(actor, slot) = time + WEP_CVAR(machinegun, first_refire) * W_WeaponRateFactor(actor);
160 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), W_MachineGun_Attack_Auto);
163 void W_MachineGun_Attack_Burst(Weapon thiswep, entity actor, .entity weaponentity, int fire)
165 W_SetupShot(actor, weaponentity, true, 0, SND_UZI_FIRE, CH_WEAPON_A, WEP_CVAR(machinegun, sustained_damage));
166 if(!autocvar_g_norecoil)
168 actor.punchangle_x = random() - 0.5;
169 actor.punchangle_y = random() - 0.5;
172 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);
174 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
176 W_MachineGun_MuzzleFlash(actor, weaponentity);
177 W_AttachToShotorg(actor, weaponentity, actor.(weaponentity).muzzle_flash, '5 0 0');
179 if(autocvar_g_casings >= 2) // casing code
181 makevectors(actor.v_angle); // for some reason, this is lost
182 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);
185 actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
186 if(actor.(weaponentity).misc_bulletcounter == 0)
188 int slot = weaponslot(weaponentity);
189 ATTACK_FINISHED(actor, slot) = time + WEP_CVAR(machinegun, burst_refire2) * W_WeaponRateFactor(actor);
190 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(machinegun, burst_animtime), w_ready);
194 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(machinegun, burst_refire), W_MachineGun_Attack_Burst);
199 METHOD(MachineGun, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
201 if(vdist(actor.origin - actor.enemy.origin, <, 3000 - bound(0, skill, 10) * 200))
202 PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
204 PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
206 METHOD(MachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
208 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
209 thiswep.wr_reload(thiswep, actor, weaponentity);
211 if(WEP_CVAR(machinegun, mode) == 1)
214 if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
216 actor.(weaponentity).misc_bulletcounter = 0;
217 W_MachineGun_Attack_Auto(thiswep, actor, weaponentity, fire);
221 if(weapon_prepareattack(thiswep, actor, weaponentity, true, 0))
223 if(!thiswep.wr_checkammo2(thiswep, actor, weaponentity))
224 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
226 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
227 w_ready(thiswep, actor, weaponentity, fire);
231 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(machinegun, burst_ammo), weaponentity);
233 actor.(weaponentity).misc_bulletcounter = WEP_CVAR(machinegun, burst) * -1;
234 W_MachineGun_Attack_Burst(thiswep, actor, weaponentity, fire);
241 if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
243 actor.(weaponentity).misc_bulletcounter = 1;
244 W_MachineGun_Attack(WEP_MACHINEGUN, WEP_MACHINEGUN.m_id, actor, weaponentity); // sets attack_finished
245 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), W_MachineGun_Attack_Frame);
248 if((fire & 2) && WEP_CVAR(machinegun, first))
249 if(weapon_prepareattack(thiswep, actor, weaponentity, true, 0))
251 actor.(weaponentity).misc_bulletcounter = 1;
252 W_MachineGun_Attack(WEP_MACHINEGUN, WEP_MACHINEGUN.m_id | HITTYPE_SECONDARY, actor, weaponentity); // sets attack_finished
253 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(machinegun, first_refire), w_ready);
257 METHOD(MachineGun, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
260 if(WEP_CVAR(machinegun, mode) == 1)
261 ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR(machinegun, sustained_ammo);
263 ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR(machinegun, first_ammo);
265 if(WEP_CVAR(machinegun, reload_ammo))
267 if(WEP_CVAR(machinegun, mode) == 1)
268 ammo_amount += actor.(weaponentity).(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, sustained_ammo);
270 ammo_amount += actor.(weaponentity).(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, first_ammo);
274 METHOD(MachineGun, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
277 if(WEP_CVAR(machinegun, mode) == 1)
278 ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR(machinegun, burst_ammo);
280 ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR(machinegun, first_ammo);
282 if(WEP_CVAR(machinegun, reload_ammo))
284 if(WEP_CVAR(machinegun, mode) == 1)
285 ammo_amount += actor.(weaponentity).(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, burst_ammo);
287 ammo_amount += actor.(weaponentity).(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, first_ammo);
291 METHOD(MachineGun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
293 W_Reload(actor, weaponentity, min(max(WEP_CVAR(machinegun, sustained_ammo), WEP_CVAR(machinegun, first_ammo)), WEP_CVAR(machinegun, burst_ammo)), SND_RELOAD);
295 METHOD(MachineGun, wr_suicidemessage, Notification(entity thiswep))
297 return WEAPON_THINKING_WITH_PORTALS;
299 METHOD(MachineGun, wr_killmessage, Notification(entity thiswep))
301 if(w_deathtype & HITTYPE_SECONDARY)
302 return WEAPON_MACHINEGUN_MURDER_SNIPE;
304 return WEAPON_MACHINEGUN_MURDER_SPRAY;
310 METHOD(MachineGun, wr_impacteffect, void(entity thiswep, entity actor))
313 org2 = w_org + w_backoff * 2;
314 pointparticles(EFFECT_MACHINEGUN_IMPACT, org2, w_backoff * 1000, 1);
316 sound(actor, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTN_NORM);