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