1 #include "machinegun.qh"
5 void W_MachineGun_MuzzleFlash_Think(entity this)
10 this.nextthink = time + 0.05;
14 setthink(this, SUB_Remove);
15 this.nextthink = time;
16 this.realowner.muzzle_flash = NULL;
22 void W_MachineGun_MuzzleFlash(entity actor, .entity weaponentity)
24 entity wepent = actor.(weaponentity);
26 if(wepent.muzzle_flash == NULL)
27 wepent.muzzle_flash = spawn();
29 // muzzle flash for 1st person view
30 setmodel(wepent.muzzle_flash, MDL_MACHINEGUN_MUZZLEFLASH); // precision set below
32 wepent.muzzle_flash.scale = 0.75;
33 setthink(wepent.muzzle_flash, W_MachineGun_MuzzleFlash_Think);
34 wepent.muzzle_flash.nextthink = time + 0.02;
35 wepent.muzzle_flash.frame = 2;
36 wepent.muzzle_flash.alpha = 0.75;
37 wepent.muzzle_flash.angles_z = random() * 180;
38 wepent.muzzle_flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
39 wepent.muzzle_flash.owner = wepent.muzzle_flash.realowner = wepent;
42 void W_MachineGun_Attack(Weapon thiswep, int deathtype, entity actor, .entity weaponentity)
44 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)), deathtype);
45 if(!autocvar_g_norecoil)
47 actor.punchangle_x = random() - 0.5;
48 actor.punchangle_y = random() - 0.5;
50 // this attack_finished just enforces a cooldown at the end of a burst
51 ATTACK_FINISHED(actor, weaponentity) = time + WEP_CVAR(machinegun, first_refire) * W_WeaponRateFactor(actor);
53 if(actor.(weaponentity).misc_bulletcounter == 1)
54 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, EFFECT_BULLET);
56 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, EFFECT_BULLET);
58 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
60 W_MachineGun_MuzzleFlash(actor, weaponentity);
61 W_AttachToShotorg(actor, weaponentity, actor.(weaponentity).muzzle_flash, '5 0 0');
64 if(autocvar_g_casings >= 2)
66 makevectors(actor.v_angle); // for some reason, this is lost
67 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);
70 if(actor.(weaponentity).misc_bulletcounter == 1)
71 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(machinegun, first_ammo), weaponentity);
73 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(machinegun, sustained_ammo), weaponentity);
77 void W_MachineGun_Attack_Frame(Weapon thiswep, entity actor, .entity weaponentity, int fire)
79 if(actor.(weaponentity).m_weapon != actor.(weaponentity).m_switchweapon || !weapon_prepareattack_check(thiswep, actor, weaponentity, (fire & 2), -1)) // abort immediately if switching
81 w_ready(thiswep, actor, weaponentity, fire);
84 if(PHYS_INPUT_BUTTON_ATCK(actor))
86 if(!thiswep.wr_checkammo2(thiswep, actor, weaponentity))
87 if(!(actor.items & IT_UNLIMITED_AMMO))
89 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
90 w_ready(thiswep, actor, weaponentity, fire);
93 actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
94 W_MachineGun_Attack(thiswep, thiswep.m_id, actor, weaponentity);
95 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), W_MachineGun_Attack_Frame);
98 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), w_ready);
102 void W_MachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity, int fire)
104 float machinegun_spread;
106 if(!(fire & 1) || !weapon_prepareattack_check(thiswep, actor, weaponentity, false, -1))
108 w_ready(thiswep, actor, weaponentity, fire);
112 if(!thiswep.wr_checkammo1(thiswep, actor, weaponentity))
113 if(!(actor.items & IT_UNLIMITED_AMMO))
115 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
116 w_ready(thiswep, actor, weaponentity, fire);
120 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(machinegun, sustained_ammo), weaponentity);
122 W_SetupShot(actor, weaponentity, true, 0, SND_UZI_FIRE, CH_WEAPON_A, WEP_CVAR(machinegun, sustained_damage), thiswep.m_id);
123 if(!autocvar_g_norecoil)
125 actor.punchangle_x = random() - 0.5;
126 actor.punchangle_y = random() - 0.5;
129 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));
130 fireBullet(actor, weaponentity, w_shotorg, w_shotdir, machinegun_spread, WEP_CVAR(machinegun, solidpenetration), WEP_CVAR(machinegun, sustained_damage), WEP_CVAR(machinegun, sustained_force), thiswep.m_id, EFFECT_BULLET);
132 actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
134 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
136 W_MachineGun_MuzzleFlash(actor, weaponentity);
137 W_AttachToShotorg(actor, weaponentity, actor.(weaponentity).muzzle_flash, '5 0 0');
139 if(autocvar_g_casings >= 2) // casing code
141 makevectors(actor.v_angle); // for some reason, this is lost
142 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);
145 ATTACK_FINISHED(actor, weaponentity) = time + WEP_CVAR(machinegun, first_refire) * W_WeaponRateFactor(actor);
146 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), W_MachineGun_Attack_Auto);
149 void W_MachineGun_Attack_Burst(Weapon thiswep, entity actor, .entity weaponentity, int fire)
151 W_SetupShot(actor, weaponentity, true, 0, SND_UZI_FIRE, CH_WEAPON_A, WEP_CVAR(machinegun, sustained_damage), thiswep.m_id);
152 if(!autocvar_g_norecoil)
154 actor.punchangle_x = random() - 0.5;
155 actor.punchangle_y = random() - 0.5;
158 fireBullet(actor, weaponentity, w_shotorg, w_shotdir, WEP_CVAR(machinegun, burst_spread), WEP_CVAR(machinegun, solidpenetration), WEP_CVAR(machinegun, sustained_damage), WEP_CVAR(machinegun, sustained_force), thiswep.m_id, EFFECT_BULLET);
160 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
162 W_MachineGun_MuzzleFlash(actor, weaponentity);
163 W_AttachToShotorg(actor, weaponentity, actor.(weaponentity).muzzle_flash, '5 0 0');
165 if(autocvar_g_casings >= 2) // casing code
167 makevectors(actor.v_angle); // for some reason, this is lost
168 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);
171 actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
172 if(actor.(weaponentity).misc_bulletcounter == 0)
174 ATTACK_FINISHED(actor, weaponentity) = time + WEP_CVAR(machinegun, burst_refire2) * W_WeaponRateFactor(actor);
175 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(machinegun, burst_animtime), w_ready);
179 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(machinegun, burst_refire), W_MachineGun_Attack_Burst);
184 METHOD(MachineGun, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
186 if(vdist(actor.origin - actor.enemy.origin, <, 3000 - bound(0, skill, 10) * 200))
187 PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
189 PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
191 METHOD(MachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
193 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
194 thiswep.wr_reload(thiswep, actor, weaponentity);
196 if(WEP_CVAR(machinegun, mode) == 1)
199 if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
201 actor.(weaponentity).misc_bulletcounter = 0;
202 W_MachineGun_Attack_Auto(thiswep, actor, weaponentity, fire);
206 if(weapon_prepareattack(thiswep, actor, weaponentity, true, 0))
208 if(!thiswep.wr_checkammo2(thiswep, actor, weaponentity))
209 if(!(actor.items & IT_UNLIMITED_AMMO))
211 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
212 w_ready(thiswep, actor, weaponentity, fire);
216 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(machinegun, burst_ammo), weaponentity);
218 actor.(weaponentity).misc_bulletcounter = WEP_CVAR(machinegun, burst) * -1;
219 W_MachineGun_Attack_Burst(thiswep, actor, weaponentity, fire);
226 if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
228 actor.(weaponentity).misc_bulletcounter = 1;
229 W_MachineGun_Attack(thiswep, thiswep.m_id, actor, weaponentity); // sets attack_finished
230 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), W_MachineGun_Attack_Frame);
233 if((fire & 2) && WEP_CVAR(machinegun, first))
234 if(weapon_prepareattack(thiswep, actor, weaponentity, true, 0))
236 actor.(weaponentity).misc_bulletcounter = 1;
237 W_MachineGun_Attack(thiswep, thiswep.m_id | HITTYPE_SECONDARY, actor, weaponentity); // sets attack_finished
238 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(machinegun, first_refire), w_ready);
242 METHOD(MachineGun, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
245 if(WEP_CVAR(machinegun, mode) == 1)
246 ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR(machinegun, sustained_ammo);
248 ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR(machinegun, first_ammo);
250 if(WEP_CVAR(machinegun, reload_ammo))
252 if(WEP_CVAR(machinegun, mode) == 1)
253 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR(machinegun, sustained_ammo);
255 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR(machinegun, first_ammo);
259 METHOD(MachineGun, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
262 if(WEP_CVAR(machinegun, mode) == 1)
263 ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR(machinegun, burst_ammo);
265 ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR(machinegun, first_ammo);
267 if(WEP_CVAR(machinegun, reload_ammo))
269 if(WEP_CVAR(machinegun, mode) == 1)
270 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR(machinegun, burst_ammo);
272 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR(machinegun, first_ammo);
276 METHOD(MachineGun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
278 W_Reload(actor, weaponentity, min(max(WEP_CVAR(machinegun, sustained_ammo), WEP_CVAR(machinegun, first_ammo)), WEP_CVAR(machinegun, burst_ammo)), SND_RELOAD);
280 METHOD(MachineGun, wr_suicidemessage, Notification(entity thiswep))
282 return WEAPON_THINKING_WITH_PORTALS;
284 METHOD(MachineGun, wr_killmessage, Notification(entity thiswep))
286 if(w_deathtype & HITTYPE_SECONDARY)
287 return WEAPON_MACHINEGUN_MURDER_SNIPE;
289 return WEAPON_MACHINEGUN_MURDER_SPRAY;
295 METHOD(MachineGun, wr_impacteffect, void(entity thiswep, entity actor))
298 org2 = w_org + w_backoff * 2;
299 pointparticles(EFFECT_MACHINEGUN_IMPACT, org2, w_backoff * 1000, 1);
301 sound(actor, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTN_NORM);