]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_electro.qc
Reload if we don't have ammo for a certain attack. Prevents situations in which you...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_electro.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(ELECTRO, w_electro, IT_CELLS, 5, WEP_FLAG_NORMAL | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "electro", "electro", _("Electro"));
3 #else
4 #ifdef SVQC
5 .float electro_count;
6 .float electro_secondarytime;
7
8 .float electro_load;
9
10 void W_Electro_SetAmmoCounter()
11 {
12         // set clip_load to the weapon we have switched to, if the gun uses reloading
13         if(!autocvar_g_balance_electro_reload_ammo)
14                 self.clip_load = 0; // also keeps crosshair ammo from displaying
15         else
16         {
17                 self.clip_load = self.electro_load;
18                 self.clip_size = autocvar_g_balance_electro_reload_ammo; // for the crosshair ammo display
19         }
20 }
21
22 void W_Electro_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_electro_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.electro_load = self.clip_load;
34
35         t = ATTACK_FINISHED(self) - autocvar_g_balance_electro_reload_time - 1;
36         ATTACK_FINISHED(self) = t;
37         w_ready();
38 }
39
40 void W_Electro_Reload()
41 {
42         // return if reloading is disabled for this weapon
43         if(!autocvar_g_balance_electro_reload_ammo)
44                 return;
45
46         if(!W_ReloadCheck(self.ammo_cells, min(autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_secondary_ammo)))
47                 return;
48
49         float t;
50
51         sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
52
53         t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_electro_reload_time + 1;
54         ATTACK_FINISHED(self) = t;
55
56         weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_electro_reload_time, W_Electro_ReloadedAndReady);
57
58         self.old_clip_load = self.clip_load;
59         self.clip_load = -1;
60 }
61
62 void W_Plasma_Explode_Combo (void);
63
64 void W_Plasma_TriggerCombo(vector org, float rad, entity own)
65 {
66         local entity e;
67         e = WarpZone_FindRadius(org, rad, TRUE);
68         while (e)
69         {
70                 if (e.classname == "plasma")
71                 {
72                         // change owner to whoever caused the combo explosion
73                         e.owner = own;
74                         e.takedamage = DAMAGE_NO;
75                         e.classname = "plasma_chain";
76                         e.think = W_Plasma_Explode_Combo;
77                         e.nextthink = time + vlen(e.WarpZone_findradius_dist) / autocvar_g_balance_electro_combo_speed; // delay combo chains, looks cooler
78                 }
79                 e = e.chain;
80         }
81 }
82
83 void W_Plasma_Explode (void)
84 {
85         if(other.takedamage == DAMAGE_AIM)
86                 if(other.classname == "player")
87                         if(IsDifferentTeam(self.owner, other))
88                                 if(other.deadflag == DEAD_NO)
89                                         if(IsFlying(other))
90                                                 AnnounceTo(self.owner, "electrobitch");
91
92         self.event_damage = SUB_Null;
93         self.takedamage = DAMAGE_NO;
94         if (self.movetype == MOVETYPE_BOUNCE)
95         {
96                 RadiusDamage (self, self.owner, autocvar_g_balance_electro_secondary_damage, autocvar_g_balance_electro_secondary_edgedamage, autocvar_g_balance_electro_secondary_radius, world, autocvar_g_balance_electro_secondary_force, self.projectiledeathtype, other);
97         }
98         else
99         {
100                 W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_primary_comboradius, self.owner);
101                 RadiusDamage (self, self.owner, autocvar_g_balance_electro_primary_damage, autocvar_g_balance_electro_primary_edgedamage, autocvar_g_balance_electro_primary_radius, world, autocvar_g_balance_electro_primary_force, self.projectiledeathtype, other);
102         }
103
104         remove (self);
105 }
106
107 void W_Plasma_Explode_Combo (void)
108 {
109         W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_combo_comboradius, self.owner);
110
111         self.event_damage = SUB_Null;
112         RadiusDamage (self, self.owner, autocvar_g_balance_electro_combo_damage, autocvar_g_balance_electro_combo_edgedamage, autocvar_g_balance_electro_combo_radius, world, autocvar_g_balance_electro_combo_force, WEP_ELECTRO | HITTYPE_BOUNCE, world); // use THIS type for a combo because primary can't bounce
113         remove (self);
114 }
115
116 void W_Plasma_Touch (void)
117 {
118         //self.velocity = self.velocity  * 0.1;
119
120         PROJECTILE_TOUCH;
121         if (other.takedamage == DAMAGE_AIM) {
122                 W_Plasma_Explode ();
123         } else {
124                 //UpdateCSQCProjectile(self);
125                 spamsound (self, CHAN_PROJECTILE, "weapons/electro_bounce.wav", VOL_BASE, ATTN_NORM);
126                 self.projectiledeathtype |= HITTYPE_BOUNCE;
127         }
128 }
129
130 void W_Plasma_TouchExplode (void)
131 {
132         PROJECTILE_TOUCH;
133         W_Plasma_Explode ();
134 }
135
136 void W_Plasma_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
137 {
138         if(self.health <= 0)
139                 return;
140         // note: combos are usually triggered by W_Plasma_TriggerCombo, not damage
141         self.health = self.health - damage;
142         if (self.health <= 0)
143         {
144                 self.takedamage = DAMAGE_NO;
145                 self.nextthink = time;
146                 if (inflictor.classname == "plasma_chain" || inflictor.classname == "plasma_prim")
147                 {
148                         // change owner to whoever caused the combo explosion
149                         self.owner = inflictor.owner;
150                         self.classname = "plasma_chain";
151                         self.think = W_Plasma_Explode_Combo;
152                         self.nextthink = time + min(autocvar_g_balance_electro_combo_radius, vlen(self.origin - inflictor.origin)) / autocvar_g_balance_electro_combo_speed; // delay combo chains, looks cooler
153                                 //                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bounding the length, because inflictor may be in a galaxy far far away (warpzones)
154                 }
155                 else
156                 {
157                         self.use = W_Plasma_Explode;
158                         self.think = adaptor_think2use; // not _hittype_splash, as this runs "immediately"
159                 }
160         }
161 }
162
163 void W_Electro_Attack()
164 {
165         local entity proj;
166
167         // if there's not enough ammo for this attack (but we still have the weapon), reload
168         if(autocvar_g_balance_electro_reload_ammo && self.clip_load < autocvar_g_balance_electro_primary_ammo)
169         {
170                 W_Electro_Reload();
171                 return;
172         }
173
174         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
175         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
176         {
177                 if(autocvar_g_balance_electro_reload_ammo)
178                 {
179                         self.clip_load -= autocvar_g_balance_electro_primary_ammo;
180                         self.electro_load = self.clip_load;
181                 }
182                 else
183                         self.ammo_cells -= autocvar_g_balance_electro_primary_ammo;
184         }
185
186         W_SetupShot_ProjectileSize (self, '0 0 -3', '0 0 -3', FALSE, 2, "weapons/electro_fire.wav", CHAN_WEAPON, autocvar_g_balance_electro_primary_damage);
187
188         pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
189
190         proj = spawn ();
191         proj.classname = "plasma_prim";
192         proj.owner = self;
193         proj.bot_dodge = TRUE;
194         proj.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
195         proj.use = W_Plasma_Explode;
196         proj.think = adaptor_think2use_hittype_splash;
197         proj.nextthink = time + autocvar_g_balance_electro_primary_lifetime;
198         PROJECTILE_MAKETRIGGER(proj);
199         proj.projectiledeathtype = WEP_ELECTRO;
200         setorigin(proj, w_shotorg);
201
202         proj.movetype = MOVETYPE_FLY;
203         W_SETUPPROJECTILEVELOCITY(proj, g_balance_electro_primary);
204         proj.angles = vectoangles(proj.velocity);
205         proj.touch = W_Plasma_TouchExplode;
206         setsize(proj, '0 0 -3', '0 0 -3');
207         proj.flags = FL_PROJECTILE;
208
209         //sound (proj, CHAN_PAIN, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
210         //sounds bad
211
212         CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO_BEAM, TRUE);
213
214         other = proj; MUTATOR_CALLHOOK(EditProjectile);
215 }
216
217 void W_Electro_Attack2()
218 {
219         local entity proj;
220
221         // if there's not enough ammo for this attack (but we still have the weapon), reload
222         if(autocvar_g_balance_electro_reload_ammo && self.clip_load < autocvar_g_balance_electro_secondary_ammo)
223         {
224                 W_Electro_Reload();
225                 return;
226         }
227
228         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
229         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
230         {
231                 if(autocvar_g_balance_electro_reload_ammo)
232                 {
233                         self.clip_load -= autocvar_g_balance_electro_secondary_ammo;
234                         self.electro_load = self.clip_load;
235                 }
236                 else
237                         self.ammo_cells -= autocvar_g_balance_electro_secondary_ammo;
238         }
239
240         W_SetupShot_ProjectileSize (self, '0 0 -4', '0 0 -4', FALSE, 2, "weapons/electro_fire2.wav", CHAN_WEAPON, autocvar_g_balance_electro_secondary_damage);
241
242         w_shotdir = v_forward; // no TrueAim for grenades please
243
244         pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
245
246         proj = spawn ();
247         proj.classname = "plasma";
248         proj.owner = self;
249         proj.use = W_Plasma_Explode;
250         proj.think = adaptor_think2use_hittype_splash;
251         proj.bot_dodge = TRUE;
252         proj.bot_dodgerating = autocvar_g_balance_electro_secondary_damage;
253         proj.nextthink = time + autocvar_g_balance_electro_secondary_lifetime;
254         PROJECTILE_MAKETRIGGER(proj);
255         proj.projectiledeathtype = WEP_ELECTRO | HITTYPE_SECONDARY;
256         setorigin(proj, w_shotorg);
257
258         //proj.glow_size = 50;
259         //proj.glow_color = 45;
260         proj.movetype = MOVETYPE_BOUNCE;
261         W_SETUPPROJECTILEVELOCITY_UP(proj, g_balance_electro_secondary);
262         proj.touch = W_Plasma_Touch;
263         setsize(proj, '0 0 -4', '0 0 -4');
264         proj.takedamage = DAMAGE_YES;
265         proj.damageforcescale = autocvar_g_balance_electro_secondary_damageforcescale;
266         proj.health = autocvar_g_balance_electro_secondary_health;
267         proj.event_damage = W_Plasma_Damage;
268         proj.flags = FL_PROJECTILE;
269
270         proj.bouncefactor = autocvar_g_balance_electro_secondary_bouncefactor;
271         proj.bouncestop = autocvar_g_balance_electro_secondary_bouncestop;
272
273 #if 0
274         entity p2;
275         p2 = spawn();
276         copyentity(proj, p2);
277         setmodel(p2, "models/ebomb.mdl");
278         setsize(p2, proj.mins, proj.maxs);
279 #endif
280
281         CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO, FALSE); // no culling, it has sound
282
283         other = proj; MUTATOR_CALLHOOK(EditProjectile);
284 }
285
286 .vector hook_start, hook_end;
287 float lgbeam_send(entity to, float sf)
288 {
289         WriteByte(MSG_ENTITY, ENT_CLIENT_LGBEAM);
290         sf = sf & 0x7F;
291         if(sound_allowed(MSG_BROADCAST, self.owner))
292                 sf |= 0x80;
293         WriteByte(MSG_ENTITY, sf);
294         if(sf & 1)
295         {
296                 WriteByte(MSG_ENTITY, num_for_edict(self.owner));
297                 WriteCoord(MSG_ENTITY, autocvar_g_balance_electro_primary_range);
298         }
299         if(sf & 2)
300         {
301                 WriteCoord(MSG_ENTITY, self.hook_start_x);
302                 WriteCoord(MSG_ENTITY, self.hook_start_y);
303                 WriteCoord(MSG_ENTITY, self.hook_start_z);
304         }
305         if(sf & 4)
306         {
307                 WriteCoord(MSG_ENTITY, self.hook_end_x);
308                 WriteCoord(MSG_ENTITY, self.hook_end_y);
309                 WriteCoord(MSG_ENTITY, self.hook_end_z);
310         }
311         return TRUE;
312 }
313 .entity lgbeam;
314 .float prevlgfire;
315 float lgbeam_checkammo()
316 {
317         if(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
318                 return TRUE;
319         else if(autocvar_g_balance_electro_reload_ammo)
320                 return self.owner.clip_load > 0;
321         else
322                 return self.owner.ammo_cells > 0;
323 }
324
325 void lgbeam_think()
326 {
327         self.owner.prevlgfire = time;
328         if (self != self.owner.lgbeam)
329         {
330                 remove(self);
331                 return;
332         }
333
334         if (self.owner.weaponentity.state != WS_INUSE || !lgbeam_checkammo() || self.owner.deadflag != DEAD_NO || !self.owner.BUTTON_ATCK || self.owner.freezetag_frozen)
335         {
336                 if(self == self.owner.lgbeam)
337                         self.owner.lgbeam = world;
338                 remove(self);
339                 return;
340         }
341
342         self.nextthink = time;
343
344         makevectors(self.owner.v_angle);
345
346         float dt, f;
347         dt = frametime;
348         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
349         if not(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
350         {
351                 if(autocvar_g_balance_electro_primary_ammo)
352                 {
353                         if(autocvar_g_balance_electro_reload_ammo)
354                         {
355                                 dt = min(dt, self.owner.clip_load / autocvar_g_balance_electro_primary_ammo);
356                                 self.owner.clip_load = max(0, self.owner.clip_load - autocvar_g_balance_electro_primary_ammo * frametime);
357                                 self.owner.electro_load = self.owner.clip_load;
358                         }
359                         else
360                         {
361                                 dt = min(dt, self.owner.ammo_cells / autocvar_g_balance_electro_primary_ammo);
362                                 self.owner.ammo_cells = max(0, self.owner.ammo_cells - autocvar_g_balance_electro_primary_ammo * frametime);
363                         }
364                 }
365         }
366
367         W_SetupShot_Range(self.owner, TRUE, 0, "", 0, autocvar_g_balance_electro_primary_damage * dt, autocvar_g_balance_electro_primary_range);
368         WarpZone_traceline_antilag(self.owner, w_shotorg, w_shotend, MOVE_NORMAL, self.owner, ANTILAG_LATENCY(self.owner));
369
370         // apply the damage
371         if(trace_ent)
372         {
373                 vector force;
374                 force = w_shotdir * autocvar_g_balance_electro_primary_force + '0 0 1' * autocvar_g_balance_electro_primary_force_up;
375
376                 f = ExponentialFalloff(autocvar_g_balance_electro_primary_falloff_mindist, autocvar_g_balance_electro_primary_falloff_maxdist, autocvar_g_balance_electro_primary_falloff_halflifedist, vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos) - w_shotorg));
377
378                 if(accuracy_isgooddamage(self.owner, trace_ent))
379                         accuracy_add(self.owner, WEP_ELECTRO, 0, autocvar_g_balance_electro_primary_damage * dt * f);
380                 Damage (trace_ent, self.owner, self.owner, autocvar_g_balance_electro_primary_damage * dt * f, WEP_ELECTRO, trace_endpos, force * dt);
381         }
382         W_Plasma_TriggerCombo(trace_endpos, autocvar_g_balance_electro_primary_comboradius, self.owner);
383
384         // draw effect
385         if(w_shotorg != self.hook_start)
386         {
387                 self.SendFlags |= 2;
388                 self.hook_start = w_shotorg;
389         }
390         if(w_shotend != self.hook_end)
391         {
392                 self.SendFlags |= 4;
393                 self.hook_end = w_shotend;
394         }
395 }
396
397 // experimental lightning gun
398 void W_Electro_Attack3 (void)
399 {
400         // only play fire sound if 0.5 sec has passed since player let go the fire button
401         if(time - self.prevlgfire > 0.5)
402                 sound (self, CHAN_WEAPON, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
403
404         entity beam, oldself;
405
406         self.lgbeam = beam = spawn();
407         beam.classname = "lgbeam";
408         beam.solid = SOLID_NOT;
409         beam.think = lgbeam_think;
410         beam.owner = self;
411         beam.movetype = MOVETYPE_NONE;
412         beam.shot_spread = 0;
413         beam.bot_dodge = TRUE;
414         beam.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
415         Net_LinkEntity(beam, FALSE, 0, lgbeam_send);
416
417         oldself = self;
418         self = beam;
419         self.think();
420         self = oldself;
421 }
422
423 void ElectroInit()
424 {
425         weapon_action(WEP_ELECTRO, WR_PRECACHE);
426         electro_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 1);
427         electro_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 2);
428         electro_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 3);
429         electro_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 4);
430 }
431
432 void spawnfunc_weapon_electro (void)
433 {
434         weapon_defaultspawnfunc(WEP_ELECTRO);
435 }
436
437 void w_electro_checkattack()
438 {
439         if(self.electro_count > 1)
440         if(self.BUTTON_ATCK2)
441         if(weapon_prepareattack(1, -1))
442         {
443                 W_Electro_Attack2();
444                 self.electro_count -= 1;
445                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
446                 return;
447         }
448
449         w_ready();
450 }
451
452 .float bot_secondary_electromooth;
453 .float BUTTON_ATCK_prev;
454 float w_electro(float req)
455 {
456         if (req == WR_AIM)
457         {
458                 self.BUTTON_ATCK=FALSE;
459                 self.BUTTON_ATCK2=FALSE;
460                 if(vlen(self.origin-self.enemy.origin) > 1000)
461                         self.bot_secondary_electromooth = 0;
462                 if(self.bot_secondary_electromooth == 0)
463                 {
464                         float shoot;
465
466                         if(autocvar_g_balance_electro_primary_speed)
467                                 shoot = bot_aim(autocvar_g_balance_electro_primary_speed, 0, autocvar_g_balance_electro_primary_lifetime, FALSE);
468                         else
469                                 shoot = bot_aim(1000000, 0, 0.001, FALSE);
470
471                         if(shoot)
472                         {
473                                 self.BUTTON_ATCK = TRUE;
474                                 if(random() < 0.01) self.bot_secondary_electromooth = 1;
475                         }
476                 }
477                 else
478                 {
479                         if(bot_aim(autocvar_g_balance_electro_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_electro_secondary_lifetime, TRUE))
480                         {
481                                 self.BUTTON_ATCK2 = TRUE;
482                                 if(random() < 0.03) self.bot_secondary_electromooth = 0;
483                         }
484                 }
485         }
486         else if (req == WR_THINK)
487         {
488                 if(autocvar_g_balance_electro_reload_ammo && self.clip_load < min(autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_secondary_ammo)) // forced reload
489                         W_Electro_Reload();
490                 else if (self.BUTTON_ATCK)
491                 {
492                         if(autocvar_g_balance_electro_lightning)
493                                 if(self.BUTTON_ATCK_prev)
494                                 {
495                                         // prolong the animtime while the gun is being fired
496                                         if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
497                                                 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_electro_primary_animtime, w_ready);
498                                         else
499                                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
500                                 }
501                         if (weapon_prepareattack(0, (autocvar_g_balance_electro_lightning ? 0 : autocvar_g_balance_electro_primary_refire)))
502                         {
503                                 if(autocvar_g_balance_electro_lightning)
504                                 {
505                                         if ((!self.lgbeam) || wasfreed(self.lgbeam))
506                                         {
507                                                 W_Electro_Attack3();
508                                         }
509                                         if(!self.BUTTON_ATCK_prev)
510                                         {
511                                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
512                                                 self.BUTTON_ATCK_prev = 1;
513                                         }
514                                 }
515                                 else
516                                 {
517                                         W_Electro_Attack();
518                                         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
519                                 }
520                         }
521                 } else {
522                         if(autocvar_g_balance_electro_lightning)
523                         {
524                                 if (self.BUTTON_ATCK_prev != 0)
525                                 {
526                                         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
527                                         ATTACK_FINISHED(self) = time + autocvar_g_balance_electro_primary_refire * W_WeaponRateFactor();
528                                 }
529                                 self.BUTTON_ATCK_prev = 0;
530                         }
531
532                         if (self.BUTTON_ATCK2)
533                         {
534                                 if (time >= self.electro_secondarytime)
535                                 if (weapon_prepareattack(1, autocvar_g_balance_electro_secondary_refire))
536                                 {
537                                         W_Electro_Attack2();
538                                         self.electro_count = autocvar_g_balance_electro_secondary_count;
539                                         weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
540                                         self.electro_secondarytime = time + autocvar_g_balance_electro_secondary_refire2 * W_WeaponRateFactor();
541                                 }
542                         }
543                 }
544
545         if(self.wish_reload)
546         {
547             if(self.switchweapon == self.weapon)
548             {
549                 if(self.weaponentity.state == WS_READY)
550                 {
551                     self.wish_reload = 0;
552                     W_Electro_Reload();
553                 }
554             }
555         }
556         }
557         else if (req == WR_PRECACHE)
558         {
559                 precache_model ("models/weapons/g_electro.md3");
560                 precache_model ("models/weapons/v_electro.md3");
561                 precache_model ("models/weapons/h_electro.iqm");
562                 precache_sound ("weapons/electro_bounce.wav");
563                 precache_sound ("weapons/electro_fire.wav");
564                 precache_sound ("weapons/electro_fire2.wav");
565                 precache_sound ("weapons/electro_impact.wav");
566                 precache_sound ("weapons/electro_impact_combo.wav");
567                 if(autocvar_g_balance_electro_lightning)
568                 {
569                         precache_sound ("weapons/lgbeam_fire.wav");
570                 }
571         }
572         else if (req == WR_SETUP)
573         {
574                 weapon_setup(WEP_ELECTRO);
575                 W_Electro_SetAmmoCounter();
576         }
577         else if (req == WR_CHECKAMMO1)
578         {
579                 if(autocvar_g_balance_electro_reload_ammo)
580                 {
581                         if(autocvar_g_balance_electro_lightning)
582                                 return !autocvar_g_balance_electro_primary_ammo || (self.electro_load > 0);
583                         else
584                                 return self.electro_load >= autocvar_g_balance_electro_primary_ammo;
585                 }
586                 else
587                 {
588                         if(autocvar_g_balance_electro_lightning)
589                                 return !autocvar_g_balance_electro_primary_ammo || (self.ammo_cells > 0);
590                         else
591                                 return self.ammo_cells >= autocvar_g_balance_electro_primary_ammo;
592                 }
593         }
594         else if (req == WR_CHECKAMMO2)
595         {
596                 if(autocvar_g_balance_electro_reload_ammo)
597                         return self.electro_load >= autocvar_g_balance_electro_secondary_ammo;
598                 else
599                         return self.ammo_cells >= autocvar_g_balance_electro_secondary_ammo;
600         }
601         else if (req == WR_RESETPLAYER)
602         {
603                 self.electro_secondarytime = time;
604         }
605         else if (req == WR_RELOAD)
606         {
607                 W_Shotgun_Reload();
608         }
609         return TRUE;
610 };
611 #endif
612 #ifdef CSQC
613 float w_electro(float req)
614 {
615         if(req == WR_IMPACTEFFECT)
616         {
617                 vector org2;
618                 org2 = w_org + w_backoff * 6;
619                 if(w_deathtype & HITTYPE_SECONDARY)
620                 {
621                         pointparticles(particleeffectnum("electro_ballexplode"), org2, '0 0 0', 1);
622                         if(!w_issilent)
623                                 sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
624                 }
625                 else
626                 {
627                         if(w_deathtype & HITTYPE_BOUNCE)
628                         {
629                                 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
630                                 pointparticles(particleeffectnum("electro_combo"), org2, '0 0 0', 1);
631                                 if(!w_issilent)
632                                         sound(self, CHAN_PROJECTILE, "weapons/electro_impact_combo.wav", VOL_BASE, ATTN_NORM);
633                         }
634                         else
635                         {
636                                 pointparticles(particleeffectnum("electro_impact"), org2, '0 0 0', 1);
637                                 if(!w_issilent)
638                                         sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
639                         }
640                 }
641         }
642         else if(req == WR_PRECACHE)
643         {
644                 precache_sound("weapons/electro_impact.wav");
645                 precache_sound("weapons/electro_impact_combo.wav");
646         }
647         else if (req == WR_SUICIDEMESSAGE)
648         {
649                 if(w_deathtype & HITTYPE_SECONDARY)
650                         w_deathtypestring = "%s could not remember where they put plasma";
651                 else
652                         w_deathtypestring = "%s played with plasma";
653         }
654         else if (req == WR_KILLMESSAGE)
655         {
656                 if(w_deathtype & HITTYPE_SECONDARY)
657                 {
658                         if(w_deathtype & HITTYPE_SPLASH) // unchecked: BOUNCE
659                                 w_deathtypestring = "%s just noticed %s's blue ball";
660                         else // unchecked: BOUNCE
661                                 w_deathtypestring = "%s got in touch with %s's blue ball";
662                 }
663                 else
664                 {
665                         if(w_deathtype & HITTYPE_BOUNCE) // combo
666                                 w_deathtypestring = "%s felt the electrifying air of %s's combo";
667                         else if(w_deathtype & HITTYPE_SPLASH)
668                                 w_deathtypestring = "%s got too close to %s's blue beam";
669                         else
670                                 w_deathtypestring = "%s was blasted by %s's blue beam";
671                 }
672         }
673         return TRUE;
674 }
675 #endif
676 #endif