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