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