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