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 /* shortname */ "electro",
11 /* fullname */ _("Electro")
16 .float electro_secondarytime;
18 void W_Plasma_Explode_Combo (void);
20 void W_Plasma_TriggerCombo(vector org, float rad, entity own)
23 e = WarpZone_FindRadius(org, rad, TRUE);
26 if (e.classname == "plasma")
28 // change owner to whoever caused the combo explosion
30 e.takedamage = DAMAGE_NO;
31 e.classname = "plasma_chain";
32 e.think = W_Plasma_Explode_Combo;
33 e.nextthink = time + vlen(e.WarpZone_findradius_dist) / autocvar_g_balance_electro_combo_speed; // delay combo chains, looks cooler
39 void W_Plasma_Explode (void)
41 if(other.takedamage == DAMAGE_AIM)
43 if(IsDifferentTeam(self.realowner, other))
44 if(other.deadflag == DEAD_NO)
46 Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_ELECTROBITCH);
48 self.event_damage = func_null;
49 self.takedamage = DAMAGE_NO;
50 if (self.movetype == MOVETYPE_BOUNCE)
52 RadiusDamage (self, self.realowner, 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);
56 W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_primary_comboradius, self.realowner);
57 RadiusDamage (self, self.realowner, 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);
63 void W_Plasma_Explode_Combo (void)
65 W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_combo_comboradius, self.realowner);
67 self.event_damage = func_null;
68 RadiusDamage (self, self.realowner, 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
72 void W_Plasma_Touch (void)
74 //self.velocity = self.velocity * 0.1;
77 if (other.takedamage == DAMAGE_AIM) {
80 //UpdateCSQCProjectile(self);
81 spamsound (self, CH_SHOTS, "weapons/electro_bounce.wav", VOL_BASE, ATTEN_NORM);
82 self.projectiledeathtype |= HITTYPE_BOUNCE;
86 void W_Plasma_TouchExplode (void)
92 void W_Plasma_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
97 // note: combos are usually triggered by W_Plasma_TriggerCombo, not damage
98 float is_combo = (inflictor.classname == "plasma_chain" || inflictor.classname == "plasma_prim");
100 if (!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, (is_combo ? 1 : -1)))
101 return; // g_projectiles_damage says to halt
103 self.health = self.health - damage;
104 if (self.health <= 0)
106 self.takedamage = DAMAGE_NO;
107 self.nextthink = time;
110 // change owner to whoever caused the combo explosion
111 self.realowner = inflictor.realowner;
112 self.classname = "plasma_chain";
113 self.think = W_Plasma_Explode_Combo;
114 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
115 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bounding the length, because inflictor may be in a galaxy far far away (warpzones)
119 self.use = W_Plasma_Explode;
120 self.think = adaptor_think2use; // not _hittype_splash, as this runs "immediately"
125 void W_Electro_Attack()
129 W_DecreaseAmmo(ammo_cells, autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_reload_ammo);
131 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);
133 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
136 proj.classname = "plasma_prim";
137 proj.owner = proj.realowner = self;
138 proj.bot_dodge = TRUE;
139 proj.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
140 proj.use = W_Plasma_Explode;
141 proj.think = adaptor_think2use_hittype_splash;
142 proj.nextthink = time + autocvar_g_balance_electro_primary_lifetime;
143 PROJECTILE_MAKETRIGGER(proj);
144 proj.projectiledeathtype = WEP_ELECTRO;
145 setorigin(proj, w_shotorg);
147 proj.movetype = MOVETYPE_FLY;
148 W_SETUPPROJECTILEVELOCITY(proj, g_balance_electro_primary);
149 proj.angles = vectoangles(proj.velocity);
150 proj.touch = W_Plasma_TouchExplode;
151 setsize(proj, '0 0 -3', '0 0 -3');
152 proj.flags = FL_PROJECTILE;
153 proj.missile_flags = MIF_SPLASH;
155 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO_BEAM, TRUE);
157 other = proj; MUTATOR_CALLHOOK(EditProjectile);
160 void W_Electro_Attack2()
164 W_DecreaseAmmo(ammo_cells, autocvar_g_balance_electro_secondary_ammo, autocvar_g_balance_electro_reload_ammo);
166 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);
168 w_shotdir = v_forward; // no TrueAim for grenades please
170 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
173 proj.classname = "plasma";
174 proj.owner = proj.realowner = self;
175 proj.use = W_Plasma_Explode;
176 proj.think = adaptor_think2use_hittype_splash;
177 proj.bot_dodge = TRUE;
178 proj.bot_dodgerating = autocvar_g_balance_electro_secondary_damage;
179 proj.nextthink = time + autocvar_g_balance_electro_secondary_lifetime;
180 PROJECTILE_MAKETRIGGER(proj);
181 proj.projectiledeathtype = WEP_ELECTRO | HITTYPE_SECONDARY;
182 setorigin(proj, w_shotorg);
184 //proj.glow_size = 50;
185 //proj.glow_color = 45;
186 proj.movetype = MOVETYPE_BOUNCE;
187 W_SETUPPROJECTILEVELOCITY_UP(proj, g_balance_electro_secondary);
188 proj.touch = W_Plasma_Touch;
189 setsize(proj, '0 0 -4', '0 0 -4');
190 proj.takedamage = DAMAGE_YES;
191 proj.damageforcescale = autocvar_g_balance_electro_secondary_damageforcescale;
192 proj.health = autocvar_g_balance_electro_secondary_health;
193 proj.event_damage = W_Plasma_Damage;
194 proj.flags = FL_PROJECTILE;
195 proj.damagedbycontents = (autocvar_g_balance_electro_secondary_damagedbycontents);
197 proj.bouncefactor = autocvar_g_balance_electro_secondary_bouncefactor;
198 proj.bouncestop = autocvar_g_balance_electro_secondary_bouncestop;
199 proj.missile_flags = MIF_SPLASH | MIF_ARC;
204 copyentity(proj, p2);
205 setmodel(p2, "models/ebomb.mdl");
206 setsize(p2, proj.mins, proj.maxs);
209 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO, FALSE); // no culling, it has sound
211 other = proj; MUTATOR_CALLHOOK(EditProjectile);
214 .vector hook_start, hook_end;
215 float lgbeam_send(entity to, float sf)
217 WriteByte(MSG_ENTITY, ENT_CLIENT_LGBEAM);
219 if(sound_allowed(MSG_BROADCAST, self.realowner))
221 WriteByte(MSG_ENTITY, sf);
224 WriteByte(MSG_ENTITY, num_for_edict(self.realowner));
225 WriteCoord(MSG_ENTITY, autocvar_g_balance_electro_primary_range);
229 WriteCoord(MSG_ENTITY, self.hook_start_x);
230 WriteCoord(MSG_ENTITY, self.hook_start_y);
231 WriteCoord(MSG_ENTITY, self.hook_start_z);
235 WriteCoord(MSG_ENTITY, self.hook_end_x);
236 WriteCoord(MSG_ENTITY, self.hook_end_y);
237 WriteCoord(MSG_ENTITY, self.hook_end_z);
243 float lgbeam_checkammo()
245 if(self.realowner.items & IT_UNLIMITED_WEAPON_AMMO)
247 else if(autocvar_g_balance_electro_reload_ammo)
248 return self.realowner.clip_load > 0;
250 return self.realowner.ammo_cells > 0;
253 entity lgbeam_owner_ent;
257 owner_player = self.realowner;
259 owner_player.prevlgfire = time;
260 if (self != owner_player.lgbeam)
266 if (owner_player.weaponentity.state != WS_INUSE || !lgbeam_checkammo() || owner_player.deadflag != DEAD_NO || !owner_player.BUTTON_ATCK || owner_player.frozen)
268 if(self == owner_player.lgbeam)
269 owner_player.lgbeam = world;
274 self.nextthink = time;
276 makevectors(owner_player.v_angle);
281 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
282 if not(owner_player.items & IT_UNLIMITED_WEAPON_AMMO)
284 if(autocvar_g_balance_electro_primary_ammo)
286 if(autocvar_g_balance_electro_reload_ammo)
288 dt = min(dt, owner_player.clip_load / autocvar_g_balance_electro_primary_ammo);
289 owner_player.clip_load = max(0, owner_player.clip_load - autocvar_g_balance_electro_primary_ammo * frametime);
290 owner_player.(weapon_load[WEP_ELECTRO]) = owner_player.clip_load;
294 dt = min(dt, owner_player.ammo_cells / autocvar_g_balance_electro_primary_ammo);
295 owner_player.ammo_cells = max(0, owner_player.ammo_cells - autocvar_g_balance_electro_primary_ammo * frametime);
300 W_SetupShot_Range(owner_player, TRUE, 0, "", 0, autocvar_g_balance_electro_primary_damage * dt, autocvar_g_balance_electro_primary_range);
301 if(!lgbeam_owner_ent)
303 lgbeam_owner_ent = spawn();
304 lgbeam_owner_ent.classname = "lgbeam_owner_ent";
306 WarpZone_traceline_antilag(lgbeam_owner_ent, w_shotorg, w_shotend, MOVE_NORMAL, lgbeam_owner_ent, ANTILAG_LATENCY(owner_player));
312 force = w_shotdir * autocvar_g_balance_electro_primary_force + '0 0 1' * autocvar_g_balance_electro_primary_force_up;
314 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));
316 if(accuracy_isgooddamage(owner_player, trace_ent))
317 accuracy_add(owner_player, WEP_ELECTRO, 0, autocvar_g_balance_electro_primary_damage * dt * f);
318 Damage (trace_ent, owner_player, owner_player, autocvar_g_balance_electro_primary_damage * dt * f, WEP_ELECTRO, trace_endpos, force * dt);
320 W_Plasma_TriggerCombo(trace_endpos, autocvar_g_balance_electro_primary_comboradius, owner_player);
323 if(w_shotorg != self.hook_start)
326 self.hook_start = w_shotorg;
328 if(w_shotend != self.hook_end)
331 self.hook_end = w_shotend;
335 // experimental lightning gun
336 void W_Electro_Attack3 (void)
338 // only play fire sound if 0.5 sec has passed since player let go the fire button
339 if(time - self.prevlgfire > 0.5)
340 sound (self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTEN_NORM);
342 entity beam, oldself;
344 self.lgbeam = beam = spawn();
345 beam.classname = "lgbeam";
346 beam.solid = SOLID_NOT;
347 beam.think = lgbeam_think;
348 beam.owner = beam.realowner = self;
349 beam.movetype = MOVETYPE_NONE;
350 beam.shot_spread = 0;
351 beam.bot_dodge = TRUE;
352 beam.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
353 Net_LinkEntity(beam, FALSE, 0, lgbeam_send);
363 weapon_action(WEP_ELECTRO, WR_PRECACHE);
364 electro_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 1);
365 electro_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 2);
366 electro_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 3);
367 electro_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 4);
370 void spawnfunc_weapon_electro (void)
372 weapon_defaultspawnfunc(WEP_ELECTRO);
375 void w_electro_checkattack()
377 if(self.electro_count > 1)
378 if(self.BUTTON_ATCK2)
379 if(weapon_prepareattack(1, -1))
382 self.electro_count -= 1;
383 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
390 .float bot_secondary_electromooth;
391 .float BUTTON_ATCK_prev;
392 float w_electro(float req)
397 self.BUTTON_ATCK=FALSE;
398 self.BUTTON_ATCK2=FALSE;
399 if(vlen(self.origin-self.enemy.origin) > 1000)
400 self.bot_secondary_electromooth = 0;
401 if(self.bot_secondary_electromooth == 0)
405 if(autocvar_g_balance_electro_primary_speed)
406 shoot = bot_aim(autocvar_g_balance_electro_primary_speed, 0, autocvar_g_balance_electro_primary_lifetime, FALSE);
408 shoot = bot_aim(1000000, 0, 0.001, FALSE);
412 self.BUTTON_ATCK = TRUE;
413 if(random() < 0.01) self.bot_secondary_electromooth = 1;
418 if(bot_aim(autocvar_g_balance_electro_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_electro_secondary_lifetime, TRUE))
420 self.BUTTON_ATCK2 = TRUE;
421 if(random() < 0.03) self.bot_secondary_electromooth = 0;
425 else if (req == WR_THINK)
427 if(autocvar_g_balance_electro_reload_ammo) // forced reload
430 if(autocvar_g_balance_electro_lightning)
432 if(self.clip_load > 0)
435 else if(self.clip_load >= autocvar_g_balance_electro_primary_ammo)
437 if(self.clip_load >= autocvar_g_balance_electro_secondary_ammo)
442 weapon_action(self.weapon, WR_RELOAD);
446 if (self.BUTTON_ATCK)
448 if(autocvar_g_balance_electro_lightning)
449 if(self.BUTTON_ATCK_prev)
450 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
452 if (weapon_prepareattack(0, (autocvar_g_balance_electro_lightning ? 0 : autocvar_g_balance_electro_primary_refire)))
454 if(autocvar_g_balance_electro_lightning)
456 if ((!self.lgbeam) || wasfreed(self.lgbeam))
460 if(!self.BUTTON_ATCK_prev)
462 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
463 self.BUTTON_ATCK_prev = 1;
469 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
473 if(autocvar_g_balance_electro_lightning)
475 if (self.BUTTON_ATCK_prev != 0)
477 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
478 ATTACK_FINISHED(self) = time + autocvar_g_balance_electro_primary_refire * W_WeaponRateFactor();
480 self.BUTTON_ATCK_prev = 0;
483 if (self.BUTTON_ATCK2)
485 if (time >= self.electro_secondarytime)
486 if (weapon_prepareattack(1, autocvar_g_balance_electro_secondary_refire))
489 self.electro_count = autocvar_g_balance_electro_secondary_count;
490 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
491 self.electro_secondarytime = time + autocvar_g_balance_electro_secondary_refire2 * W_WeaponRateFactor();
496 else if (req == WR_PRECACHE)
498 precache_model ("models/weapons/g_electro.md3");
499 precache_model ("models/weapons/v_electro.md3");
500 precache_model ("models/weapons/h_electro.iqm");
501 precache_sound ("weapons/electro_bounce.wav");
502 precache_sound ("weapons/electro_fire.wav");
503 precache_sound ("weapons/electro_fire2.wav");
504 precache_sound ("weapons/electro_impact.wav");
505 precache_sound ("weapons/electro_impact_combo.wav");
506 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
507 if(autocvar_g_balance_electro_lightning)
509 precache_sound ("weapons/lgbeam_fire.wav");
512 else if (req == WR_SETUP)
514 weapon_setup(WEP_ELECTRO);
515 self.current_ammo = ammo_cells;
517 else if (req == WR_CHECKAMMO1)
519 if(autocvar_g_balance_electro_lightning)
521 if(!autocvar_g_balance_electro_primary_ammo)
524 ammo_amount = self.ammo_cells > 0;
525 ammo_amount += self.(weapon_load[WEP_ELECTRO]) > 0;
529 ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_primary_ammo;
530 ammo_amount += self.(weapon_load[WEP_ELECTRO]) >= autocvar_g_balance_electro_primary_ammo;
534 else if (req == WR_CHECKAMMO2)
536 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.
538 ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_secondary_ammo + autocvar_g_balance_electro_primary_ammo;
539 ammo_amount += self.(weapon_load[WEP_ELECTRO]) >= autocvar_g_balance_electro_secondary_ammo + autocvar_g_balance_electro_primary_ammo;
543 ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_secondary_ammo;
544 ammo_amount += self.(weapon_load[WEP_ELECTRO]) >= autocvar_g_balance_electro_secondary_ammo;
548 else if (req == WR_RESETPLAYER)
550 self.electro_secondarytime = time;
552 else if (req == WR_RELOAD)
554 W_Reload(min(autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_secondary_ammo), autocvar_g_balance_electro_reload_ammo, autocvar_g_balance_electro_reload_time, "weapons/reload.wav");
556 else if (req == WR_SUICIDEMESSAGE)
558 if(w_deathtype & HITTYPE_SECONDARY)
559 return WEAPON_ELECTRO_SUICIDE_ORBS;
561 return WEAPON_ELECTRO_SUICIDE_BOLT;
563 else if (req == WR_KILLMESSAGE)
565 if(w_deathtype & HITTYPE_SECONDARY)
567 return WEAPON_ELECTRO_MURDER_ORBS;
571 if(w_deathtype & HITTYPE_BOUNCE)
572 return WEAPON_ELECTRO_MURDER_COMBO;
574 return WEAPON_ELECTRO_MURDER_BOLT;
581 float w_electro(float req)
583 if(req == WR_IMPACTEFFECT)
586 org2 = w_org + w_backoff * 6;
587 if(w_deathtype & HITTYPE_SECONDARY)
589 pointparticles(particleeffectnum("electro_ballexplode"), org2, '0 0 0', 1);
591 sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTEN_NORM);
595 if(w_deathtype & HITTYPE_BOUNCE)
597 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
598 pointparticles(particleeffectnum("electro_combo"), org2, '0 0 0', 1);
600 sound(self, CH_SHOTS, "weapons/electro_impact_combo.wav", VOL_BASE, ATTEN_NORM);
604 pointparticles(particleeffectnum("electro_impact"), org2, '0 0 0', 1);
606 sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTEN_NORM);
610 else if(req == WR_PRECACHE)
612 precache_sound("weapons/electro_impact.wav");
613 precache_sound("weapons/electro_impact_combo.wav");