]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_uzi.qc
Merge branch 'master' into mirceakitsune/universal_reload_system
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_uzi.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(UZI, w_uzi, IT_NAILS, 3, WEP_FLAG_NORMAL | WEP_TYPE_HITSCAN, BOT_PICKUP_RATING_MID, "uzi", "uzi", _("Machine Gun"))
3 #else
4 #ifdef SVQC
5
6 // weapon load persistence, for weapons that support reloading
7 .float uzi_load;
8
9 void W_UZI_SetAmmoCounter()
10 {
11         // set clip_load to the weapon we have switched to, if the gun uses reloading
12         if(!autocvar_g_balance_uzi_reload_ammo)
13                 self.clip_load = 0; // also keeps crosshair ammo from displaying
14         else
15         {
16                 self.clip_load = self.uzi_load;
17                 self.clip_size = autocvar_g_balance_uzi_reload_ammo; // for the crosshair ammo display
18         }
19 }
20
21 void W_UZI_ReloadedAndReady()
22 {
23         float t;
24
25         // now do the ammo transfer
26         self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
27         while(self.clip_load < autocvar_g_balance_uzi_reload_ammo && self.ammo_nails) // make sure we don't add more ammo than we have
28         {
29                 self.clip_load += 1;
30                 self.ammo_nails -= 1;
31         }
32         self.uzi_load = self.clip_load;
33
34         t = ATTACK_FINISHED(self) - autocvar_g_balance_uzi_reload_time - 1;
35         ATTACK_FINISHED(self) = t;
36         w_ready();
37 }
38
39 void W_UZI_Reload()
40 {
41         // return if reloading is disabled for this weapon
42         if(!autocvar_g_balance_uzi_reload_ammo)
43                 return;
44
45         if(!W_ReloadCheck(self.ammo_nails, min(max(autocvar_g_balance_uzi_sustained_ammo, autocvar_g_balance_uzi_first_ammo), autocvar_g_balance_uzi_burst_ammo)))
46                 return;
47
48         float t;
49
50         sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
51
52         t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_uzi_reload_time + 1;
53         ATTACK_FINISHED(self) = t;
54
55         weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_uzi_reload_time, W_UZI_ReloadedAndReady);
56
57         self.old_clip_load = self.clip_load;
58         self.clip_load = -1;
59 }
60
61 // leilei's fancy muzzleflash stuff
62 void UZI_Flash_Go() 
63 {       
64         self.frame = self.frame + 2;
65         self.scale = self.scale * 0.5;
66         self.alpha = self.alpha - 0.25;
67         self.nextthink = time + 0.05;
68
69         if (self.alpha <= 0)
70         {
71                 self.think = SUB_Remove;
72                 self.nextthink = time;
73                 self.owner.muzzle_flash = world;
74                 return;
75         }
76         
77 }
78
79 void UziFlash()
80 {       
81         if (self.muzzle_flash == world)
82                 self.muzzle_flash = spawn();    
83         
84         // muzzle flash for 1st person view
85         setmodel(self.muzzle_flash, "models/uziflash.md3"); // precision set below
86         
87         self.muzzle_flash.scale = 0.75;
88         self.muzzle_flash.think = UZI_Flash_Go;
89         self.muzzle_flash.nextthink = time + 0.02;
90         self.muzzle_flash.frame = 2;
91         self.muzzle_flash.alpha = 0.75;
92         self.muzzle_flash.angles_z = random() * 180;
93         self.muzzle_flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
94         self.muzzle_flash.owner = self;
95 }
96
97 void W_UZI_Attack (float deathtype)
98 {
99         W_SetupShot (self, autocvar_g_antilag_bullets && autocvar_g_balance_uzi_speed >= autocvar_g_antilag_bullets, 0, "weapons/uzi_fire.wav", CHAN_WEAPON, ((self.misc_bulletcounter == 1) ? autocvar_g_balance_uzi_first_damage : autocvar_g_balance_uzi_sustained_damage));
100         if (!g_norecoil)
101         {
102                 self.punchangle_x = random () - 0.5;
103                 self.punchangle_y = random () - 0.5;
104         }
105
106         // this attack_finished just enforces a cooldown at the end of a burst
107         ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_first_refire * W_WeaponRateFactor();
108
109         if (self.misc_bulletcounter == 1)
110                 fireBallisticBullet(w_shotorg, w_shotdir, autocvar_g_balance_uzi_first_spread, autocvar_g_balance_uzi_speed, 5, autocvar_g_balance_uzi_first_damage, 0, autocvar_g_balance_uzi_first_force, deathtype, 0, 1, autocvar_g_balance_uzi_bulletconstant);
111         else
112                 fireBallisticBullet(w_shotorg, w_shotdir, autocvar_g_balance_uzi_sustained_spread, autocvar_g_balance_uzi_speed, 5, autocvar_g_balance_uzi_sustained_damage, 0, autocvar_g_balance_uzi_sustained_force, deathtype, 0, 1, autocvar_g_balance_uzi_bulletconstant);
113         endFireBallisticBullet();
114
115         pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
116
117         UziFlash();
118         W_AttachToShotorg(self.muzzle_flash, '5 0 0');
119
120         // casing code
121         if (autocvar_g_casings >= 2)
122                 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);
123
124         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
125         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
126         {
127                 if(autocvar_g_balance_uzi_reload_ammo)
128                 {
129                         if (self.misc_bulletcounter == 1)
130                                 self.clip_load -= autocvar_g_balance_uzi_first_ammo;
131                         else
132                                 self.clip_load -= autocvar_g_balance_uzi_sustained_ammo;
133                         self.uzi_load = self.clip_load;
134                 }
135                 else
136                 {
137                         if (self.misc_bulletcounter == 1)
138                                 self.ammo_nails -= autocvar_g_balance_uzi_first_ammo;
139                         else
140                                 self.ammo_nails -= autocvar_g_balance_uzi_sustained_ammo;
141                 }
142         }
143 }
144
145 // weapon frames
146 void uzi_fire1_02()
147 {
148         if(self.weapon != self.switchweapon) // abort immediately if switching
149         {
150                 w_ready();
151                 return;
152         }
153         if (self.BUTTON_ATCK)
154         {
155                 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
156                 {
157                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
158                         w_ready();
159                         return;
160                 }
161                 self.misc_bulletcounter = self.misc_bulletcounter + 1;
162                 W_UZI_Attack(WEP_UZI);
163                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_fire1_02);
164         }
165         else
166                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, w_ready);
167 }
168
169
170 void uzi_mode1_fire_auto()
171 {
172         float uzi_spread;
173
174         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
175         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
176         {
177                 if(autocvar_g_balance_uzi_reload_ammo)
178                 {
179                         self.clip_load -= autocvar_g_balance_uzi_sustained_ammo;
180                         self.uzi_load = self.clip_load;
181                 }
182                 else
183                         self.ammo_nails -= autocvar_g_balance_uzi_sustained_ammo;
184         }
185         
186         if (self.BUTTON_ATCK)
187                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_mode1_fire_auto);
188         else
189         {
190                 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_first_refire * W_WeaponRateFactor();
191                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, w_ready);
192                 return;
193         }
194
195         if (!weapon_action(self.weapon, WR_CHECKAMMO1))
196         {
197                 W_SwitchWeapon_Force(self, w_getbestweapon(self));
198                 w_ready();
199                 return;
200         }
201         
202         W_SetupShot (self, autocvar_g_antilag_bullets && autocvar_g_balance_uzi_speed >= autocvar_g_antilag_bullets, 0, "weapons/uzi_fire.wav", CHAN_WEAPON, autocvar_g_balance_uzi_sustained_damage);
203         if (!g_norecoil)
204         {
205                 self.punchangle_x = random () - 0.5;
206                 self.punchangle_y = random () - 0.5;
207         }
208         
209         uzi_spread = bound(autocvar_g_balance_uzi_spread_min, autocvar_g_balance_uzi_spread_min + (autocvar_g_balance_uzi_spread_add * self.misc_bulletcounter), autocvar_g_balance_uzi_spread_max);
210         fireBallisticBullet(w_shotorg, w_shotdir, uzi_spread, autocvar_g_balance_uzi_speed, 5, autocvar_g_balance_uzi_sustained_damage, 0, autocvar_g_balance_uzi_sustained_force, WEP_UZI, 0, 1, autocvar_g_balance_uzi_bulletconstant);
211         endFireBallisticBullet();
212         
213         self.misc_bulletcounter = self.misc_bulletcounter + 1;
214         
215         pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
216
217         UziFlash();
218         W_AttachToShotorg(self.muzzle_flash, '5 0 0');
219         
220         if (autocvar_g_casings >= 2) // casing code
221                 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);
222 }
223
224 void uzi_mode1_fire_burst()
225 {
226         W_SetupShot (self, autocvar_g_antilag_bullets && autocvar_g_balance_uzi_speed >= autocvar_g_antilag_bullets, 0, "weapons/uzi_fire.wav", CHAN_WEAPON, autocvar_g_balance_uzi_sustained_damage);
227         if (!g_norecoil)
228         {
229                 self.punchangle_x = random () - 0.5;
230                 self.punchangle_y = random () - 0.5;
231         }
232         
233         fireBallisticBullet(w_shotorg, w_shotdir, autocvar_g_balance_uzi_burst_spread, autocvar_g_balance_uzi_speed, 5, autocvar_g_balance_uzi_sustained_damage, 0, autocvar_g_balance_uzi_sustained_force, WEP_UZI, 0, 1, autocvar_g_balance_uzi_bulletconstant);
234         endFireBallisticBullet();
235         
236         
237         pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
238
239         UziFlash();
240         W_AttachToShotorg(self.muzzle_flash, '5 0 0');
241         
242         if (autocvar_g_casings >= 2) // casing code
243                 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);
244
245         self.misc_bulletcounter = self.misc_bulletcounter + 1;
246         if (self.misc_bulletcounter == 0)
247         {
248                 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_burst_refire2 * W_WeaponRateFactor();
249                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_burst_animtime, w_ready);
250         }
251         else
252         {
253                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_burst_refire, uzi_mode1_fire_burst);
254         }
255                 
256 }
257
258 void spawnfunc_weapon_machinegun(); // defined in t_items.qc
259
260 float w_uzi(float req)
261 {
262         float ammo_amount;
263         if (req == WR_AIM)
264                 if(vlen(self.origin-self.enemy.origin) < 3000 - bound(0, skill, 10) * 200)
265                         self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
266                 else
267                 {
268                         self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
269                 }
270         else if (req == WR_THINK)
271         {
272                 if(autocvar_g_balance_uzi_reload_ammo && self.clip_load < min(max(autocvar_g_balance_uzi_sustained_ammo, autocvar_g_balance_uzi_first_ammo), autocvar_g_balance_uzi_burst_ammo)) // forced reload
273                         W_UZI_Reload();
274                 else if(autocvar_g_balance_uzi_mode == 1)
275                 {
276                         if (self.BUTTON_ATCK)
277                         if (weapon_prepareattack(0, 0))
278                         {                               
279                                 self.misc_bulletcounter = 0;
280                                 uzi_mode1_fire_auto();
281                         }
282                         
283                         if(self.BUTTON_ATCK2)
284                         if(weapon_prepareattack(1, 0))
285                         {
286                                 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
287                                 {
288                                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
289                                         w_ready();
290                                         return FALSE;
291                                 }
292
293                                 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
294                                 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
295                                 {
296                                         if(autocvar_g_balance_uzi_reload_ammo)
297                                         {
298                                                 self.clip_load -= autocvar_g_balance_uzi_burst_ammo;
299                                                 self.uzi_load = self.clip_load;
300                                         }
301                                         else
302                                                 self.ammo_nails -= autocvar_g_balance_uzi_burst_ammo;
303                                 }
304
305                                 self.misc_bulletcounter = autocvar_g_balance_uzi_burst * -1;
306                                 uzi_mode1_fire_burst();
307                         }
308                 }
309                 else
310                 {
311                         
312                         if (self.BUTTON_ATCK)
313                         if (weapon_prepareattack(0, 0))
314                         {
315                                 self.misc_bulletcounter = 1;
316                                 W_UZI_Attack(WEP_UZI); // sets attack_finished
317                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_fire1_02);
318                         }
319
320                         if (self.BUTTON_ATCK2 && autocvar_g_balance_uzi_first)
321                         if (weapon_prepareattack(1, 0))
322                         {
323                                 self.misc_bulletcounter = 1;
324                                 W_UZI_Attack(WEP_UZI | HITTYPE_SECONDARY); // sets attack_finished
325                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_first_refire, w_ready);
326                         }
327                 }
328         }
329         else if (req == WR_PRECACHE)
330         {
331                 precache_model ("models/uziflash.md3");
332                 precache_model ("models/weapons/g_uzi.md3");
333                 precache_model ("models/weapons/v_uzi.md3");
334                 precache_model ("models/weapons/h_uzi.iqm");
335                 precache_sound ("weapons/uzi_fire.wav");
336                 precache_sound ("weapons/reload.wav");
337         }
338         else if (req == WR_SETUP)
339         {
340                 weapon_setup(WEP_UZI);
341                 W_UZI_SetAmmoCounter();
342         }
343         else if (req == WR_CHECKAMMO1)
344         {
345                 if(autocvar_g_balance_uzi_mode == 1)
346                         ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_sustained_ammo;
347                 else
348                         ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
349
350                 if(autocvar_g_balance_uzi_reload_ammo)
351                 {
352                         if(autocvar_g_balance_uzi_mode == 1)
353                                 ammo_amount += self.uzi_load >= autocvar_g_balance_uzi_sustained_ammo;
354                         else
355                                 ammo_amount += self.uzi_load >= autocvar_g_balance_uzi_first_ammo;
356                 }
357                 return ammo_amount;
358         }
359         else if (req == WR_CHECKAMMO2)
360         {
361                 if(autocvar_g_balance_uzi_mode == 1)
362                         ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_burst_ammo;
363                 else
364                         ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
365
366                 if(autocvar_g_balance_uzi_reload_ammo)
367                 {
368                         if(autocvar_g_balance_uzi_mode == 1)
369                                 ammo_amount += self.uzi_load >= autocvar_g_balance_uzi_burst_ammo;
370                         else
371                                 ammo_amount += self.uzi_load >= autocvar_g_balance_uzi_first_ammo;
372                 }
373                 return ammo_amount;
374         }
375         else if (req == WR_RESETPLAYER)
376         {
377                 // all weapons must be fully loaded when we spawn
378                 self.uzi_load = autocvar_g_balance_uzi_reload_ammo;
379         }
380         else if (req == WR_RELOAD)
381         {
382                 W_UZI_Reload();
383         }
384         return TRUE;
385 };
386 #endif
387 #ifdef CSQC
388 float w_uzi(float req)
389 {
390         if(req == WR_IMPACTEFFECT)
391         {
392                 vector org2;
393                 org2 = w_org + w_backoff * 2;
394                 pointparticles(particleeffectnum("machinegun_impact"), org2, w_backoff * 1000, 1);
395                 if(!w_issilent)
396                         if(w_random < 0.05)
397                                 sound(self, CHAN_PROJECTILE, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
398                         else if(w_random < 0.1)
399                                 sound(self, CHAN_PROJECTILE, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
400                         else if(w_random < 0.2)
401                                 sound(self, CHAN_PROJECTILE, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
402         }
403         else if(req == WR_PRECACHE)
404         {
405                 precache_sound("weapons/ric1.wav");
406                 precache_sound("weapons/ric2.wav");
407                 precache_sound("weapons/ric3.wav");
408         }
409         else if (req == WR_SUICIDEMESSAGE)
410                 w_deathtypestring = _("%s did the impossible");
411         else if (req == WR_KILLMESSAGE)
412         {
413                 if(w_deathtype & HITTYPE_SECONDARY)
414                         w_deathtypestring = _("%s was sniped by %s");
415                 else
416                         w_deathtypestring = _("%s was riddled full of holes by %s");
417         }
418         return TRUE;
419 }
420 #endif
421 #endif