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