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