]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/machinegun.qc
Weapons: require explicit pickup model
[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 /* model     */ MDL_MACHINEGUN_ITEM,
12 /* simplemdl */ "foobar",
13 /* crosshair */ "gfx/crosshairuzi 0.6",
14 /* wepimg    */ "weaponuzi",
15 /* refname   */ "machinegun",
16 /* wepname   */ _("Machine Gun")
17 );
18
19 #define MACHINEGUN_SETTINGS(w_cvar,w_prop) MACHINEGUN_SETTINGS_LIST(w_cvar, w_prop, MACHINEGUN, machinegun)
20 #define MACHINEGUN_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
21         w_cvar(id, sn, NONE, spread_min) \
22         w_cvar(id, sn, NONE, spread_max) \
23         w_cvar(id, sn, NONE, spread_add) \
24         w_cvar(id, sn, NONE, mode) \
25         w_cvar(id, sn, NONE, first) \
26         w_cvar(id, sn, NONE, first_damage) \
27         w_cvar(id, sn, NONE, first_force) \
28         w_cvar(id, sn, NONE, first_refire) \
29         w_cvar(id, sn, NONE, first_spread) \
30         w_cvar(id, sn, NONE, first_ammo) \
31         w_cvar(id, sn, NONE, solidpenetration) \
32         w_cvar(id, sn, NONE, sustained_damage) \
33         w_cvar(id, sn, NONE, sustained_force) \
34         w_cvar(id, sn, NONE, sustained_refire) \
35         w_cvar(id, sn, NONE, sustained_spread) \
36         w_cvar(id, sn, NONE, sustained_ammo) \
37         w_cvar(id, sn, NONE, burst) \
38         w_cvar(id, sn, NONE, burst_refire) \
39         w_cvar(id, sn, NONE, burst_refire2) \
40         w_cvar(id, sn, NONE, burst_animtime) \
41         w_cvar(id, sn, NONE, burst_speed) \
42         w_cvar(id, sn, NONE, burst_ammo) \
43         w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
44         w_prop(id, sn, float,  reloading_time, reload_time) \
45         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
46         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
47         w_prop(id, sn, string, weaponreplace, weaponreplace) \
48         w_prop(id, sn, float,  weaponstart, weaponstart) \
49         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
50         w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
51
52 #ifdef SVQC
53 MACHINEGUN_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
54 #endif
55 #endif
56 #ifdef IMPLEMENTATION
57 #ifdef SVQC
58
59 void spawnfunc_weapon_machinegun(void)
60 {SELFPARAM();
61         if(autocvar_sv_q3acompat_machineshotgunswap)
62         if(self.classname != "droppedweapon")
63         {
64                 weapon_defaultspawnfunc(WEP_SHOCKWAVE.m_id);
65                 return;
66         }
67         weapon_defaultspawnfunc(WEP_MACHINEGUN.m_id);
68 }
69 void spawnfunc_weapon_uzi(void) { spawnfunc_weapon_machinegun(); }
70
71 void W_MachineGun_MuzzleFlash_Think(void)
72 {SELFPARAM();
73         self.frame = self.frame + 2;
74         self.scale = self.scale * 0.5;
75         self.alpha = self.alpha - 0.25;
76         self.nextthink = time + 0.05;
77
78         if(self.alpha <= 0)
79         {
80                 self.think = SUB_Remove;
81                 self.nextthink = time;
82                 self.realowner.muzzle_flash = world;
83                 return;
84         }
85
86 }
87
88 void W_MachineGun_MuzzleFlash(void)
89 {SELFPARAM();
90         if(self.muzzle_flash == world)
91                 self.muzzle_flash = spawn();
92
93         // muzzle flash for 1st person view
94         setmodel(self.muzzle_flash, MDL_MACHINEGUN_MUZZLEFLASH); // precision set below
95
96         self.muzzle_flash.scale = 0.75;
97         self.muzzle_flash.think = W_MachineGun_MuzzleFlash_Think;
98         self.muzzle_flash.nextthink = time + 0.02;
99         self.muzzle_flash.frame = 2;
100         self.muzzle_flash.alpha = 0.75;
101         self.muzzle_flash.angles_z = random() * 180;
102         self.muzzle_flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
103         self.muzzle_flash.owner = self.muzzle_flash.realowner = self;
104 }
105
106 void W_MachineGun_Attack(int deathtype)
107 {SELFPARAM();
108         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)));
109         if(!autocvar_g_norecoil)
110         {
111                 self.punchangle_x = random() - 0.5;
112                 self.punchangle_y = random() - 0.5;
113         }
114
115         // this attack_finished just enforces a cooldown at the end of a burst
116         ATTACK_FINISHED(self) = time + WEP_CVAR(machinegun, first_refire) * W_WeaponRateFactor();
117
118         if(self.misc_bulletcounter == 1)
119                 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         else
121                 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
123         Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
124
125         W_MachineGun_MuzzleFlash();
126         W_AttachToShotorg(self.muzzle_flash, '5 0 0');
127
128         // casing code
129         if(autocvar_g_casings >= 2)
130                 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
132         if(self.misc_bulletcounter == 1)
133                 W_DecreaseAmmo(WEP_CVAR(machinegun, first_ammo));
134         else
135                 W_DecreaseAmmo(WEP_CVAR(machinegun, sustained_ammo));
136 }
137
138 // weapon frames
139 void W_MachineGun_Attack_Frame(void)
140 {SELFPARAM();
141         if(self.weapon != self.switchweapon) // abort immediately if switching
142         {
143                 w_ready();
144                 return;
145         }
146         if(self.BUTTON_ATCK)
147         {
148                 if(!_WEP_ACTION(self.weapon, WR_CHECKAMMO2))
149                 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
150                 {
151                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
152                         w_ready();
153                         return;
154                 }
155                 self.misc_bulletcounter = self.misc_bulletcounter + 1;
156                 W_MachineGun_Attack(WEP_MACHINEGUN.m_id);
157                 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), W_MachineGun_Attack_Frame);
158         }
159         else
160                 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), w_ready);
161 }
162
163
164 void W_MachineGun_Attack_Auto(void)
165 {SELFPARAM();
166         float machinegun_spread;
167
168         if(!self.BUTTON_ATCK)
169         {
170                 w_ready();
171                 return;
172         }
173
174         if(!_WEP_ACTION(self.weapon, WR_CHECKAMMO1))
175         if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
176         {
177                 W_SwitchWeapon_Force(self, w_getbestweapon(self));
178                 w_ready();
179                 return;
180         }
181
182         W_DecreaseAmmo(WEP_CVAR(machinegun, sustained_ammo));
183
184         W_SetupShot(self, true, 0, SND(UZI_FIRE), CH_WEAPON_A, WEP_CVAR(machinegun, sustained_damage));
185         if(!autocvar_g_norecoil)
186         {
187                 self.punchangle_x = random() - 0.5;
188                 self.punchangle_y = random() - 0.5;
189         }
190
191         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));
192         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
194         self.misc_bulletcounter = self.misc_bulletcounter + 1;
195
196         Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
197
198         W_MachineGun_MuzzleFlash();
199         W_AttachToShotorg(self.muzzle_flash, '5 0 0');
200
201         if(autocvar_g_casings >= 2) // casing code
202                 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
204         ATTACK_FINISHED(self) = time + WEP_CVAR(machinegun, first_refire) * W_WeaponRateFactor();
205         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), W_MachineGun_Attack_Auto);
206 }
207
208 void W_MachineGun_Attack_Burst(void)
209 {SELFPARAM();
210         W_SetupShot(self, true, 0, SND(UZI_FIRE), CH_WEAPON_A, WEP_CVAR(machinegun, sustained_damage));
211         if(!autocvar_g_norecoil)
212         {
213                 self.punchangle_x = random() - 0.5;
214                 self.punchangle_y = random() - 0.5;
215         }
216
217         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
219         Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
220
221         W_MachineGun_MuzzleFlash();
222         W_AttachToShotorg(self.muzzle_flash, '5 0 0');
223
224         if(autocvar_g_casings >= 2) // casing code
225                 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
227         self.misc_bulletcounter = self.misc_bulletcounter + 1;
228         if(self.misc_bulletcounter == 0)
229         {
230                 ATTACK_FINISHED(self) = time + WEP_CVAR(machinegun, burst_refire2) * W_WeaponRateFactor();
231                 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(machinegun, burst_animtime), w_ready);
232         }
233         else
234         {
235                 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(machinegun, burst_refire), W_MachineGun_Attack_Burst);
236         }
237
238 }
239
240 bool W_MachineGun(entity thiswep, int req)
241 {SELFPARAM();
242         float ammo_amount;
243         switch(req)
244         {
245                 case WR_AIM:
246                 {
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);
249                         else
250                                 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, false);
251
252                         return true;
253                 }
254                 case WR_THINK:
255                 {
256                         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
257                                 _WEP_ACTION(self.weapon, WR_RELOAD);
258                         else if(WEP_CVAR(machinegun, mode) == 1)
259                         {
260                                 if(self.BUTTON_ATCK)
261                                 if(weapon_prepareattack(0, 0))
262                                 {
263                                         self.misc_bulletcounter = 0;
264                                         W_MachineGun_Attack_Auto();
265                                 }
266
267                                 if(self.BUTTON_ATCK2)
268                                 if(weapon_prepareattack(1, 0))
269                                 {
270                                         if(!_WEP_ACTION(self.weapon, WR_CHECKAMMO2))
271                                         if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
272                                         {
273                                                 W_SwitchWeapon_Force(self, w_getbestweapon(self));
274                                                 w_ready();
275                                                 return false;
276                                         }
277
278                                         W_DecreaseAmmo(WEP_CVAR(machinegun, burst_ammo));
279
280                                         self.misc_bulletcounter = WEP_CVAR(machinegun, burst) * -1;
281                                         W_MachineGun_Attack_Burst();
282                                 }
283                         }
284                         else
285                         {
286
287                                 if(self.BUTTON_ATCK)
288                                 if(weapon_prepareattack(0, 0))
289                                 {
290                                         self.misc_bulletcounter = 1;
291                                         W_MachineGun_Attack(WEP_MACHINEGUN.m_id); // sets attack_finished
292                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(machinegun, sustained_refire), W_MachineGun_Attack_Frame);
293                                 }
294
295                                 if(self.BUTTON_ATCK2 && WEP_CVAR(machinegun, first))
296                                 if(weapon_prepareattack(1, 0))
297                                 {
298                                         self.misc_bulletcounter = 1;
299                                         W_MachineGun_Attack(WEP_MACHINEGUN.m_id | HITTYPE_SECONDARY); // sets attack_finished
300                                         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(machinegun, first_refire), w_ready);
301                                 }
302                         }
303
304                         return true;
305                 }
306                 case WR_INIT:
307                 {
308                         MACHINEGUN_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
309                         return true;
310                 }
311                 case WR_CHECKAMMO1:
312                 {
313                         if(WEP_CVAR(machinegun, mode) == 1)
314                                 ammo_amount = self.WEP_AMMO(MACHINEGUN) >= WEP_CVAR(machinegun, sustained_ammo);
315                         else
316                                 ammo_amount = self.WEP_AMMO(MACHINEGUN) >= WEP_CVAR(machinegun, first_ammo);
317
318                         if(WEP_CVAR(machinegun, reload_ammo))
319                         {
320                                 if(WEP_CVAR(machinegun, mode) == 1)
321                                         ammo_amount += self.(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, sustained_ammo);
322                                 else
323                                         ammo_amount += self.(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, first_ammo);
324                         }
325                         return ammo_amount;
326                 }
327                 case WR_CHECKAMMO2:
328                 {
329                         if(WEP_CVAR(machinegun, mode) == 1)
330                                 ammo_amount = self.WEP_AMMO(MACHINEGUN) >= WEP_CVAR(machinegun, burst_ammo);
331                         else
332                                 ammo_amount = self.WEP_AMMO(MACHINEGUN) >= WEP_CVAR(machinegun, first_ammo);
333
334                         if(WEP_CVAR(machinegun, reload_ammo))
335                         {
336                                 if(WEP_CVAR(machinegun, mode) == 1)
337                                         ammo_amount += self.(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, burst_ammo);
338                                 else
339                                         ammo_amount += self.(weapon_load[WEP_MACHINEGUN.m_id]) >= WEP_CVAR(machinegun, first_ammo);
340                         }
341                         return ammo_amount;
342                 }
343                 case WR_CONFIG:
344                 {
345                         MACHINEGUN_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
346                         return true;
347                 }
348                 case WR_RELOAD:
349                 {
350                         W_Reload(min(max(WEP_CVAR(machinegun, sustained_ammo), WEP_CVAR(machinegun, first_ammo)), WEP_CVAR(machinegun, burst_ammo)), SND(RELOAD));
351                         return true;
352                 }
353                 case WR_SUICIDEMESSAGE:
354                 {
355                         return WEAPON_THINKING_WITH_PORTALS;
356                 }
357                 case WR_KILLMESSAGE:
358                 {
359                         if(w_deathtype & HITTYPE_SECONDARY)
360                                 return WEAPON_MACHINEGUN_MURDER_SNIPE;
361                         else
362                                 return WEAPON_MACHINEGUN_MURDER_SPRAY;
363                 }
364         }
365         return false;
366 }
367 #endif
368 #ifdef CSQC
369 bool W_MachineGun(entity thiswep, int req)
370 {SELFPARAM();
371         switch(req)
372         {
373                 case WR_IMPACTEFFECT:
374                 {
375                         vector org2;
376                         org2 = w_org + w_backoff * 2;
377                         pointparticles(particleeffectnum(EFFECT_MACHINEGUN_IMPACT), org2, w_backoff * 1000, 1);
378                         if(!w_issilent)
379                                 if(w_random < 0.05)
380                                         sound(self, CH_SHOTS, SND_RIC1, VOL_BASE, ATTN_NORM);
381                                 else if(w_random < 0.1)
382                                         sound(self, CH_SHOTS, SND_RIC2, VOL_BASE, ATTN_NORM);
383                                 else if(w_random < 0.2)
384                                         sound(self, CH_SHOTS, SND_RIC3, VOL_BASE, ATTN_NORM);
385
386                         return true;
387                 }
388                 case WR_INIT:
389                 {
390                         return true;
391                 }
392                 case WR_ZOOMRETICLE:
393                 {
394                         // no weapon specific image for this weapon
395                         return false;
396                 }
397         }
398         return false;
399 }
400 #endif
401 #endif