]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_minstanex.qc
3fdec0d06d88f95436721ec1dd6cb413727000b3
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_minstanex.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(MINSTANEX, w_minstanex, IT_CELLS, 7, WEP_FLAG_HIDDEN | WEP_FLAG_CANCLIMB | WEP_TYPE_HITSCAN, BOT_PICKUP_RATING_HIGH, "minstanex", "minstanex", _("MinstaNex"))
3 #else
4 #ifdef SVQC
5 .float minstanex_lasthit;
6
7 .float minstanex_load;
8
9 void W_Minstanex_SetAmmoCounter()
10 {
11         // set clip_load to the weapon we have switched to, if the gun uses reloading
12         if(!autocvar_g_balance_minstanex_reload_ammo)
13                 self.clip_load = 0; // also keeps crosshair ammo from displaying
14         else
15         {
16                 self.clip_load = self.minstanex_load;
17                 self.clip_size = autocvar_g_balance_minstanex_reload_ammo; // for the crosshair ammo display
18         }
19 }
20
21 void W_Minstanex_ReloadedAndReady()
22 {
23         float t;
24
25         // now do the ammo transfer
26         self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
27         while(self.clip_load < autocvar_g_balance_minstanex_reload_ammo && self.ammo_cells) // make sure we don't add more ammo than we have
28         {
29                 self.clip_load += 1;
30                 self.ammo_cells -= 1;
31         }
32         self.minstanex_load = self.clip_load;
33
34         t = ATTACK_FINISHED(self) - autocvar_g_balance_minstanex_reload_time - 1;
35         ATTACK_FINISHED(self) = t;
36         w_ready();
37 }
38
39 void W_Minstanex_Reload()
40 {
41         // return if reloading is disabled for this weapon
42         if(!autocvar_g_balance_minstanex_reload_ammo)
43                 return;
44
45         if(!W_ReloadCheck(self.ammo_cells, autocvar_g_balance_minstanex_ammo))
46                 return;
47
48         float t;
49
50         sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
51
52         t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_minstanex_reload_time + 1;
53         ATTACK_FINISHED(self) = t;
54
55         weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_minstanex_reload_time, W_Minstanex_ReloadedAndReady);
56
57         self.old_clip_load = self.clip_load;
58         self.clip_load = -1;
59 }
60
61 void W_MinstaNex_Attack (void)
62 {
63         float flying;
64         flying = IsFlying(self); // do this BEFORE to make the trace values from FireRailgunBullet last
65
66         W_SetupShot (self, TRUE, 0, "weapons/minstanexfire.wav", CHAN_WEAPON, 10000);
67
68         yoda = 0;
69         damage_goodhits = 0;
70         headshot = 0;
71         FireRailgunBullet (w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, 10000, 800, 0, 0, 0, 0, WEP_MINSTANEX);
72
73         if(g_minstagib)
74         {
75                 if(yoda)
76                         AnnounceTo(self, "yoda");
77         }
78         else
79         {
80                 if(yoda && flying)
81                         AnnounceTo(self, "yoda");
82                 if(headshot)
83                 {
84                         AnnounceTo(self, "headshot");
85                 }
86                 if(damage_goodhits && self.minstanex_lasthit)
87                 {
88                         if(AnnounceTo(self, "impressive"))
89                                 damage_goodhits = 0; // only every second time
90                 }
91         }
92
93         self.minstanex_lasthit = damage_goodhits;
94
95         pointparticles(particleeffectnum("nex_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
96
97         // teamcolor / hit beam effect
98         vector v;
99         v = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
100         if(teams_matter)
101         {
102             switch(self.team)
103             {
104             case COLOR_TEAM1:   // Red
105                 if(damage_goodhits)
106                     WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3RED_HIT"), w_shotorg, v);
107                 else
108                     WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3RED"), w_shotorg, v);
109                 break;
110             case COLOR_TEAM2:   // Blue
111                 if(damage_goodhits)
112                     WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3BLUE_HIT"), w_shotorg, v);
113                 else
114                     WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3BLUE"), w_shotorg, v);
115                 break;
116             case COLOR_TEAM3:   // Yellow
117                 if(damage_goodhits)
118                     WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3YELLOW_HIT"), w_shotorg, v);
119                 else
120                     WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3YELLOW"), w_shotorg, v);
121                 break;
122             case COLOR_TEAM4:   // Pink
123                 if(damage_goodhits)
124                     WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3PINK_HIT"), w_shotorg, v);
125                 else
126                     WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3PINK"), w_shotorg, v);
127                 break;
128             }
129         }
130         else
131         WarpZone_TrailParticles(world, particleeffectnum("TE_TEI_G3"), w_shotorg, v);
132
133         // flash and burn the wall
134         if (trace_ent.solid == SOLID_BSP && !(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
135                 Damage_DamageInfo(trace_endpos, 10000, 0, 0, 800 * w_shotdir, WEP_MINSTANEX, self);
136
137         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
138         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
139         {
140                 if(autocvar_g_balance_minstanex_reload_ammo)
141                 {
142                         if (g_minstagib)
143                                 self.clip_load -= - 1;
144                         else
145                                 self.clip_load -= autocvar_g_balance_minstanex_ammo;
146                         self.minstanex_load = self.clip_load;
147                 }
148                 else
149                 {
150                         if (g_minstagib)
151                                 self.ammo_cells -= - 1;
152                         else
153                                 self.ammo_cells -= autocvar_g_balance_minstanex_ammo;
154                 }
155         }
156 }
157
158
159 .float minstagib_nextthink;
160 void minstagib_ammocheck (void)
161 {
162         if (time < self.minstagib_nextthink || self.deadflag || gameover)
163                 return;
164
165         if (self.ammo_cells <= 0)
166         {
167                 if (self.health == 5)
168                 {
169                         centerprint(self, "you're dead now...\n");
170                         Damage(self, self, self, 5, DEATH_NOAMMO, self.origin, '0 0 0');
171                         AnnounceTo(self, "terminated");
172                 }
173                 else if (self.health == 10)
174                 {
175                         centerprint(self, "^11^7 second left to find some ammo\n");
176                         Damage(self, self, self, 5, DEATH_NOAMMO, self.origin, '0 0 0');
177                         AnnounceTo(self, "1");
178                 }
179                 else if (self.health == 20)
180                 {
181                         centerprint(self, "^12^7 seconds left to find some ammo\n");
182                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
183                         AnnounceTo(self, "2");
184                 }
185                 else if (self.health == 30)
186                 {
187                         centerprint(self, "^13^7 seconds left to find some ammo\n");
188                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
189                         AnnounceTo(self, "3");
190                 }
191                 else if (self.health == 40)
192                 {
193                         centerprint(self, "^14^7 seconds left to find some ammo\n");
194                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
195                         AnnounceTo(self, "4");
196                 }
197                 else if (self.health == 50)
198                 {
199                         centerprint(self, "^15^7 seconds left to find some ammo\n");
200                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
201                         AnnounceTo(self, "5");
202                 }
203                 else if (self.health == 60)
204                 {
205                         centerprint(self, "^36^7 seconds left to find some ammo\n");
206                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
207                         AnnounceTo(self, "6");
208                 }
209                 else if (self.health == 70)
210                 {
211                         centerprint(self, "^37^7 seconds left to find some ammo\n");
212                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
213                         AnnounceTo(self, "7");
214                 }
215                 else if (self.health == 80)
216                 {
217                         centerprint(self, "^38^7 seconds left to find some ammo\n");
218                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
219                         AnnounceTo(self, "8");
220                 }
221                 else if (self.health == 90)
222                 {
223                         centerprint(self, "^39^7 seconds left to find some ammo\n");
224                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
225                         AnnounceTo(self, "9");
226                 }
227                 else if (self.health == 100)
228                 {
229                         centerprint(self, "get some ammo or\nyou'll be dead in ^310^7 seconds...");
230                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
231                         if not(self.flags & FL_GODMODE)
232                                 AnnounceTo(self, "10");
233                 }
234         }
235         self.minstagib_nextthink = time + 1;
236 }
237
238 void spawnfunc_weapon_minstanex (void); // defined in t_items.qc
239
240 float w_minstanex(float req)
241 {
242         if (req == WR_AIM)
243         {
244                 if(self.ammo_cells>0)
245                         self.BUTTON_ATCK = bot_aim(1000000, 0, 1, FALSE);
246                 else
247                         self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_laser_primary_speed, 0, autocvar_g_balance_laser_primary_lifetime, FALSE);
248         }
249         else if (req == WR_THINK)
250         {
251                 if(autocvar_g_balance_minstanex_reload_ammo && ((g_minstagib && self.clip_load < 1) || (!g_minstagib && self.clip_load < autocvar_g_balance_minstanex_ammo))) // forced reload
252                         W_Minstanex_Reload();
253                 else if (self.BUTTON_ATCK)
254                 {
255                         if (weapon_prepareattack(0, autocvar_g_balance_minstanex_refire))
256                         {
257                                 W_MinstaNex_Attack();
258                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_minstanex_animtime, w_ready);
259                         }
260                 }
261                 else if (self.BUTTON_ATCK2)
262                 {
263                         if (self.jump_interval <= time)
264                         {
265                                 self.jump_interval = time + autocvar_g_balance_laser_primary_refire * W_WeaponRateFactor();
266
267                                 // ugly minstagib hack to reuse the fire mode of the laser
268                                 float w;
269                                 w = self.weapon;
270                                 self.weapon = WEP_LASER;
271                                 W_Laser_Attack(2);
272                                 self.weapon = w;
273                         }
274                 }
275         if(self.wish_reload)
276         {
277             if(self.switchweapon == self.weapon)
278             {
279                 if(self.weaponentity.state == WS_READY)
280                 {
281                     self.wish_reload = 0;
282                     W_Minstanex_Reload();
283                 }
284             }
285         }
286         }
287         else if (req == WR_PRECACHE)
288         {
289                 precache_model ("models/nexflash.md3");
290                 precache_model ("models/weapons/g_minstanex.md3");
291                 precache_model ("models/weapons/v_minstanex.md3");
292                 precache_model ("models/weapons/h_minstanex.iqm");
293                 precache_sound ("weapons/minstanexfire.wav");
294                 precache_sound ("weapons/nexwhoosh1.wav");
295                 precache_sound ("weapons/nexwhoosh2.wav");
296                 precache_sound ("weapons/nexwhoosh3.wav");
297                 w_laser(WR_PRECACHE);
298         }
299         else if (req == WR_SETUP)
300         {
301                 weapon_setup(WEP_MINSTANEX);
302                 W_Minstanex_SetAmmoCounter();
303                 self.minstanex_lasthit = 0;
304         }
305         else if (req == WR_CHECKAMMO1)
306         {
307                 if(autocvar_g_balance_minstanex_reload_ammo)
308                 {
309                         if (g_minstagib)
310                                 return self.clip_load >= 1;
311                         else
312                                 return self.clip_load >= autocvar_g_balance_minstanex_ammo;
313                 }
314                 else
315                 {
316                         if (g_minstagib)
317                                 return self.ammo_cells >= 1;
318                         else
319                                 return self.ammo_cells >= autocvar_g_balance_minstanex_ammo;
320                 }
321         }
322         else if (req == WR_CHECKAMMO2)
323                 return TRUE;
324         else if (req == WR_RESETPLAYER)
325         {
326                 self.minstanex_lasthit = 0;
327         }
328         else if (req == WR_RELOAD)
329         {
330                 W_Minstanex_Reload();
331         }
332         return TRUE;
333 };
334 #endif
335 #ifdef CSQC
336 float w_minstanex(float req)
337 {
338         if(req == WR_IMPACTEFFECT)
339         {
340                 vector org2;
341                 org2 = w_org + w_backoff * 6;
342                 pointparticles(particleeffectnum("nex_impact"), org2, '0 0 0', 1);
343                 if(!w_issilent)
344                         sound(self, CHAN_PROJECTILE, "weapons/neximpact.wav", VOL_BASE, ATTN_NORM);
345         }
346         else if(req == WR_PRECACHE)
347         {
348                 precache_sound("weapons/neximpact.wav");
349         }
350         else if (req == WR_SUICIDEMESSAGE)
351                 w_deathtypestring = "%s did the impossible";
352         else if (req == WR_KILLMESSAGE)
353                 w_deathtypestring = "%s has been vaporized by %s";
354         return TRUE;
355 }
356 #endif
357 #endif