]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_uzi.qc
Add velocity_len to reduce calls of vlen
[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 // 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         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
45         {
46                 if (self.misc_bulletcounter == 1)
47                         self.ammo_nails = self.ammo_nails - autocvar_g_balance_uzi_first_ammo;
48                 else
49                         self.ammo_nails = self.ammo_nails - autocvar_g_balance_uzi_sustained_ammo;
50         }
51         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));
52         if (!g_norecoil)
53         {
54                 self.punchangle_x = random () - 0.5;
55                 self.punchangle_y = random () - 0.5;
56         }
57
58         // this attack_finished just enforces a cooldown at the end of a burst
59         ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_first_refire * W_WeaponRateFactor();
60
61         if (self.misc_bulletcounter == 1)
62                 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);
63         else
64                 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);
65         endFireBallisticBullet();
66
67         pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
68
69         UziFlash();
70         W_AttachToShotorg(self.muzzle_flash, '5 0 0');
71
72         // casing code
73         if (autocvar_g_casings >= 2)
74                 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);
75 }
76
77 // weapon frames
78 void uzi_fire1_02()
79 {
80         if(self.weapon != self.switchweapon) // abort immediately if switching
81         {
82                 w_ready();
83                 return;
84         }
85         if (self.BUTTON_ATCK)
86         {
87                 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
88                 {
89                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
90                         w_ready();
91                         return;
92                 }
93                 self.misc_bulletcounter = self.misc_bulletcounter + 1;
94                 W_Uzi_Attack(WEP_UZI);
95                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_fire1_02);
96         }
97         else
98                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, w_ready);
99 }
100
101
102 void uzi_mode1_fire_auto()
103 {
104         float uzi_spread;
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         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)   
144                 self.ammo_nails = self.ammo_nails - autocvar_g_balance_uzi_sustained_ammo;
145         
146 }
147
148 void uzi_mode1_fire_burst()
149 {
150         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);
151         if (!g_norecoil)
152         {
153                 self.punchangle_x = random () - 0.5;
154                 self.punchangle_y = random () - 0.5;
155         }
156         
157         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);
158         endFireBallisticBullet();
159         
160         
161         pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
162
163         UziFlash();
164         W_AttachToShotorg(self.muzzle_flash, '5 0 0');
165         
166         if (autocvar_g_casings >= 2) // casing code
167                 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);
168
169         self.misc_bulletcounter = self.misc_bulletcounter + 1;
170         if (self.misc_bulletcounter == 0)
171                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_burst_refire2, w_ready);
172         else
173         {
174                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_burst_refire, uzi_mode1_fire_burst);
175         }
176                 
177 }
178
179 void spawnfunc_weapon_machinegun(); // defined in t_items.qc
180
181 float w_uzi(float req)
182 {
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_mode == 1)
193                 {
194                         if (self.BUTTON_ATCK)
195                         if (weapon_prepareattack(0, 0))
196                         {                               
197                                 self.misc_bulletcounter = 0;
198                                 uzi_mode1_fire_auto();
199                         }
200                         
201                         if(self.BUTTON_ATCK2)
202                         if(weapon_prepareattack(1, 0))
203                         {
204                                 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
205                                 {
206                                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
207                                         w_ready();
208                                         return FALSE;
209                                 }
210                                 
211                                 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)   
212                                         self.ammo_nails = self.ammo_nails - autocvar_g_balance_uzi_burst_ammo;
213
214                                 self.misc_bulletcounter = autocvar_g_balance_uzi_burst * -1;
215                                 uzi_mode1_fire_burst();
216                         }
217                 }
218                 else
219                 {
220                         
221                         if (self.BUTTON_ATCK)
222                         if (weapon_prepareattack(0, 0))
223                         {
224                                 self.misc_bulletcounter = 1;
225                                 W_Uzi_Attack(WEP_UZI); // sets attack_finished
226                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_fire1_02);
227                         }
228
229                         if (self.BUTTON_ATCK2 && autocvar_g_balance_uzi_first)
230                         if (weapon_prepareattack(1, 0))
231                         {
232                                 self.misc_bulletcounter = 1;
233                                 W_Uzi_Attack(WEP_UZI | HITTYPE_SECONDARY); // sets attack_finished
234                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_first_refire, w_ready);
235                         }
236                 }
237         }
238         else if (req == WR_PRECACHE)
239         {
240                 precache_model ("models/uziflash.md3");
241                 precache_model ("models/weapons/g_uzi.md3");
242                 precache_model ("models/weapons/v_uzi.md3");
243                 precache_model ("models/weapons/h_uzi.iqm");
244                 precache_sound ("weapons/uzi_fire.wav");
245         }
246         else if (req == WR_SETUP)
247                 weapon_setup(WEP_UZI);
248         else if (req == WR_CHECKAMMO1)
249                 if(autocvar_g_balance_uzi_mode == 1)
250                         return self.ammo_nails >= autocvar_g_balance_uzi_sustained_ammo;
251                 else
252                         return self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
253         else if (req == WR_CHECKAMMO2)
254                 if(autocvar_g_balance_uzi_mode == 1)
255                         return self.ammo_nails >= autocvar_g_balance_uzi_burst_ammo;
256                 else
257                         return self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
258         return TRUE;
259 };
260 #endif
261 #ifdef CSQC
262 float w_uzi(float req)
263 {
264         if(req == WR_IMPACTEFFECT)
265         {
266                 vector org2;
267                 org2 = w_org + w_backoff * 2;
268                 pointparticles(particleeffectnum("machinegun_impact"), org2, w_backoff * 1000, 1);
269                 if(!w_issilent)
270                         if(w_random < 0.05)
271                                 sound(self, CHAN_PROJECTILE, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
272                         else if(w_random < 0.1)
273                                 sound(self, CHAN_PROJECTILE, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
274                         else if(w_random < 0.2)
275                                 sound(self, CHAN_PROJECTILE, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
276         }
277         else if(req == WR_PRECACHE)
278         {
279                 precache_sound("weapons/ric1.wav");
280                 precache_sound("weapons/ric2.wav");
281                 precache_sound("weapons/ric3.wav");
282         }
283         else if (req == WR_SUICIDEMESSAGE)
284                 w_deathtypestring = "%s did the impossible";
285         else if (req == WR_KILLMESSAGE)
286         {
287                 if(w_deathtype & HITTYPE_SECONDARY)
288                         w_deathtypestring = "%s was sniped by %s";
289                 else
290                         w_deathtypestring = "%s was riddled full of holes by %s";
291         }
292         return TRUE;
293 }
294 #endif
295 #endif