]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_nex.qc
Doh, it CAN be done differently than my ugly list. Use WR checks
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_nex.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(NEX, w_nex, IT_CELLS, 7, WEP_FLAG_NORMAL | WEP_TYPE_HITSCAN, BOT_PICKUP_RATING_HIGH, "nex", "nex", _("Nex"))
3 #else
4 #ifdef SVQC
5
6 void W_Nex_SetAmmoCounter()
7 {
8         // set clip_load to the weapon we have switched to, if the gun uses reloading
9         if(!autocvar_g_balance_nex_reload_ammo)
10                 self.clip_load = 0; // also keeps crosshair ammo from displaying
11         else
12         {
13                 self.clip_load = self.nex_load;
14                 self.clip_size = autocvar_g_balance_nex_reload_ammo; // for the crosshair ammo display
15         }
16 }
17
18 void W_Nex_ReloadedAndReady()
19 {
20         float t;
21
22         // now do the ammo transfer
23         self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
24         while(self.clip_load < autocvar_g_balance_nex_reload_ammo && self.ammo_cells) // make sure we don't add more ammo than we have
25         {
26                 self.clip_load += 1;
27                 self.ammo_cells -= 1;
28         }
29         self.nex_load = self.clip_load;
30
31         t = ATTACK_FINISHED(self) - autocvar_g_balance_nex_reload_time - 1;
32         ATTACK_FINISHED(self) = t;
33         w_ready();
34 }
35
36 void W_Nex_Reload()
37 {
38         // return if reloading is disabled for this weapon
39         if(!autocvar_g_balance_nex_reload_ammo)
40                 return;
41
42         if(!W_ReloadCheck(self.ammo_cells, min(autocvar_g_balance_nex_primary_ammo, autocvar_g_balance_nex_secondary_ammo)))
43                 return;
44
45         float t;
46
47         sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
48
49         t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_nex_reload_time + 1;
50         ATTACK_FINISHED(self) = t;
51
52         weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_nex_reload_time, W_Nex_ReloadedAndReady);
53
54         self.old_clip_load = self.clip_load;
55         self.clip_load = -1;
56 }
57
58 void SendCSQCNexBeamParticle(float charge) {
59         vector v;
60         v = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
61         WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
62         WriteByte(MSG_BROADCAST, TE_CSQC_NEXGUNBEAMPARTICLE);
63         WriteCoord(MSG_BROADCAST, w_shotorg_x);
64         WriteCoord(MSG_BROADCAST, w_shotorg_y);
65         WriteCoord(MSG_BROADCAST, w_shotorg_z);
66         WriteCoord(MSG_BROADCAST, v_x);
67         WriteCoord(MSG_BROADCAST, v_y);
68         WriteCoord(MSG_BROADCAST, v_z);
69         WriteByte(MSG_BROADCAST, bound(0, 255 * charge, 255));
70 }
71
72 void W_Nex_Attack (float issecondary)
73 {
74         float mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, myammo, charge;
75         if(issecondary)
76         {
77                 mydmg = autocvar_g_balance_nex_secondary_damage;
78                 myforce = autocvar_g_balance_nex_secondary_force;
79                 mymindist = autocvar_g_balance_nex_secondary_damagefalloff_mindist;
80                 mymaxdist = autocvar_g_balance_nex_secondary_damagefalloff_maxdist;
81                 myhalflife = autocvar_g_balance_nex_secondary_damagefalloff_halflife;
82                 myforcehalflife = autocvar_g_balance_nex_secondary_damagefalloff_forcehalflife;
83                 myammo = autocvar_g_balance_nex_secondary_ammo;
84         }
85         else
86         {
87                 mydmg = autocvar_g_balance_nex_primary_damage;
88                 myforce = autocvar_g_balance_nex_primary_force;
89                 mymindist = autocvar_g_balance_nex_primary_damagefalloff_mindist;
90                 mymaxdist = autocvar_g_balance_nex_primary_damagefalloff_maxdist;
91                 myhalflife = autocvar_g_balance_nex_primary_damagefalloff_halflife;
92                 myforcehalflife = autocvar_g_balance_nex_primary_damagefalloff_forcehalflife;
93                 myammo = autocvar_g_balance_nex_primary_ammo;
94         }
95
96         float flying;
97         flying = IsFlying(self); // do this BEFORE to make the trace values from FireRailgunBullet last
98
99         if(autocvar_g_balance_nex_charge)
100         {
101                 charge = autocvar_g_balance_nex_charge_mindmg / mydmg + (1 - autocvar_g_balance_nex_charge_mindmg / mydmg) * self.nex_charge;
102                 self.nex_charge *= autocvar_g_balance_nex_charge_shot_multiplier; // do this AFTER setting mydmg/myforce
103                 // O RLY? -- divVerent
104                 // YA RLY -- FruitieX
105         }
106         else
107                 charge = 1;
108         mydmg *= charge;
109         myforce *= charge;
110
111         W_SetupShot (self, TRUE, 5, "weapons/nexfire.wav", CHAN_WEAPON, mydmg);
112         if(charge > autocvar_g_balance_nex_charge_limit && autocvar_g_balance_nex_charge_limit) // if the Nex is overcharged, we play an extra sound
113         {
114                 sound (self, CHAN_WEAPON2, "weapons/nexcharge.wav", VOL_BASE * (charge - 0.5 * autocvar_g_balance_nex_charge_limit) / (1 - 0.5 * autocvar_g_balance_nex_charge_limit), ATTN_NORM);
115         }
116
117         yoda = 0;
118         FireRailgunBullet (w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, mydmg, myforce, mymindist, mymaxdist, myhalflife, myforcehalflife, WEP_NEX);
119
120         if(yoda && flying)
121                 AnnounceTo(self, "yoda");
122
123         //beam and muzzle flash done on client
124         SendCSQCNexBeamParticle(charge);
125
126         // flash and burn the wall
127         if (trace_ent.solid == SOLID_BSP && !(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
128                 Damage_DamageInfo(trace_endpos, mydmg, 0, 0, myforce * w_shotdir, WEP_NEX, self);
129
130         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
131         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
132         {
133                 if(autocvar_g_balance_nex_reload_ammo)
134                 {
135                         self.clip_load -= myammo;
136                         self.nex_load = self.clip_load;
137                 }
138                 else
139                         self.ammo_cells -= myammo;
140         }
141 }
142
143 void spawnfunc_weapon_nex (void); // defined in t_items.qc
144
145 .float nex_chargepool_pauseregen_finished;
146 float w_nex(float req)
147 {
148         float dt;
149         if (req == WR_AIM)
150         {
151                 self.BUTTON_ATCK = bot_aim(1000000, 0, 1, FALSE);
152                 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 1, FALSE);
153         }
154         else if (req == WR_THINK)
155         {
156                 if(autocvar_g_balance_nex_charge && self.nex_charge < autocvar_g_balance_nex_charge_limit)
157                         self.nex_charge = min(1, self.nex_charge + autocvar_g_balance_nex_charge_rate * frametime / W_TICSPERFRAME);
158
159                 if(autocvar_g_balance_nex_secondary_chargepool)
160                         if(self.nex_chargepool_ammo < 1)
161                         {
162                                 if(self.nex_chargepool_pauseregen_finished < time)
163                                         self.nex_chargepool_ammo = min(1, self.nex_chargepool_ammo + autocvar_g_balance_nex_secondary_chargepool_regen * frametime / W_TICSPERFRAME);
164                                 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_nex_secondary_chargepool_pause_health_regen);
165                         }
166
167                 if(autocvar_g_balance_nex_reload_ammo && self.clip_load < min(autocvar_g_balance_nex_primary_ammo, autocvar_g_balance_nex_secondary_ammo)) // forced reload
168                         W_Nex_Reload();
169                 else
170                 {
171                         if (self.BUTTON_ATCK)
172                         {
173                                 if (weapon_prepareattack(0, autocvar_g_balance_nex_primary_refire))
174                                 {
175                                         W_Nex_Attack(0);
176                                         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_nex_primary_animtime, w_ready);
177                                 }
178                         }
179                         if ((autocvar_g_balance_nex_secondary_charge && !autocvar_g_balance_nex_secondary) ? self.BUTTON_ZOOM : self.BUTTON_ATCK2)
180                         {
181                                 if(autocvar_g_balance_nex_secondary_charge)
182                                 {
183                                         self.nex_charge_rottime = time + autocvar_g_balance_nex_charge_rot_pause;
184                                         dt = frametime / W_TICSPERFRAME;
185
186                                         if(self.nex_charge < 1)
187                                         {
188                                                 if(autocvar_g_balance_nex_secondary_chargepool)
189                                                 {
190                                                         if(autocvar_g_balance_nex_secondary_ammo)
191                                                         {
192                                                                 // always deplete if secondary is held
193                                                                 self.nex_chargepool_ammo = max(0, self.nex_chargepool_ammo - autocvar_g_balance_nex_secondary_ammo * dt);
194
195                                                                 dt = min(dt, (1 - self.nex_charge) / autocvar_g_balance_nex_secondary_charge_rate);
196                                                                 self.nex_chargepool_pauseregen_finished = time + autocvar_g_balance_nex_secondary_chargepool_pause_regen;
197                                                                 dt = min(dt, self.nex_chargepool_ammo);
198                                                                 dt = max(0, dt);
199
200                                                                 self.nex_charge += dt * autocvar_g_balance_nex_secondary_charge_rate;
201                                                         }
202                                                 }
203
204                                                 else if(autocvar_g_balance_nex_secondary_ammo)
205                                                 {
206                                                         if(self.BUTTON_ATCK2) // only eat ammo when the button is pressed
207                                                         {
208                                                                 dt = min(dt, (1 - self.nex_charge) / autocvar_g_balance_nex_secondary_charge_rate);
209                                                                 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
210                                                                 {
211                                                                         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
212                                                                         if(autocvar_g_balance_nex_reload_ammo)
213                                                                         {
214                                                                                 dt = min(dt, (self.clip_load - autocvar_g_balance_nex_primary_ammo) / autocvar_g_balance_nex_secondary_ammo);
215                                                                                 dt = max(0, dt);
216                                                                                 if(dt > 0)
217                                                                                 {
218                                                                                         self.clip_load = max(autocvar_g_balance_nex_secondary_ammo, self.clip_load - autocvar_g_balance_nex_secondary_ammo * dt);
219                                                                                 }
220                                                                                 self.nex_load = self.clip_load;
221                                                                         }
222                                                                         else
223                                                                         {
224                                                                                 dt = min(dt, (self.ammo_cells - autocvar_g_balance_nex_primary_ammo) / autocvar_g_balance_nex_secondary_ammo);
225                                                                                 dt = max(0, dt);
226                                                                                 if(dt > 0)
227                                                                                 {
228                                                                                         self.ammo_cells = max(autocvar_g_balance_nex_secondary_ammo, self.ammo_cells - autocvar_g_balance_nex_secondary_ammo * dt);
229                                                                                 }
230                                                                         }
231                                                                 }
232                                                                 self.nex_charge += dt * autocvar_g_balance_nex_secondary_charge_rate;
233                                                         }
234                                                 }
235
236                                                 else
237                                                 {
238                                                         dt = min(dt, (1 - self.nex_charge) / autocvar_g_balance_nex_secondary_charge_rate);
239                                                         self.nex_charge += dt * autocvar_g_balance_nex_secondary_charge_rate;
240                                                 }
241                                         }
242                                 }
243                                 else if(autocvar_g_balance_nex_secondary)
244                                 {
245                                         if (weapon_prepareattack(0, autocvar_g_balance_nex_secondary_refire))
246                                         {
247                                                 W_Nex_Attack(1);
248                                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_nex_secondary_animtime, w_ready);
249                                         }
250                                 }
251                         }
252                 }
253
254                 if(autocvar_g_balance_nex_charge)
255                 {
256                         self.weaponentity_glowmod_x = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_half * min(1, self.nex_charge / autocvar_g_balance_nex_charge_limit);
257                         self.weaponentity_glowmod_y = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_half * min(1, self.nex_charge / autocvar_g_balance_nex_charge_limit);
258                         self.weaponentity_glowmod_z = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_half * min(1, self.nex_charge / autocvar_g_balance_nex_charge_limit);
259
260                         if(self.nex_charge > autocvar_g_balance_nex_charge_limit)
261                         {
262                                 self.weaponentity_glowmod_x = self.weaponentity_glowmod_x + autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_full * (self.nex_charge - autocvar_g_balance_nex_charge_limit) / (1 - autocvar_g_balance_nex_charge_limit);
263                                 self.weaponentity_glowmod_y = self.weaponentity_glowmod_y + autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_full * (self.nex_charge - autocvar_g_balance_nex_charge_limit) / (1 - autocvar_g_balance_nex_charge_limit);
264                                 self.weaponentity_glowmod_z = self.weaponentity_glowmod_z + autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_full * (self.nex_charge - autocvar_g_balance_nex_charge_limit) / (1 - autocvar_g_balance_nex_charge_limit);
265                         }
266                 }
267
268         if(self.wish_reload)
269         {
270             if(self.switchweapon == self.weapon)
271             {
272                 if(self.weaponentity.state == WS_READY)
273                 {
274                     self.wish_reload = 0;
275                     W_Nex_Reload();
276                 }
277             }
278         }
279         }
280         else if (req == WR_PRECACHE)
281         {
282                 precache_model ("models/nexflash.md3");
283                 precache_model ("models/weapons/g_nex.md3");
284                 precache_model ("models/weapons/v_nex.md3");
285                 precache_model ("models/weapons/h_nex.iqm");
286                 precache_sound ("weapons/nexfire.wav");
287                 precache_sound ("weapons/nexcharge.wav");
288                 precache_sound ("weapons/nexwhoosh1.wav");
289                 precache_sound ("weapons/nexwhoosh2.wav");
290                 precache_sound ("weapons/nexwhoosh3.wav");
291                 precache_sound ("weapons/reload.wav");
292         }
293         else if (req == WR_SETUP)
294         {
295                 weapon_setup(WEP_NEX);
296                 W_Nex_SetAmmoCounter();
297         }
298         else if (req == WR_CHECKAMMO1)
299         {
300                 if(autocvar_g_balance_nex_reload_ammo)
301                         return self.clip_load >= autocvar_g_balance_nex_primary_ammo;
302                 else
303                         return self.ammo_cells >= autocvar_g_balance_nex_primary_ammo;
304         }
305         else if (req == WR_CHECKAMMO2)
306         {
307                 if(autocvar_g_balance_nex_reload_ammo)
308                         return self.clip_load >= autocvar_g_balance_nex_primary_ammo; // don't allow charging if we don't have enough ammo
309                 else
310                         return self.ammo_cells >= autocvar_g_balance_nex_primary_ammo; // don't allow charging if we don't have enough ammo
311         }
312         else if (req == WR_RELOAD)
313         {
314                 W_Nex_Reload();
315         }
316         else if (req == WR_SWITCHABLE)
317         {
318                 // checks if this weapon can be switched to, when reloading is enabled
319                 // returns true if there's either enough load in the weapon to use it,
320                 // or we have enough ammo to reload the weapon to a usable point
321                 float ammo_amount;
322                 ammo_amount = min(autocvar_g_balance_nex_primary_ammo, autocvar_g_balance_nex_secondary_ammo);
323                 return self.nex_load >= ammo_amount || self.ammo_cells >= ammo_amount;
324         }
325
326         return TRUE;
327 };
328 #endif
329 #ifdef CSQC
330 float w_nex(float req)
331 {
332         if(req == WR_IMPACTEFFECT)
333         {
334                 vector org2;
335                 org2 = w_org + w_backoff * 6;
336                 pointparticles(particleeffectnum("nex_impact"), org2, '0 0 0', 1);
337                 if(!w_issilent)
338                         sound(self, CHAN_PROJECTILE, "weapons/neximpact.wav", VOL_BASE, ATTN_NORM);
339         }
340         else if(req == WR_PRECACHE)
341         {
342                 precache_sound("weapons/neximpact.wav");
343         }
344         else if (req == WR_SUICIDEMESSAGE)
345                 w_deathtypestring = "%s did the impossible";
346         else if (req == WR_KILLMESSAGE)
347                 w_deathtypestring = "%s has been vaporized by %s";
348         return TRUE;
349 }
350 #endif
351 #endif