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