3 /* WEP_##id */ MACHINEGUN,
4 /* function */ W_MachineGun,
5 /* ammotype */ ammo_nails,
7 /* flags */ WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN,
8 /* rating */ BOT_PICKUP_RATING_MID,
10 /* modelname */ "uzi",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairuzi 0.6",
13 /* wepimg */ "weaponuzi",
14 /* refname */ "machinegun",
15 /* wepname */ _("Machine Gun")
18 #define MACHINEGUN_SETTINGS(w_cvar,w_prop) MACHINEGUN_SETTINGS_LIST(w_cvar, w_prop, MACHINEGUN, machinegun)
19 #define MACHINEGUN_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
20 w_cvar(id, sn, NONE, spread_min) \
21 w_cvar(id, sn, NONE, spread_max) \
22 w_cvar(id, sn, NONE, spread_add) \
23 w_cvar(id, sn, NONE, mode) \
24 w_cvar(id, sn, NONE, first) \
25 w_cvar(id, sn, NONE, first_damage) \
26 w_cvar(id, sn, NONE, first_force) \
27 w_cvar(id, sn, NONE, first_refire) \
28 w_cvar(id, sn, NONE, first_spread) \
29 w_cvar(id, sn, NONE, first_ammo) \
30 w_cvar(id, sn, NONE, solidpenetration) \
31 w_cvar(id, sn, NONE, sustained_damage) \
32 w_cvar(id, sn, NONE, sustained_force) \
33 w_cvar(id, sn, NONE, sustained_refire) \
34 w_cvar(id, sn, NONE, sustained_spread) \
35 w_cvar(id, sn, NONE, sustained_ammo) \
36 w_cvar(id, sn, NONE, burst) \
37 w_cvar(id, sn, NONE, burst_refire) \
38 w_cvar(id, sn, NONE, burst_refire2) \
39 w_cvar(id, sn, NONE, burst_animtime) \
40 w_cvar(id, sn, NONE, burst_speed) \
41 w_cvar(id, sn, NONE, burst_ammo) \
42 w_prop(id, sn, float, reloading_ammo, reload_ammo) \
43 w_prop(id, sn, float, reloading_time, reload_time) \
44 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
45 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
46 w_prop(id, sn, string, weaponreplace, weaponreplace) \
47 w_prop(id, sn, float, weaponstart, weaponstart) \
48 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
49 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
52 MACHINEGUN_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
58 void spawnfunc_weapon_machinegun(void)
60 if(autocvar_sv_q3acompat_machineshotgunswap)
61 if(self.classname != "droppedweapon")
63 weapon_defaultspawnfunc(WEP_SHOCKWAVE.m_id);
66 weapon_defaultspawnfunc(WEP_MACHINEGUN.m_id);
68 void spawnfunc_weapon_uzi(void) { spawnfunc_weapon_machinegun(); }
70 void W_MachineGun_MuzzleFlash_Think(void)
72 self.frame = self.frame + 2;
73 self.scale = self.scale * 0.5;
74 self.alpha = self.alpha - 0.25;
75 self.nextthink = time + 0.05;
79 self.think = SUB_Remove;
80 self.nextthink = time;
81 self.realowner.muzzle_flash = world;
87 void W_MachineGun_MuzzleFlash(void)
89 if(self.muzzle_flash == world)
90 self.muzzle_flash = spawn();
92 // muzzle flash for 1st person view
93 setmodel(self.muzzle_flash, "models/uziflash.md3"); // precision set below
95 self.muzzle_flash.scale = 0.75;
96 self.muzzle_flash.think = W_MachineGun_MuzzleFlash_Think;
97 self.muzzle_flash.nextthink = time + 0.02;
98 self.muzzle_flash.frame = 2;
99 self.muzzle_flash.alpha = 0.75;
100 self.muzzle_flash.angles_z = random() * 180;
101 self.muzzle_flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
102 self.muzzle_flash.owner = self.muzzle_flash.realowner = self;
105 void W_MachineGun_Attack(int deathtype)
107 W_SetupShot(self, true, 0, W_Sound("uzi_fire"), CH_WEAPON_A, ((self.misc_bulletcounter == 1) ? WEP_CVAR(machinegun, first_damage) : WEP_CVAR(machinegun, sustained_damage)));
108 if(!autocvar_g_norecoil)
110 self.punchangle_x = random() - 0.5;
111 self.punchangle_y = random() - 0.5;
114 // this attack_finished just enforces a cooldown at the end of a burst
115 ATTACK_FINISHED(self) = time + WEP_CVAR(machinegun, first_refire) * W_WeaponRateFactor();
117 if(self.misc_bulletcounter == 1)
118 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);
120 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);
122 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
124 W_MachineGun_MuzzleFlash();
125 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
128 if(autocvar_g_casings >= 2)
129 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);
131 if(self.misc_bulletcounter == 1)
132 W_DecreaseAmmo(WEP_CVAR(machinegun, first_ammo));
134 W_DecreaseAmmo(WEP_CVAR(machinegun, sustained_ammo));
138 void W_MachineGun_Attack_Frame(void)
140 if(self.weapon != self.switchweapon) // abort immediately if switching
147 if(!WEP_ACTION(self.weapon, WR_CHECKAMMO2))
148 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
150 W_SwitchWeapon_Force(self, w_getbestweapon(self));
154 self.misc_bulletcounter = self.misc_bulletcounter + 1;
155 W_MachineGun_Attack(WEP_MACHINEGUN.m_id);
156 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), W_MachineGun_Attack_Frame);
159 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), w_ready);
163 void W_MachineGun_Attack_Auto(void)
165 float machinegun_spread;
167 if(!self.BUTTON_ATCK)
173 if(!WEP_ACTION(self.weapon, WR_CHECKAMMO1))
174 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
176 W_SwitchWeapon_Force(self, w_getbestweapon(self));
181 W_DecreaseAmmo(WEP_CVAR(machinegun, sustained_ammo));
183 W_SetupShot(self, true, 0, W_Sound("uzi_fire"), CH_WEAPON_A, WEP_CVAR(machinegun, sustained_damage));
184 if(!autocvar_g_norecoil)
186 self.punchangle_x = random() - 0.5;
187 self.punchangle_y = random() - 0.5;
190 machinegun_spread = bound(WEP_CVAR(machinegun, spread_min), WEP_CVAR(machinegun, spread_min) + (WEP_CVAR(machinegun, spread_add) * self.misc_bulletcounter), WEP_CVAR(machinegun, spread_max));
191 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);
193 self.misc_bulletcounter = self.misc_bulletcounter + 1;
195 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
197 W_MachineGun_MuzzleFlash();
198 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
200 if(autocvar_g_casings >= 2) // casing code
201 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);
203 ATTACK_FINISHED(self) = time + WEP_CVAR(machinegun, first_refire) * W_WeaponRateFactor();
204 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), W_MachineGun_Attack_Auto);
207 void W_MachineGun_Attack_Burst(void)
209 W_SetupShot(self, true, 0, W_Sound("uzi_fire"), CH_WEAPON_A, WEP_CVAR(machinegun, sustained_damage));
210 if(!autocvar_g_norecoil)
212 self.punchangle_x = random() - 0.5;
213 self.punchangle_y = random() - 0.5;
216 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);
218 Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
220 W_MachineGun_MuzzleFlash();
221 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
223 if(autocvar_g_casings >= 2) // casing code
224 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);
226 self.misc_bulletcounter = self.misc_bulletcounter + 1;
227 if(self.misc_bulletcounter == 0)
229 ATTACK_FINISHED(self) = time + WEP_CVAR(machinegun, burst_refire2) * W_WeaponRateFactor();
230 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(machinegun, burst_animtime), w_ready);
234 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(machinegun, burst_refire), W_MachineGun_Attack_Burst);
239 bool W_MachineGun(int req)
246 if(vlen(self.origin-self.enemy.origin) < 3000 - bound(0, skill, 10) * 200)
247 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, false);
249 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, false);
255 if(WEP_CVAR(machinegun, reload_ammo) && self.clip_load < min(max(WEP_CVAR(machinegun, sustained_ammo), WEP_CVAR(machinegun, first_ammo)), WEP_CVAR(machinegun, burst_ammo))) // forced reload
256 WEP_ACTION(self.weapon, WR_RELOAD);
257 else if(WEP_CVAR(machinegun, mode) == 1)
260 if(weapon_prepareattack(0, 0))
262 self.misc_bulletcounter = 0;
263 W_MachineGun_Attack_Auto();
266 if(self.BUTTON_ATCK2)
267 if(weapon_prepareattack(1, 0))
269 if(!WEP_ACTION(self.weapon, WR_CHECKAMMO2))
270 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
272 W_SwitchWeapon_Force(self, w_getbestweapon(self));
277 W_DecreaseAmmo(WEP_CVAR(machinegun, burst_ammo));
279 self.misc_bulletcounter = WEP_CVAR(machinegun, burst) * -1;
280 W_MachineGun_Attack_Burst();
287 if(weapon_prepareattack(0, 0))
289 self.misc_bulletcounter = 1;
290 W_MachineGun_Attack(WEP_MACHINEGUN.m_id); // sets attack_finished
291 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), W_MachineGun_Attack_Frame);
294 if(self.BUTTON_ATCK2 && WEP_CVAR(machinegun, first))
295 if(weapon_prepareattack(1, 0))
297 self.misc_bulletcounter = 1;
298 W_MachineGun_Attack(WEP_MACHINEGUN.m_id | HITTYPE_SECONDARY); // sets attack_finished
299 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(machinegun, first_refire), w_ready);
307 precache_model("models/uziflash.md3");
308 precache_model(W_Model("g_uzi.md3"));
309 precache_model(W_Model("v_uzi.md3"));
310 precache_model(W_Model("h_uzi.iqm"));
311 precache_sound(W_Sound("uzi_fire"));
312 MACHINEGUN_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
317 if(WEP_CVAR(machinegun, mode) == 1)
318 ammo_amount = self.WEP_AMMO(MACHINEGUN) >= WEP_CVAR(machinegun, sustained_ammo);
320 ammo_amount = self.WEP_AMMO(MACHINEGUN) >= WEP_CVAR(machinegun, first_ammo);
322 if(WEP_CVAR(machinegun, reload_ammo))
324 if(WEP_CVAR(machinegun, mode) == 1)
325 ammo_amount += self.(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, sustained_ammo);
327 ammo_amount += self.(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, first_ammo);
333 if(WEP_CVAR(machinegun, mode) == 1)
334 ammo_amount = self.WEP_AMMO(MACHINEGUN) >= WEP_CVAR(machinegun, burst_ammo);
336 ammo_amount = self.WEP_AMMO(MACHINEGUN) >= WEP_CVAR(machinegun, first_ammo);
338 if(WEP_CVAR(machinegun, reload_ammo))
340 if(WEP_CVAR(machinegun, mode) == 1)
341 ammo_amount += self.(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, burst_ammo);
343 ammo_amount += self.(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, first_ammo);
349 MACHINEGUN_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
354 W_Reload(min(max(WEP_CVAR(machinegun, sustained_ammo), WEP_CVAR(machinegun, first_ammo)), WEP_CVAR(machinegun, burst_ammo)), W_Sound("reload"));
357 case WR_SUICIDEMESSAGE:
359 return WEAPON_THINKING_WITH_PORTALS;
363 if(w_deathtype & HITTYPE_SECONDARY)
364 return WEAPON_MACHINEGUN_MURDER_SNIPE;
366 return WEAPON_MACHINEGUN_MURDER_SPRAY;
373 bool W_MachineGun(int req)
377 case WR_IMPACTEFFECT:
380 org2 = w_org + w_backoff * 2;
381 pointparticles(particleeffectnum(EFFECT_MACHINEGUN_IMPACT), org2, w_backoff * 1000, 1);
384 sound(self, CH_SHOTS, W_Sound("ric1"), VOL_BASE, ATTN_NORM);
385 else if(w_random < 0.1)
386 sound(self, CH_SHOTS, W_Sound("ric2"), VOL_BASE, ATTN_NORM);
387 else if(w_random < 0.2)
388 sound(self, CH_SHOTS, W_Sound("ric3"), VOL_BASE, ATTN_NORM);
394 precache_sound(W_Sound("ric1"));
395 precache_sound(W_Sound("ric2"));
396 precache_sound(W_Sound("ric3"));
401 // no weapon specific image for this weapon