2 CLASS(MachineGun, Weapon)
3 /* ammotype */ ATTRIB(MachineGun, ammo_field, .int, ammo_nails)
4 /* impulse */ ATTRIB(MachineGun, impulse, int, 3)
5 /* flags */ ATTRIB(MachineGun, spawnflags, int, WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN);
6 /* rating */ ATTRIB(MachineGun, bot_pickupbasevalue, float, BOT_PICKUP_RATING_MID);
7 /* color */ ATTRIB(MachineGun, wpcolor, vector, '1 1 0');
8 /* modelname */ ATTRIB(MachineGun, mdl, string, "uzi");
10 /* model */ ATTRIB(MachineGun, m_model, Model, MDL_MACHINEGUN_ITEM);
12 /* crosshair */ ATTRIB(MachineGun, w_crosshair, string, "gfx/crosshairuzi");
13 /* crosshair */ ATTRIB(MachineGun, w_crosshair_size, float, 0.6);
14 /* wepimg */ ATTRIB(MachineGun, model2, string, "weaponuzi");
15 /* refname */ ATTRIB(MachineGun, netname, string, "machinegun");
16 /* wepname */ ATTRIB(MachineGun, m_name, string, _("MachineGun"));
18 REGISTER_WEAPON(MACHINEGUN, NEW(MachineGun));
20 #define MACHINEGUN_SETTINGS(w_cvar,w_prop) MACHINEGUN_SETTINGS_LIST(w_cvar, w_prop, MACHINEGUN, machinegun)
21 #define MACHINEGUN_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
22 w_cvar(id, sn, NONE, spread_min) \
23 w_cvar(id, sn, NONE, spread_max) \
24 w_cvar(id, sn, NONE, spread_add) \
25 w_cvar(id, sn, NONE, mode) \
26 w_cvar(id, sn, NONE, first) \
27 w_cvar(id, sn, NONE, first_damage) \
28 w_cvar(id, sn, NONE, first_force) \
29 w_cvar(id, sn, NONE, first_refire) \
30 w_cvar(id, sn, NONE, first_spread) \
31 w_cvar(id, sn, NONE, first_ammo) \
32 w_cvar(id, sn, NONE, solidpenetration) \
33 w_cvar(id, sn, NONE, sustained_damage) \
34 w_cvar(id, sn, NONE, sustained_force) \
35 w_cvar(id, sn, NONE, sustained_refire) \
36 w_cvar(id, sn, NONE, sustained_spread) \
37 w_cvar(id, sn, NONE, sustained_ammo) \
38 w_cvar(id, sn, NONE, burst) \
39 w_cvar(id, sn, NONE, burst_refire) \
40 w_cvar(id, sn, NONE, burst_refire2) \
41 w_cvar(id, sn, NONE, burst_animtime) \
42 w_cvar(id, sn, NONE, burst_speed) \
43 w_cvar(id, sn, NONE, burst_ammo) \
44 w_prop(id, sn, float, reloading_ammo, reload_ammo) \
45 w_prop(id, sn, float, reloading_time, reload_time) \
46 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
47 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
48 w_prop(id, sn, string, weaponreplace, weaponreplace) \
49 w_prop(id, sn, float, weaponstart, weaponstart) \
50 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
51 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
54 MACHINEGUN_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
60 spawnfunc(weapon_machinegun)
62 if(autocvar_sv_q3acompat_machineshotgunswap)
63 if(self.classname != "droppedweapon")
65 weapon_defaultspawnfunc(this, WEP_SHOCKWAVE);
68 weapon_defaultspawnfunc(this, WEP_MACHINEGUN);
70 spawnfunc(weapon_uzi) { spawnfunc_weapon_machinegun(this); }
72 void W_MachineGun_MuzzleFlash_Think(void)
74 self.frame = self.frame + 2;
75 self.scale = self.scale * 0.5;
76 self.alpha = self.alpha - 0.25;
77 self.nextthink = time + 0.05;
81 self.think = SUB_Remove;
82 self.nextthink = time;
83 self.realowner.muzzle_flash = world;
89 void W_MachineGun_MuzzleFlash(void)
91 if(self.muzzle_flash == world)
92 self.muzzle_flash = spawn();
94 // muzzle flash for 1st person view
95 setmodel(self.muzzle_flash, MDL_MACHINEGUN_MUZZLEFLASH); // precision set below
97 self.muzzle_flash.scale = 0.75;
98 self.muzzle_flash.think = W_MachineGun_MuzzleFlash_Think;
99 self.muzzle_flash.nextthink = time + 0.02;
100 self.muzzle_flash.frame = 2;
101 self.muzzle_flash.alpha = 0.75;
102 self.muzzle_flash.angles_z = random() * 180;
103 self.muzzle_flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
104 self.muzzle_flash.owner = self.muzzle_flash.realowner = self;
107 void W_MachineGun_Attack(Weapon thiswep, int deathtype, .entity weaponentity)
109 W_SetupShot(self, true, 0, SND(UZI_FIRE), CH_WEAPON_A, ((self.misc_bulletcounter == 1) ? WEP_CVAR(machinegun, first_damage) : WEP_CVAR(machinegun, sustained_damage)));
110 if(!autocvar_g_norecoil)
112 self.punchangle_x = random() - 0.5;
113 self.punchangle_y = random() - 0.5;
115 int slot = weaponslot(weaponentity);
116 // this attack_finished just enforces a cooldown at the end of a burst
117 ATTACK_FINISHED(self, slot) = time + WEP_CVAR(machinegun, first_refire) * W_WeaponRateFactor();
119 if(self.misc_bulletcounter == 1)
120 fireBullet(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);
122 fireBullet(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);
124 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
126 W_MachineGun_MuzzleFlash();
127 W_AttachToShotorg(self, self.muzzle_flash, '5 0 0');
130 if(autocvar_g_casings >= 2)
131 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, self);
133 if(self.misc_bulletcounter == 1)
134 W_DecreaseAmmo(thiswep, self, WEP_CVAR(machinegun, first_ammo));
136 W_DecreaseAmmo(thiswep, self, WEP_CVAR(machinegun, sustained_ammo));
140 void W_MachineGun_Attack_Frame(Weapon thiswep, entity actor, .entity weaponentity, int fire)
142 if(actor.weapon != actor.switchweapon) // abort immediately if switching
144 w_ready(thiswep, actor, weaponentity, fire);
147 if(actor.BUTTON_ATCK)
149 Weapon w = get_weaponinfo(actor.weapon);
150 if(!w.wr_checkammo2(w))
151 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
153 W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
154 w_ready(thiswep, actor, weaponentity, fire);
157 actor.misc_bulletcounter = actor.misc_bulletcounter + 1;
158 W_MachineGun_Attack(WEP_MACHINEGUN, WEP_MACHINEGUN.m_id, weaponentity);
159 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), W_MachineGun_Attack_Frame);
162 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), w_ready);
166 void W_MachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity, int fire)
168 float machinegun_spread;
172 w_ready(thiswep, actor, weaponentity, fire);
176 Weapon w = get_weaponinfo(actor.weapon);
177 if(!w.wr_checkammo1(w))
178 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
180 W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
181 w_ready(thiswep, actor, weaponentity, fire);
185 W_DecreaseAmmo(WEP_MACHINEGUN, actor, WEP_CVAR(machinegun, sustained_ammo));
187 W_SetupShot(actor, true, 0, SND(UZI_FIRE), CH_WEAPON_A, WEP_CVAR(machinegun, sustained_damage));
188 if(!autocvar_g_norecoil)
190 actor.punchangle_x = random() - 0.5;
191 actor.punchangle_y = random() - 0.5;
194 machinegun_spread = bound(WEP_CVAR(machinegun, spread_min), WEP_CVAR(machinegun, spread_min) + (WEP_CVAR(machinegun, spread_add) * actor.misc_bulletcounter), WEP_CVAR(machinegun, spread_max));
195 fireBullet(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);
197 actor.misc_bulletcounter = actor.misc_bulletcounter + 1;
199 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
201 W_MachineGun_MuzzleFlash();
202 W_AttachToShotorg(actor, actor.muzzle_flash, '5 0 0');
204 if(autocvar_g_casings >= 2) // casing code
205 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);
207 int slot = weaponslot(weaponentity);
208 ATTACK_FINISHED(actor, slot) = time + WEP_CVAR(machinegun, first_refire) * W_WeaponRateFactor();
209 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), W_MachineGun_Attack_Auto);
212 void W_MachineGun_Attack_Burst(Weapon thiswep, entity actor, .entity weaponentity, int fire)
214 W_SetupShot(actor, true, 0, SND(UZI_FIRE), CH_WEAPON_A, WEP_CVAR(machinegun, sustained_damage));
215 if(!autocvar_g_norecoil)
217 actor.punchangle_x = random() - 0.5;
218 actor.punchangle_y = random() - 0.5;
221 fireBullet(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);
223 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
225 W_MachineGun_MuzzleFlash();
226 W_AttachToShotorg(actor, actor.muzzle_flash, '5 0 0');
228 if(autocvar_g_casings >= 2) // casing code
229 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);
231 actor.misc_bulletcounter = actor.misc_bulletcounter + 1;
232 if(actor.misc_bulletcounter == 0)
234 int slot = weaponslot(weaponentity);
235 ATTACK_FINISHED(actor, slot) = time + WEP_CVAR(machinegun, burst_refire2) * W_WeaponRateFactor();
236 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(machinegun, burst_animtime), w_ready);
240 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(machinegun, burst_refire), W_MachineGun_Attack_Burst);
245 METHOD(MachineGun, wr_aim, void(entity thiswep))
247 if(vlen(self.origin-self.enemy.origin) < 3000 - bound(0, skill, 10) * 200)
248 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, false);
250 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, false);
252 METHOD(MachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
254 if(WEP_CVAR(machinegun, reload_ammo) && actor.clip_load < min(max(WEP_CVAR(machinegun, sustained_ammo), WEP_CVAR(machinegun, first_ammo)), WEP_CVAR(machinegun, burst_ammo))) { // forced reload
255 Weapon w = get_weaponinfo(actor.weapon);
258 if(WEP_CVAR(machinegun, mode) == 1)
261 if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
263 actor.misc_bulletcounter = 0;
264 W_MachineGun_Attack_Auto(thiswep, actor, weaponentity, fire);
268 if(weapon_prepareattack(thiswep, actor, weaponentity, true, 0))
270 Weapon w = get_weaponinfo(actor.weapon);
271 if(!w.wr_checkammo2(w))
272 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
274 W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
275 w_ready(thiswep, actor, weaponentity, fire);
279 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(machinegun, burst_ammo));
281 actor.misc_bulletcounter = WEP_CVAR(machinegun, burst) * -1;
282 W_MachineGun_Attack_Burst(thiswep, actor, weaponentity, fire);
289 if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
291 actor.misc_bulletcounter = 1;
292 W_MachineGun_Attack(WEP_MACHINEGUN, WEP_MACHINEGUN.m_id, weaponentity); // sets attack_finished
293 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), W_MachineGun_Attack_Frame);
296 if((fire & 2) && WEP_CVAR(machinegun, first))
297 if(weapon_prepareattack(thiswep, actor, weaponentity, true, 0))
299 actor.misc_bulletcounter = 1;
300 W_MachineGun_Attack(WEP_MACHINEGUN, WEP_MACHINEGUN.m_id | HITTYPE_SECONDARY, weaponentity); // sets attack_finished
301 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(machinegun, first_refire), w_ready);
305 METHOD(MachineGun, wr_init, void(entity thiswep))
307 MACHINEGUN_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
309 METHOD(MachineGun, wr_checkammo1, bool(entity thiswep))
312 if(WEP_CVAR(machinegun, mode) == 1)
313 ammo_amount = self.WEP_AMMO(MACHINEGUN) >= WEP_CVAR(machinegun, sustained_ammo);
315 ammo_amount = self.WEP_AMMO(MACHINEGUN) >= WEP_CVAR(machinegun, first_ammo);
317 if(WEP_CVAR(machinegun, reload_ammo))
319 if(WEP_CVAR(machinegun, mode) == 1)
320 ammo_amount += self.(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, sustained_ammo);
322 ammo_amount += self.(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, first_ammo);
326 METHOD(MachineGun, wr_checkammo2, bool(entity thiswep))
329 if(WEP_CVAR(machinegun, mode) == 1)
330 ammo_amount = self.WEP_AMMO(MACHINEGUN) >= WEP_CVAR(machinegun, burst_ammo);
332 ammo_amount = self.WEP_AMMO(MACHINEGUN) >= WEP_CVAR(machinegun, first_ammo);
334 if(WEP_CVAR(machinegun, reload_ammo))
336 if(WEP_CVAR(machinegun, mode) == 1)
337 ammo_amount += self.(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, burst_ammo);
339 ammo_amount += self.(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, first_ammo);
343 METHOD(MachineGun, wr_config, void(entity thiswep))
345 MACHINEGUN_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
347 METHOD(MachineGun, wr_reload, void(entity thiswep))
349 W_Reload(self, min(max(WEP_CVAR(machinegun, sustained_ammo), WEP_CVAR(machinegun, first_ammo)), WEP_CVAR(machinegun, burst_ammo)), SND(RELOAD));
351 METHOD(MachineGun, wr_suicidemessage, int(entity thiswep))
353 return WEAPON_THINKING_WITH_PORTALS;
355 METHOD(MachineGun, wr_killmessage, int(entity thiswep))
357 if(w_deathtype & HITTYPE_SECONDARY)
358 return WEAPON_MACHINEGUN_MURDER_SNIPE;
360 return WEAPON_MACHINEGUN_MURDER_SPRAY;
366 METHOD(MachineGun, wr_impacteffect, void(entity thiswep))
369 org2 = w_org + w_backoff * 2;
370 pointparticles(EFFECT_MACHINEGUN_IMPACT, org2, w_backoff * 1000, 1);
372 sound(self, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTN_NORM);