]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_machinegun.qc
Add weaponstartoverride property to weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_machinegun.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(
3 /* WEP_##id */ UZI,
4 /* function */ w_uzi,
5 /* ammotype */ IT_NAILS,
6 /* impulse  */ 3,
7 /* flags    */ WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN,
8 /* rating   */ BOT_PICKUP_RATING_MID,
9 /* model    */ "uzi",
10 /* netname  */ "uzi",
11 /* fullname */ _("Machine Gun")
12 );
13
14 #define UZI_SETTINGS(w_cvar,w_prop) \
15         w_cvar(WEP_UZI, uzi, MO_NONE, speed) \
16         w_cvar(WEP_UZI, uzi, MO_NONE, spread_min) \
17         w_cvar(WEP_UZI, uzi, MO_NONE, spread_max) \
18         w_cvar(WEP_UZI, uzi, MO_NONE, spread_add) \
19         w_cvar(WEP_UZI, uzi, MO_NONE, mode) \
20         w_cvar(WEP_UZI, uzi, MO_NONE, bulletconstant) \
21         w_cvar(WEP_UZI, uzi, MO_NONE, first) \
22         w_cvar(WEP_UZI, uzi, MO_NONE, first_damage) \
23         w_cvar(WEP_UZI, uzi, MO_NONE, first_force) \
24         w_cvar(WEP_UZI, uzi, MO_NONE, first_refire) \
25         w_cvar(WEP_UZI, uzi, MO_NONE, first_spread) \
26         w_cvar(WEP_UZI, uzi, MO_NONE, first_ammo) \
27         w_cvar(WEP_UZI, uzi, MO_NONE, sustained_damage) \
28         w_cvar(WEP_UZI, uzi, MO_NONE, sustained_force) \
29         w_cvar(WEP_UZI, uzi, MO_NONE, sustained_refire) \
30         w_cvar(WEP_UZI, uzi, MO_NONE, sustained_spread) \
31         w_cvar(WEP_UZI, uzi, MO_NONE, sustained_ammo) \
32         w_cvar(WEP_UZI, uzi, MO_NONE, burst) \
33         w_cvar(WEP_UZI, uzi, MO_NONE, burst_refire) \
34         w_cvar(WEP_UZI, uzi, MO_NONE, burst_refire2) \
35         w_cvar(WEP_UZI, uzi, MO_NONE, burst_animtime) \
36         w_cvar(WEP_UZI, uzi, MO_NONE, burst_speed) \
37         w_cvar(WEP_UZI, uzi, MO_NONE, burst_ammo) \
38         w_prop(WEP_UZI, uzi, float,  reloading_ammo, reload_ammo) \
39         w_prop(WEP_UZI, uzi, float,  reloading_time, reload_time) \
40         w_prop(WEP_UZI, uzi, float,  switchdelay_raise, switchdelay_raise) \
41         w_prop(WEP_UZI, uzi, float,  switchdelay_drop, switchdelay_drop) \
42         w_prop(WEP_UZI, uzi, string, weaponreplace, weaponreplace) \
43         w_prop(WEP_UZI, uzi, float,  weaponstart, weaponstart) \
44         w_prop(WEP_UZI, uzi, float,  weaponstartoverride, weaponstartoverride)
45
46 #ifdef SVQC
47 UZI_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
48 #endif
49 #else
50 #ifdef SVQC
51
52 void spawnfunc_weapon_uzi()
53 {
54         if(autocvar_sv_q3acompat_machineshotgunswap)
55         if(self.classname != "droppedweapon")
56         {
57                 weapon_defaultspawnfunc(WEP_SHOCKWAVE);
58                 return;
59         }
60         weapon_defaultspawnfunc(WEP_UZI);
61 }
62
63 // leilei's fancy muzzleflash stuff
64 void UZI_Flash_Go()
65 {
66         self.frame = self.frame + 2;
67         self.scale = self.scale * 0.5;
68         self.alpha = self.alpha - 0.25;
69         self.nextthink = time + 0.05;
70
71         if (self.alpha <= 0)
72         {
73                 self.think = SUB_Remove;
74                 self.nextthink = time;
75                 self.realowner.muzzle_flash = world;
76                 return;
77         }
78
79 }
80
81 void UziFlash()
82 {
83         if (self.muzzle_flash == world)
84                 self.muzzle_flash = spawn();
85
86         // muzzle flash for 1st person view
87         setmodel(self.muzzle_flash, "models/uziflash.md3"); // precision set below
88
89         self.muzzle_flash.scale = 0.75;
90         self.muzzle_flash.think = UZI_Flash_Go;
91         self.muzzle_flash.nextthink = time + 0.02;
92         self.muzzle_flash.frame = 2;
93         self.muzzle_flash.alpha = 0.75;
94         self.muzzle_flash.angles_z = random() * 180;
95         self.muzzle_flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
96         self.muzzle_flash.owner = self.muzzle_flash.realowner = self;
97 }
98
99 void W_UZI_Attack (float deathtype)
100 {
101         W_SetupShot (self, TRUE, 0, "weapons/uzi_fire.wav", CH_WEAPON_A, ((self.misc_bulletcounter == 1) ? WEP_CVAR(uzi, first_damage) : WEP_CVAR(uzi, sustained_damage)));
102         if (!autocvar_g_norecoil)
103         {
104                 self.punchangle_x = random () - 0.5;
105                 self.punchangle_y = random () - 0.5;
106         }
107
108         // this attack_finished just enforces a cooldown at the end of a burst
109         ATTACK_FINISHED(self) = time + WEP_CVAR(uzi, first_refire) * W_WeaponRateFactor();
110
111         if (self.misc_bulletcounter == 1)
112                 fireBallisticBullet(w_shotorg, w_shotdir, WEP_CVAR(uzi, first_spread), WEP_CVAR(uzi, speed), 5, WEP_CVAR(uzi, first_damage), WEP_CVAR(uzi, first_force), deathtype, 0, WEP_CVAR(uzi, bulletconstant));
113         else
114                 fireBallisticBullet(w_shotorg, w_shotdir, WEP_CVAR(uzi, sustained_spread), WEP_CVAR(uzi, speed), 5, WEP_CVAR(uzi, sustained_damage), WEP_CVAR(uzi, sustained_force), deathtype, 0, WEP_CVAR(uzi, bulletconstant));
115         endFireBallisticBullet();
116
117         pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
118
119         UziFlash();
120         W_AttachToShotorg(self.muzzle_flash, '5 0 0');
121
122         // casing code
123         if (autocvar_g_casings >= 2)
124                 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);
125
126         if (self.misc_bulletcounter == 1)
127                 W_DecreaseAmmo(ammo_nails, WEP_CVAR(uzi, first_ammo), autocvar_g_balance_uzi_reload_ammo);
128         else
129                 W_DecreaseAmmo(ammo_nails, WEP_CVAR(uzi, sustained_ammo), autocvar_g_balance_uzi_reload_ammo);
130 }
131
132 // weapon frames
133 void uzi_fire1_02()
134 {
135         if(self.weapon != self.switchweapon) // abort immediately if switching
136         {
137                 w_ready();
138                 return;
139         }
140         if (self.BUTTON_ATCK)
141         {
142                 if (!WEP_ACTION(self.weapon, WR_CHECKAMMO2))
143                 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
144                 {
145                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
146                         w_ready();
147                         return;
148                 }
149                 self.misc_bulletcounter = self.misc_bulletcounter + 1;
150                 W_UZI_Attack(WEP_UZI);
151                 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(uzi, sustained_refire), uzi_fire1_02);
152         }
153         else
154                 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(uzi, sustained_refire), w_ready);
155 }
156
157
158 void uzi_mode1_fire_auto()
159 {
160         float uzi_spread;
161
162         if (!self.BUTTON_ATCK)
163         {
164                 w_ready();
165                 return;
166         }
167
168         if (!WEP_ACTION(self.weapon, WR_CHECKAMMO1))
169         if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
170         {
171                 W_SwitchWeapon_Force(self, w_getbestweapon(self));
172                 w_ready();
173                 return;
174         }
175
176         W_DecreaseAmmo(ammo_nails, WEP_CVAR(uzi, sustained_ammo), autocvar_g_balance_uzi_reload_ammo);
177
178         W_SetupShot (self, TRUE, 0, "weapons/uzi_fire.wav", CH_WEAPON_A, WEP_CVAR(uzi, sustained_damage));
179         if (!autocvar_g_norecoil)
180         {
181                 self.punchangle_x = random () - 0.5;
182                 self.punchangle_y = random () - 0.5;
183         }
184
185         uzi_spread = bound(WEP_CVAR(uzi, spread_min), WEP_CVAR(uzi, spread_min) + (WEP_CVAR(uzi, spread_add) * self.misc_bulletcounter), WEP_CVAR(uzi, spread_max));
186         fireBallisticBullet(w_shotorg, w_shotdir, uzi_spread, WEP_CVAR(uzi, speed), 5, WEP_CVAR(uzi, sustained_damage), WEP_CVAR(uzi, sustained_force), WEP_UZI, 0, WEP_CVAR(uzi, bulletconstant));
187         endFireBallisticBullet();
188
189         self.misc_bulletcounter = self.misc_bulletcounter + 1;
190
191         pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
192
193         UziFlash();
194         W_AttachToShotorg(self.muzzle_flash, '5 0 0');
195
196         if (autocvar_g_casings >= 2) // casing code
197                 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);
198
199         ATTACK_FINISHED(self) = time + WEP_CVAR(uzi, first_refire) * W_WeaponRateFactor();
200         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(uzi, sustained_refire), uzi_mode1_fire_auto);
201 }
202
203 void uzi_mode1_fire_burst()
204 {
205         W_SetupShot (self, TRUE, 0, "weapons/uzi_fire.wav", CH_WEAPON_A, WEP_CVAR(uzi, sustained_damage));
206         if (!autocvar_g_norecoil)
207         {
208                 self.punchangle_x = random () - 0.5;
209                 self.punchangle_y = random () - 0.5;
210         }
211
212         fireBallisticBullet(w_shotorg, w_shotdir, WEP_CVAR(uzi, burst_speed), WEP_CVAR(uzi, speed), 5, WEP_CVAR(uzi, sustained_damage), WEP_CVAR(uzi, sustained_force), WEP_UZI, 0, WEP_CVAR(uzi, bulletconstant));
213         endFireBallisticBullet();
214
215
216         pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
217
218         UziFlash();
219         W_AttachToShotorg(self.muzzle_flash, '5 0 0');
220
221         if (autocvar_g_casings >= 2) // casing code
222                 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);
223
224         self.misc_bulletcounter = self.misc_bulletcounter + 1;
225         if (self.misc_bulletcounter == 0)
226         {
227                 ATTACK_FINISHED(self) = time + WEP_CVAR(uzi, burst_refire2) * W_WeaponRateFactor();
228                 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(uzi, burst_animtime), w_ready);
229         }
230         else
231         {
232                 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(uzi, burst_refire), uzi_mode1_fire_burst);
233         }
234
235 }
236
237 float w_uzi(float req)
238 {
239         float ammo_amount;
240         switch(req)
241         {
242                 case WR_AIM:
243                 {
244                         if(vlen(self.origin-self.enemy.origin) < 3000 - bound(0, skill, 10) * 200)
245                                 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
246                         else
247                                 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
248                         
249                         return TRUE;
250                 }
251                 case WR_THINK:
252                 {
253                         if(autocvar_g_balance_uzi_reload_ammo && self.clip_load < min(max(WEP_CVAR(uzi, sustained_ammo), WEP_CVAR(uzi, first_ammo)), WEP_CVAR(uzi, burst_ammo))) // forced reload
254                                 WEP_ACTION(self.weapon, WR_RELOAD);
255                         else if(WEP_CVAR(uzi, mode) == 1)
256                         {
257                                 if (self.BUTTON_ATCK)
258                                 if (weapon_prepareattack(0, 0))
259                                 {
260                                         self.misc_bulletcounter = 0;
261                                         uzi_mode1_fire_auto();
262                                 }
263
264                                 if(self.BUTTON_ATCK2)
265                                 if(weapon_prepareattack(1, 0))
266                                 {
267                                         if (!WEP_ACTION(self.weapon, WR_CHECKAMMO2))
268                                         if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
269                                         {
270                                                 W_SwitchWeapon_Force(self, w_getbestweapon(self));
271                                                 w_ready();
272                                                 return FALSE;
273                                         }
274
275                                         W_DecreaseAmmo(ammo_nails, WEP_CVAR(uzi, burst_ammo), autocvar_g_balance_uzi_reload_ammo);
276
277                                         self.misc_bulletcounter = WEP_CVAR(uzi, burst) * -1;
278                                         uzi_mode1_fire_burst();
279                                 }
280                         }
281                         else
282                         {
283
284                                 if (self.BUTTON_ATCK)
285                                 if (weapon_prepareattack(0, 0))
286                                 {
287                                         self.misc_bulletcounter = 1;
288                                         W_UZI_Attack(WEP_UZI); // sets attack_finished
289                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(uzi, sustained_refire), uzi_fire1_02);
290                                 }
291
292                                 if (self.BUTTON_ATCK2 && WEP_CVAR(uzi, first))
293                                 if (weapon_prepareattack(1, 0))
294                                 {
295                                         self.misc_bulletcounter = 1;
296                                         W_UZI_Attack(WEP_UZI | HITTYPE_SECONDARY); // sets attack_finished
297                                         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(uzi, first_refire), w_ready);
298                                 }
299                         }
300                         
301                         return TRUE;
302                 }
303                 case WR_INIT:
304                 {
305                         precache_model ("models/uziflash.md3");
306                         precache_model ("models/weapons/g_uzi.md3");
307                         precache_model ("models/weapons/v_uzi.md3");
308                         precache_model ("models/weapons/h_uzi.iqm");
309                         precache_sound ("weapons/uzi_fire.wav");
310                         UZI_SETTINGS(WEP_SKIPCVAR, WEP_SET_PROP)
311                         return TRUE;
312                 }
313                 case WR_SETUP:
314                 {
315                         self.current_ammo = ammo_nails;
316                         return TRUE;
317                 }
318                 case WR_CHECKAMMO1:
319                 {
320                         if(WEP_CVAR(uzi, mode) == 1)
321                                 ammo_amount = self.ammo_nails >= WEP_CVAR(uzi, sustained_ammo);
322                         else
323                                 ammo_amount = self.ammo_nails >= WEP_CVAR(uzi, first_ammo);
324
325                         if(autocvar_g_balance_uzi_reload_ammo)
326                         {
327                                 if(WEP_CVAR(uzi, mode) == 1)
328                                         ammo_amount += self.(weapon_load[WEP_UZI]) >= WEP_CVAR(uzi, sustained_ammo);
329                                 else
330                                         ammo_amount += self.(weapon_load[WEP_UZI]) >= WEP_CVAR(uzi, first_ammo);
331                         }
332                         return ammo_amount;
333                 }
334                 case WR_CHECKAMMO2:
335                 {
336                         if(WEP_CVAR(uzi, mode) == 1)
337                                 ammo_amount = self.ammo_nails >= WEP_CVAR(uzi, burst_ammo);
338                         else
339                                 ammo_amount = self.ammo_nails >= WEP_CVAR(uzi, first_ammo);
340
341                         if(autocvar_g_balance_uzi_reload_ammo)
342                         {
343                                 if(WEP_CVAR(uzi, mode) == 1)
344                                         ammo_amount += self.(weapon_load[WEP_UZI]) >= WEP_CVAR(uzi, burst_ammo);
345                                 else
346                                         ammo_amount += self.(weapon_load[WEP_UZI]) >= WEP_CVAR(uzi, first_ammo);
347                         }
348                         return ammo_amount;
349                 }
350                 case WR_CONFIG:
351                 {
352                         UZI_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
353                         return TRUE;
354                 }
355                 case WR_RELOAD:
356                 {
357                         W_Reload(min(max(WEP_CVAR(uzi, sustained_ammo), WEP_CVAR(uzi, first_ammo)), WEP_CVAR(uzi, burst_ammo)), "weapons/reload.wav");
358                         return TRUE;
359                 }
360                 case WR_SUICIDEMESSAGE:
361                 {
362                         return WEAPON_THINKING_WITH_PORTALS;
363                 }
364                 case WR_KILLMESSAGE:
365                 {
366                         if(w_deathtype & HITTYPE_SECONDARY)
367                                 return WEAPON_UZI_MURDER_SNIPE;
368                         else
369                                 return WEAPON_UZI_MURDER_SPRAY;
370                 }
371         }
372         return TRUE;
373 }
374 #endif
375 #ifdef CSQC
376 float w_uzi(float req)
377 {
378         switch(req)
379         {
380                 case WR_IMPACTEFFECT:
381                 {
382                         vector org2;
383                         org2 = w_org + w_backoff * 2;
384                         pointparticles(particleeffectnum("machinegun_impact"), org2, w_backoff * 1000, 1);
385                         if(!w_issilent)
386                                 if(w_random < 0.05)
387                                         sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
388                                 else if(w_random < 0.1)
389                                         sound(self, CH_SHOTS, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
390                                 else if(w_random < 0.2)
391                                         sound(self, CH_SHOTS, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
392                                         
393                         return TRUE;
394                 }
395                 case WR_INIT:
396                 {
397                         precache_sound("weapons/ric1.wav");
398                         precache_sound("weapons/ric2.wav");
399                         precache_sound("weapons/ric3.wav");
400                         return TRUE;
401                 }
402         }
403         return TRUE;
404 }
405 #endif
406 #endif