]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/machinegun.qc
Use the sound list
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / machinegun.qc
1 #ifndef IMPLEMENTATION
2 REGISTER_WEAPON(
3 /* WEP_##id  */ MACHINEGUN,
4 /* function  */ W_MachineGun,
5 /* ammotype  */ ammo_nails,
6 /* impulse   */ 3,
7 /* flags     */ WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN,
8 /* rating    */ BOT_PICKUP_RATING_MID,
9 /* color     */ '1 1 0',
10 /* modelname */ "uzi",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairuzi 0.6",
13 /* wepimg    */ "weaponuzi",
14 /* refname   */ "machinegun",
15 /* wepname   */ _("Machine Gun")
16 );
17
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)
50
51 #ifdef SVQC
52 MACHINEGUN_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
53 #endif
54 #endif
55 #ifdef IMPLEMENTATION
56 #ifdef SVQC
57
58 void spawnfunc_weapon_machinegun(void)
59 {SELFPARAM();
60         if(autocvar_sv_q3acompat_machineshotgunswap)
61         if(self.classname != "droppedweapon")
62         {
63                 weapon_defaultspawnfunc(WEP_SHOCKWAVE.m_id);
64                 return;
65         }
66         weapon_defaultspawnfunc(WEP_MACHINEGUN.m_id);
67 }
68 void spawnfunc_weapon_uzi(void) { spawnfunc_weapon_machinegun(); }
69
70 void W_MachineGun_MuzzleFlash_Think(void)
71 {SELFPARAM();
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;
76
77         if(self.alpha <= 0)
78         {
79                 self.think = SUB_Remove;
80                 self.nextthink = time;
81                 self.realowner.muzzle_flash = world;
82                 return;
83         }
84
85 }
86
87 void W_MachineGun_MuzzleFlash(void)
88 {SELFPARAM();
89         if(self.muzzle_flash == world)
90                 self.muzzle_flash = spawn();
91
92         // muzzle flash for 1st person view
93         setmodel(self.muzzle_flash, MDL_MACHINEGUN_MUZZLEFLASH); // precision set below
94
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;
103 }
104
105 void W_MachineGun_Attack(int deathtype)
106 {SELFPARAM();
107         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)));
108         if(!autocvar_g_norecoil)
109         {
110                 self.punchangle_x = random() - 0.5;
111                 self.punchangle_y = random() - 0.5;
112         }
113
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();
116
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);
119         else
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);
121
122         Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
123
124         W_MachineGun_MuzzleFlash();
125         W_AttachToShotorg(self.muzzle_flash, '5 0 0');
126
127         // casing code
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);
130
131         if(self.misc_bulletcounter == 1)
132                 W_DecreaseAmmo(WEP_CVAR(machinegun, first_ammo));
133         else
134                 W_DecreaseAmmo(WEP_CVAR(machinegun, sustained_ammo));
135 }
136
137 // weapon frames
138 void W_MachineGun_Attack_Frame(void)
139 {SELFPARAM();
140         if(self.weapon != self.switchweapon) // abort immediately if switching
141         {
142                 w_ready();
143                 return;
144         }
145         if(self.BUTTON_ATCK)
146         {
147                 if(!WEP_ACTION(self.weapon, WR_CHECKAMMO2))
148                 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
149                 {
150                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
151                         w_ready();
152                         return;
153                 }
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);
157         }
158         else
159                 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), w_ready);
160 }
161
162
163 void W_MachineGun_Attack_Auto(void)
164 {SELFPARAM();
165         float machinegun_spread;
166
167         if(!self.BUTTON_ATCK)
168         {
169                 w_ready();
170                 return;
171         }
172
173         if(!WEP_ACTION(self.weapon, WR_CHECKAMMO1))
174         if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
175         {
176                 W_SwitchWeapon_Force(self, w_getbestweapon(self));
177                 w_ready();
178                 return;
179         }
180
181         W_DecreaseAmmo(WEP_CVAR(machinegun, sustained_ammo));
182
183         W_SetupShot(self, true, 0, SND(UZI_FIRE), CH_WEAPON_A, WEP_CVAR(machinegun, sustained_damage));
184         if(!autocvar_g_norecoil)
185         {
186                 self.punchangle_x = random() - 0.5;
187                 self.punchangle_y = random() - 0.5;
188         }
189
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);
192
193         self.misc_bulletcounter = self.misc_bulletcounter + 1;
194
195         Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
196
197         W_MachineGun_MuzzleFlash();
198         W_AttachToShotorg(self.muzzle_flash, '5 0 0');
199
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);
202
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);
205 }
206
207 void W_MachineGun_Attack_Burst(void)
208 {SELFPARAM();
209         W_SetupShot(self, true, 0, SND(UZI_FIRE), CH_WEAPON_A, WEP_CVAR(machinegun, sustained_damage));
210         if(!autocvar_g_norecoil)
211         {
212                 self.punchangle_x = random() - 0.5;
213                 self.punchangle_y = random() - 0.5;
214         }
215
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);
217
218         Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
219
220         W_MachineGun_MuzzleFlash();
221         W_AttachToShotorg(self.muzzle_flash, '5 0 0');
222
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);
225
226         self.misc_bulletcounter = self.misc_bulletcounter + 1;
227         if(self.misc_bulletcounter == 0)
228         {
229                 ATTACK_FINISHED(self) = time + WEP_CVAR(machinegun, burst_refire2) * W_WeaponRateFactor();
230                 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(machinegun, burst_animtime), w_ready);
231         }
232         else
233         {
234                 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(machinegun, burst_refire), W_MachineGun_Attack_Burst);
235         }
236
237 }
238
239 bool W_MachineGun(int req)
240 {SELFPARAM();
241         float ammo_amount;
242         switch(req)
243         {
244                 case WR_AIM:
245                 {
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);
248                         else
249                                 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, false);
250
251                         return true;
252                 }
253                 case WR_THINK:
254                 {
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)
258                         {
259                                 if(self.BUTTON_ATCK)
260                                 if(weapon_prepareattack(0, 0))
261                                 {
262                                         self.misc_bulletcounter = 0;
263                                         W_MachineGun_Attack_Auto();
264                                 }
265
266                                 if(self.BUTTON_ATCK2)
267                                 if(weapon_prepareattack(1, 0))
268                                 {
269                                         if(!WEP_ACTION(self.weapon, WR_CHECKAMMO2))
270                                         if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
271                                         {
272                                                 W_SwitchWeapon_Force(self, w_getbestweapon(self));
273                                                 w_ready();
274                                                 return false;
275                                         }
276
277                                         W_DecreaseAmmo(WEP_CVAR(machinegun, burst_ammo));
278
279                                         self.misc_bulletcounter = WEP_CVAR(machinegun, burst) * -1;
280                                         W_MachineGun_Attack_Burst();
281                                 }
282                         }
283                         else
284                         {
285
286                                 if(self.BUTTON_ATCK)
287                                 if(weapon_prepareattack(0, 0))
288                                 {
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);
292                                 }
293
294                                 if(self.BUTTON_ATCK2 && WEP_CVAR(machinegun, first))
295                                 if(weapon_prepareattack(1, 0))
296                                 {
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);
300                                 }
301                         }
302
303                         return true;
304                 }
305                 case WR_INIT:
306                 {
307                         MACHINEGUN_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
308                         return true;
309                 }
310                 case WR_CHECKAMMO1:
311                 {
312                         if(WEP_CVAR(machinegun, mode) == 1)
313                                 ammo_amount = self.WEP_AMMO(MACHINEGUN) >= WEP_CVAR(machinegun, sustained_ammo);
314                         else
315                                 ammo_amount = self.WEP_AMMO(MACHINEGUN) >= WEP_CVAR(machinegun, first_ammo);
316
317                         if(WEP_CVAR(machinegun, reload_ammo))
318                         {
319                                 if(WEP_CVAR(machinegun, mode) == 1)
320                                         ammo_amount += self.(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, sustained_ammo);
321                                 else
322                                         ammo_amount += self.(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, first_ammo);
323                         }
324                         return ammo_amount;
325                 }
326                 case WR_CHECKAMMO2:
327                 {
328                         if(WEP_CVAR(machinegun, mode) == 1)
329                                 ammo_amount = self.WEP_AMMO(MACHINEGUN) >= WEP_CVAR(machinegun, burst_ammo);
330                         else
331                                 ammo_amount = self.WEP_AMMO(MACHINEGUN) >= WEP_CVAR(machinegun, first_ammo);
332
333                         if(WEP_CVAR(machinegun, reload_ammo))
334                         {
335                                 if(WEP_CVAR(machinegun, mode) == 1)
336                                         ammo_amount += self.(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, burst_ammo);
337                                 else
338                                         ammo_amount += self.(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, first_ammo);
339                         }
340                         return ammo_amount;
341                 }
342                 case WR_CONFIG:
343                 {
344                         MACHINEGUN_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
345                         return true;
346                 }
347                 case WR_RELOAD:
348                 {
349                         W_Reload(min(max(WEP_CVAR(machinegun, sustained_ammo), WEP_CVAR(machinegun, first_ammo)), WEP_CVAR(machinegun, burst_ammo)), SND(RELOAD));
350                         return true;
351                 }
352                 case WR_SUICIDEMESSAGE:
353                 {
354                         return WEAPON_THINKING_WITH_PORTALS;
355                 }
356                 case WR_KILLMESSAGE:
357                 {
358                         if(w_deathtype & HITTYPE_SECONDARY)
359                                 return WEAPON_MACHINEGUN_MURDER_SNIPE;
360                         else
361                                 return WEAPON_MACHINEGUN_MURDER_SPRAY;
362                 }
363         }
364         return false;
365 }
366 #endif
367 #ifdef CSQC
368 bool W_MachineGun(int req)
369 {SELFPARAM();
370         switch(req)
371         {
372                 case WR_IMPACTEFFECT:
373                 {
374                         vector org2;
375                         org2 = w_org + w_backoff * 2;
376                         pointparticles(particleeffectnum(EFFECT_MACHINEGUN_IMPACT), org2, w_backoff * 1000, 1);
377                         if(!w_issilent)
378                                 if(w_random < 0.05)
379                                         sound(self, CH_SHOTS, SND_RIC1, VOL_BASE, ATTN_NORM);
380                                 else if(w_random < 0.1)
381                                         sound(self, CH_SHOTS, SND_RIC2, VOL_BASE, ATTN_NORM);
382                                 else if(w_random < 0.2)
383                                         sound(self, CH_SHOTS, SND_RIC3, VOL_BASE, ATTN_NORM);
384
385                         return true;
386                 }
387                 case WR_INIT:
388                 {
389                         return true;
390                 }
391                 case WR_ZOOMRETICLE:
392                 {
393                         // no weapon specific image for this weapon
394                         return false;
395                 }
396         }
397         return false;
398 }
399 #endif
400 #endif