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