3 /* WEP_##id */ ELECTRO,
4 /* function */ w_electro,
5 /* ammotype */ IT_CELLS,
7 /* flags */ WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH,
8 /* rating */ BOT_PICKUP_RATING_MID,
10 /* netname */ "electro",
11 /* fullname */ _("Electro")
16 vector electro_shotorigin[4];
17 var float autocvar_g_balance_electro_combo_comboradius_thruwall = 200;
21 void spawnfunc_weapon_electro() { weapon_defaultspawnfunc(WEP_ELECTRO); }
24 .float electro_secondarytime;
26 void W_Plasma_Explode_Combo (void);
28 void W_Plasma_TriggerCombo(vector org, float rad, entity own)
31 e = WarpZone_FindRadius(org, rad, !autocvar_g_balance_electro_combo_comboradius_thruwall);
34 if (e.classname == "plasma")
36 // change owner to whoever caused the combo explosion
37 WarpZone_TraceLine(org, e.origin, MOVE_NOMONSTERS, e);
39 if((trace_fraction == 1) || (autocvar_g_balance_electro_combo_comboradius_thruwall >= vlen(e.WarpZone_findradius_dist)))
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
52 void W_Plasma_Explode (void)
54 if(other.takedamage == DAMAGE_AIM)
56 if(DIFF_TEAM(self.realowner, other))
57 if(other.deadflag == DEAD_NO)
59 Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_ELECTROBITCH);
61 self.event_damage = func_null;
62 self.takedamage = DAMAGE_NO;
63 if (self.movetype == MOVETYPE_BOUNCE)
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);
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);
76 void W_Plasma_Explode_Combo (void)
78 W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_combo_comboradius, self.realowner);
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
86 void W_Plasma_Touch (void)
88 //self.velocity = self.velocity * 0.1;
91 if (other.takedamage == DAMAGE_AIM) {
94 //UpdateCSQCProjectile(self);
95 spamsound (self, CH_SHOTS, "weapons/electro_bounce.wav", VOL_BASE, ATTEN_NORM);
96 self.projectiledeathtype |= HITTYPE_BOUNCE;
100 void W_Plasma_TouchExplode (void)
106 void W_Plasma_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
111 // note: combos are usually triggered by W_Plasma_TriggerCombo, not damage
112 float is_combo = (inflictor.classname == "plasma_chain" || inflictor.classname == "plasma_prim");
114 if (!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, (is_combo ? 1 : -1)))
115 return; // g_projectiles_damage says to halt
117 self.health = self.health - damage;
118 if (self.health <= 0)
120 self.takedamage = DAMAGE_NO;
121 self.nextthink = time;
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)
133 self.use = W_Plasma_Explode;
134 self.think = adaptor_think2use; // not _hittype_splash, as this runs "immediately"
139 void W_Electro_Attack()
143 W_DecreaseAmmo(ammo_cells, autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_reload_ammo);
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);
147 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
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);
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;
169 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO_BEAM, TRUE);
171 other = proj; MUTATOR_CALLHOOK(EditProjectile);
174 void W_Electro_Attack2()
178 W_DecreaseAmmo(ammo_cells, autocvar_g_balance_electro_secondary_ammo, autocvar_g_balance_electro_reload_ammo);
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);
182 w_shotdir = v_forward; // no TrueAim for grenades please
184 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
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);
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);
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;
218 copyentity(proj, p2);
219 setmodel(p2, "models/ebomb.mdl");
220 setsize(p2, proj.mins, proj.maxs);
223 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO, FALSE); // no culling, it has sound
225 other = proj; MUTATOR_CALLHOOK(EditProjectile);
228 .vector hook_start, hook_end;
229 float lgbeam_send(entity to, float sf)
231 WriteByte(MSG_ENTITY, ENT_CLIENT_ELECTRO_BEAM);
233 if(sound_allowed(MSG_BROADCAST, self.realowner))
235 WriteByte(MSG_ENTITY, sf);
238 WriteByte(MSG_ENTITY, num_for_edict(self.realowner));
239 WriteCoord(MSG_ENTITY, autocvar_g_balance_electro_primary_range);
243 WriteCoord(MSG_ENTITY, self.hook_start_x);
244 WriteCoord(MSG_ENTITY, self.hook_start_y);
245 WriteCoord(MSG_ENTITY, self.hook_start_z);
249 WriteCoord(MSG_ENTITY, self.hook_end_x);
250 WriteCoord(MSG_ENTITY, self.hook_end_y);
251 WriteCoord(MSG_ENTITY, self.hook_end_z);
257 float lgbeam_checkammo()
259 if(self.realowner.items & IT_UNLIMITED_WEAPON_AMMO)
261 else if(autocvar_g_balance_electro_reload_ammo)
262 return self.realowner.clip_load > 0;
264 return self.realowner.ammo_cells > 0;
267 entity lgbeam_owner_ent;
271 owner_player = self.realowner;
273 owner_player.prevlgfire = time;
274 if (self != owner_player.lgbeam)
280 if (owner_player.weaponentity.state != WS_INUSE || !lgbeam_checkammo() || owner_player.deadflag != DEAD_NO || !owner_player.BUTTON_ATCK || owner_player.freezetag_frozen)
282 if(self == owner_player.lgbeam)
283 owner_player.lgbeam = world;
288 self.nextthink = time;
290 makevectors(owner_player.v_angle);
295 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
296 if (!(owner_player.items & IT_UNLIMITED_WEAPON_AMMO))
298 if(autocvar_g_balance_electro_primary_ammo)
300 if(autocvar_g_balance_electro_reload_ammo)
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;
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);
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)
317 lgbeam_owner_ent = spawn();
318 lgbeam_owner_ent.classname = "lgbeam_owner_ent";
320 WarpZone_traceline_antilag(lgbeam_owner_ent, w_shotorg, w_shotend, MOVE_NORMAL, lgbeam_owner_ent, ANTILAG_LATENCY(owner_player));
326 force = w_shotdir * autocvar_g_balance_electro_primary_force + '0 0 1' * autocvar_g_balance_electro_primary_force_up;
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));
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);
334 W_Plasma_TriggerCombo(trace_endpos, autocvar_g_balance_electro_primary_comboradius, owner_player);
337 if(w_shotorg != self.hook_start)
340 self.hook_start = w_shotorg;
342 if(w_shotend != self.hook_end)
345 self.hook_end = w_shotend;
349 // experimental lightning gun
350 void W_Electro_Attack3 (void)
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);
356 entity beam, oldself;
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);
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);
384 void w_electro_checkattack()
386 if(self.electro_count > 1)
387 if(self.BUTTON_ATCK2)
388 if(weapon_prepareattack(1, -1))
391 self.electro_count -= 1;
392 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
399 .float bot_secondary_electromooth;
400 .float BUTTON_ATCK_prev;
401 float w_electro(float req)
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)
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);
419 shoot = bot_aim(1000000, 0, 0.001, FALSE);
423 self.BUTTON_ATCK = TRUE;
424 if(random() < 0.01) self.bot_secondary_electromooth = 1;
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
431 self.BUTTON_ATCK2 = TRUE;
432 if(random() < 0.03) self.bot_secondary_electromooth = 0;
440 if(autocvar_g_balance_electro_reload_ammo) // forced reload
443 if(autocvar_g_balance_electro_lightning)
445 if(self.clip_load > 0)
448 else if(self.clip_load >= autocvar_g_balance_electro_primary_ammo)
450 if(self.clip_load >= autocvar_g_balance_electro_secondary_ammo)
455 WEP_ACTION(self.weapon, WR_RELOAD);
461 if (self.BUTTON_ATCK)
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);
467 if (weapon_prepareattack(0, (autocvar_g_balance_electro_lightning ? 0 : autocvar_g_balance_electro_primary_refire)))
469 if(autocvar_g_balance_electro_lightning)
471 if ((!self.lgbeam) || wasfreed(self.lgbeam))
475 if(!self.BUTTON_ATCK_prev)
477 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
478 self.BUTTON_ATCK_prev = 1;
484 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
488 if(autocvar_g_balance_electro_lightning)
490 if (self.BUTTON_ATCK_prev != 0)
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();
495 self.BUTTON_ATCK_prev = 0;
498 if (self.BUTTON_ATCK2)
500 if (time >= self.electro_secondarytime)
501 if (weapon_prepareattack(1, autocvar_g_balance_electro_secondary_refire))
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();
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");
524 if(autocvar_g_balance_electro_lightning)
525 precache_sound ("weapons/lgbeam_fire.wav");
531 self.current_ammo = ammo_cells;
536 if(autocvar_g_balance_electro_lightning)
538 if(!autocvar_g_balance_electro_primary_ammo)
541 ammo_amount = self.ammo_cells > 0;
542 ammo_amount += self.(weapon_load[WEP_ELECTRO]) > 0;
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;
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.
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;
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;
567 self.electro_secondarytime = time;
572 W_Reload(min(autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_secondary_ammo), "weapons/reload.wav");
575 case WR_SUICIDEMESSAGE:
577 if(w_deathtype & HITTYPE_SECONDARY)
578 return WEAPON_ELECTRO_SUICIDE_ORBS;
580 return WEAPON_ELECTRO_SUICIDE_BOLT;
584 if(w_deathtype & HITTYPE_SECONDARY)
586 return WEAPON_ELECTRO_MURDER_ORBS;
590 if(w_deathtype & HITTYPE_BOUNCE)
591 return WEAPON_ELECTRO_MURDER_COMBO;
593 return WEAPON_ELECTRO_MURDER_BOLT;
601 float w_electro(float req)
605 case WR_IMPACTEFFECT:
608 org2 = w_org + w_backoff * 6;
609 if(w_deathtype & HITTYPE_SECONDARY)
611 pointparticles(particleeffectnum("electro_ballexplode"), org2, '0 0 0', 1);
613 sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTEN_NORM);
617 if(w_deathtype & HITTYPE_BOUNCE)
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);
622 sound(self, CH_SHOTS, "weapons/electro_impact_combo.wav", VOL_BASE, ATTEN_NORM);
626 pointparticles(particleeffectnum("electro_impact"), org2, '0 0 0', 1);
628 sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTEN_NORM);
636 precache_sound("weapons/electro_impact.wav");
637 precache_sound("weapons/electro_impact_combo.wav");