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