]> 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 // 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.owner.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;
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", CHAN_WEAPON, ((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, 0, 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, 0, 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                 {
87                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
88                         w_ready();
89                         return;
90                 }
91                 self.misc_bulletcounter = self.misc_bulletcounter + 1;
92                 W_UZI_Attack(WEP_UZI);
93                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_fire1_02);
94         }
95         else
96                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, w_ready);
97 }
98
99
100 void uzi_mode1_fire_auto()
101 {
102         float uzi_spread;
103
104         W_DecreaseAmmo(ammo_nails, autocvar_g_balance_uzi_sustained_ammo, autocvar_g_balance_uzi_reload_ammo);
105         
106         if (self.BUTTON_ATCK)
107                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_mode1_fire_auto);
108         else
109         {
110                 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_first_refire * W_WeaponRateFactor();
111                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, w_ready);
112                 return;
113         }
114
115         if (!weapon_action(self.weapon, WR_CHECKAMMO1))
116         {
117                 W_SwitchWeapon_Force(self, w_getbestweapon(self));
118                 w_ready();
119                 return;
120         }
121         
122         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);
123         if (!g_norecoil)
124         {
125                 self.punchangle_x = random () - 0.5;
126                 self.punchangle_y = random () - 0.5;
127         }
128         
129         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);
130         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);
131         endFireBallisticBullet();
132         
133         self.misc_bulletcounter = self.misc_bulletcounter + 1;
134         
135         pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
136
137         UziFlash();
138         W_AttachToShotorg(self.muzzle_flash, '5 0 0');
139         
140         if (autocvar_g_casings >= 2) // casing code
141                 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);
142 }
143
144 void uzi_mode1_fire_burst()
145 {
146         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);
147         if (!g_norecoil)
148         {
149                 self.punchangle_x = random () - 0.5;
150                 self.punchangle_y = random () - 0.5;
151         }
152         
153         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);
154         endFireBallisticBullet();
155         
156         
157         pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
158
159         UziFlash();
160         W_AttachToShotorg(self.muzzle_flash, '5 0 0');
161         
162         if (autocvar_g_casings >= 2) // casing code
163                 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);
164
165         self.misc_bulletcounter = self.misc_bulletcounter + 1;
166         if (self.misc_bulletcounter == 0)
167         {
168                 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_burst_refire2 * W_WeaponRateFactor();
169                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_burst_animtime, w_ready);
170         }
171         else
172         {
173                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_burst_refire, uzi_mode1_fire_burst);
174         }
175                 
176 }
177
178 void spawnfunc_weapon_machinegun(); // defined in t_items.qc
179
180 float w_uzi(float req)
181 {
182         float ammo_amount;
183         if (req == WR_AIM)
184                 if(vlen(self.origin-self.enemy.origin) < 3000 - bound(0, skill, 10) * 200)
185                         self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
186                 else
187                 {
188                         self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
189                 }
190         else if (req == WR_THINK)
191         {
192                 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
193                         weapon_action(self.weapon, WR_RELOAD);
194                 else if(autocvar_g_balance_uzi_mode == 1)
195                 {
196                         if (self.BUTTON_ATCK)
197                         if (weapon_prepareattack(0, 0))
198                         {                               
199                                 self.misc_bulletcounter = 0;
200                                 uzi_mode1_fire_auto();
201                         }
202                         
203                         if(self.BUTTON_ATCK2)
204                         if(weapon_prepareattack(1, 0))
205                         {
206                                 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
207                                 {
208                                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
209                                         w_ready();
210                                         return FALSE;
211                                 }
212
213                                 W_DecreaseAmmo(ammo_nails, autocvar_g_balance_uzi_burst_ammo, autocvar_g_balance_uzi_reload_ammo);
214
215                                 self.misc_bulletcounter = autocvar_g_balance_uzi_burst * -1;
216                                 uzi_mode1_fire_burst();
217                         }
218                 }
219                 else
220                 {
221                         
222                         if (self.BUTTON_ATCK)
223                         if (weapon_prepareattack(0, 0))
224                         {
225                                 self.misc_bulletcounter = 1;
226                                 W_UZI_Attack(WEP_UZI); // sets attack_finished
227                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_fire1_02);
228                         }
229
230                         if (self.BUTTON_ATCK2 && autocvar_g_balance_uzi_first)
231                         if (weapon_prepareattack(1, 0))
232                         {
233                                 self.misc_bulletcounter = 1;
234                                 W_UZI_Attack(WEP_UZI | HITTYPE_SECONDARY); // sets attack_finished
235                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_first_refire, w_ready);
236                         }
237                 }
238         }
239         else if (req == WR_PRECACHE)
240         {
241                 precache_model ("models/uziflash.md3");
242                 precache_model ("models/weapons/g_uzi.md3");
243                 precache_model ("models/weapons/v_uzi.md3");
244                 precache_model ("models/weapons/h_uzi.iqm");
245                 precache_sound ("weapons/uzi_fire.wav");
246                 precache_sound ("weapons/reload.wav");
247         }
248         else if (req == WR_SETUP)
249         {
250                 weapon_setup(WEP_UZI);
251                 self.current_ammo = ammo_nails;
252         }
253         else if (req == WR_CHECKAMMO1)
254         {
255                 if(autocvar_g_balance_uzi_mode == 1)
256                         ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_sustained_ammo;
257                 else
258                         ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
259
260                 if(autocvar_g_balance_uzi_reload_ammo)
261                 {
262                         if(autocvar_g_balance_uzi_mode == 1)
263                                 ammo_amount += self.weapon_load[WEP_UZI] >= autocvar_g_balance_uzi_sustained_ammo;
264                         else
265                                 ammo_amount += self.weapon_load[WEP_UZI] >= autocvar_g_balance_uzi_first_ammo;
266                 }
267                 return ammo_amount;
268         }
269         else if (req == WR_CHECKAMMO2)
270         {
271                 if(autocvar_g_balance_uzi_mode == 1)
272                         ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_burst_ammo;
273                 else
274                         ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
275
276                 if(autocvar_g_balance_uzi_reload_ammo)
277                 {
278                         if(autocvar_g_balance_uzi_mode == 1)
279                                 ammo_amount += self.weapon_load[WEP_UZI] >= autocvar_g_balance_uzi_burst_ammo;
280                         else
281                                 ammo_amount += self.weapon_load[WEP_UZI] >= autocvar_g_balance_uzi_first_ammo;
282                 }
283                 return ammo_amount;
284         }
285         else if (req == WR_RELOAD)
286         {
287                 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");
288         }
289         return TRUE;
290 };
291 #endif
292 #ifdef CSQC
293 float w_uzi(float req)
294 {
295         if(req == WR_IMPACTEFFECT)
296         {
297                 vector org2;
298                 org2 = w_org + w_backoff * 2;
299                 pointparticles(particleeffectnum("machinegun_impact"), org2, w_backoff * 1000, 1);
300                 if(!w_issilent)
301                         if(w_random < 0.05)
302                                 sound(self, CHAN_PROJECTILE, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
303                         else if(w_random < 0.1)
304                                 sound(self, CHAN_PROJECTILE, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
305                         else if(w_random < 0.2)
306                                 sound(self, CHAN_PROJECTILE, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
307         }
308         else if(req == WR_PRECACHE)
309         {
310                 precache_sound("weapons/ric1.wav");
311                 precache_sound("weapons/ric2.wav");
312                 precache_sound("weapons/ric3.wav");
313         }
314         else if (req == WR_SUICIDEMESSAGE)
315                 w_deathtypestring = _("%s did the impossible");
316         else if (req == WR_KILLMESSAGE)
317         {
318                 if(w_deathtype & HITTYPE_SECONDARY)
319                         w_deathtypestring = _("%s was sniped by %s");
320                 else
321                         w_deathtypestring = _("%s was riddled full of holes by %s");
322         }
323         return TRUE;
324 }
325 #endif
326 #endif