5 void W_Electro_TriggerCombo(vector org, float rad, entity own)
7 entity e = WarpZone_FindRadius(org, rad, !WEP_CVAR(electro, combo_comboradius_thruwall));
10 if(e.classname == "electro_orb")
12 // do we allow thruwall triggering?
13 if(WEP_CVAR(electro, combo_comboradius_thruwall))
15 // if distance is greater than thruwall distance, check to make sure it's not through a wall
16 if(vdist(e.WarpZone_findradius_dist, >, WEP_CVAR(electro, combo_comboradius_thruwall)))
18 WarpZone_TraceLine(org, e.origin, MOVE_NOMONSTERS, e);
19 if(trace_fraction != 1)
21 // trigger is through a wall and outside of thruwall range, abort
28 // change owner to whoever caused the combo explosion
30 e.takedamage = DAMAGE_NO;
31 e.classname = "electro_orb_chain";
33 // now set the next one to trigger as well
34 setthink(e, W_Electro_ExplodeCombo);
36 // delay combo chains, looks cooler
41 (WEP_CVAR(electro, combo_speed) ?
42 (vlen(e.WarpZone_findradius_dist) / WEP_CVAR(electro, combo_speed))
52 void W_Electro_ExplodeComboThink(entity this)
54 float dt = time - this.teleport_time + this.dmg_interval;
55 float dmg_remaining_next = (bound(0, 1 - dt / this.dmg_duration, 1) ** this.dmg_power);
57 float f = this.dmg_last - dmg_remaining_next;
58 this.dmg_last = dmg_remaining_next;
60 RadiusDamage(this, this.realowner, this.dmg * f, this.dmg_edge * f, this.dmg_radius, NULL, NULL, this.dmg_force * f, this.projectiledeathtype, this.weaponentity_fld, NULL);
61 this.projectiledeathtype |= HITTYPE_BOUNCE; // ensure it doesn't spam its effect
63 if(dt < this.dmg_duration)
64 this.nextthink = time + this.dmg_interval; // soon
69 void W_Electro_ExplodeCombo(entity this)
71 W_Electro_TriggerCombo(this.origin, WEP_CVAR(electro, combo_comboradius), this.realowner);
73 this.event_damage = func_null;
75 if(WEP_CVAR(electro, combo_duration))
77 this.projectiledeathtype = WEP_ELECTRO.m_id | HITTYPE_SPLASH;
78 this.event_damage = func_null;
79 settouch(this, func_null);
80 this.effects |= EF_NODRAW;
82 setthink(this, W_Electro_ExplodeComboThink);
83 this.nextthink = time;
84 this.dmg = WEP_CVAR(electro, combo_damage);
85 this.dmg_edge = WEP_CVAR(electro, combo_edgedamage);
86 this.dmg_radius = WEP_CVAR(electro, combo_radius);
87 this.dmg_force = WEP_CVAR(electro, combo_force);
88 this.dmg_power = WEP_CVAR(electro, combo_power);
89 this.dmg_duration = WEP_CVAR(electro, combo_duration);
90 this.dmg_interval = WEP_CVAR(electro, combo_damage_interval);
91 this.teleport_time = time;
93 set_movetype(this, MOVETYPE_NONE);
100 WEP_CVAR(electro, combo_damage),
101 WEP_CVAR(electro, combo_edgedamage),
102 WEP_CVAR(electro, combo_radius),
105 WEP_CVAR(electro, combo_force),
106 WEP_ELECTRO.m_id | HITTYPE_BOUNCE, // use THIS type for a combo because primary can't bounce
107 this.weaponentity_fld,
114 void W_Electro_Explode(entity this, entity directhitentity)
116 if(directhitentity.takedamage == DAMAGE_AIM)
117 if(IS_PLAYER(directhitentity))
118 if(DIFF_TEAM(this.realowner, directhitentity))
119 if(!IS_DEAD(directhitentity))
120 if(IsFlying(directhitentity))
121 Send_Notification(NOTIF_ONE, this.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_ELECTROBITCH);
123 this.event_damage = func_null;
124 this.takedamage = DAMAGE_NO;
126 if(this.move_movetype == MOVETYPE_BOUNCE || this.classname == "electro_orb") // TODO: classname is more reliable anyway?
131 WEP_CVAR_SEC(electro, damage),
132 WEP_CVAR_SEC(electro, edgedamage),
133 WEP_CVAR_SEC(electro, radius),
136 WEP_CVAR_SEC(electro, force),
137 this.projectiledeathtype,
138 this.weaponentity_fld,
144 W_Electro_TriggerCombo(this.origin, WEP_CVAR_PRI(electro, comboradius), this.realowner);
148 WEP_CVAR_PRI(electro, damage),
149 WEP_CVAR_PRI(electro, edgedamage),
150 WEP_CVAR_PRI(electro, radius),
153 WEP_CVAR_PRI(electro, force),
154 this.projectiledeathtype,
155 this.weaponentity_fld,
163 void W_Electro_Explode_use(entity this, entity actor, entity trigger)
165 W_Electro_Explode(this, trigger);
168 void W_Electro_TouchExplode(entity this, entity toucher)
170 PROJECTILE_TOUCH(this, toucher);
171 W_Electro_Explode(this, toucher);
175 void sys_phys_update_single(entity this);
177 void W_Electro_Bolt_Think(entity this)
179 // sys_phys_update_single(this);
180 if(time >= this.ltime)
182 this.use(this, NULL, NULL);
186 if(WEP_CVAR_PRI(electro, midaircombo_radius))
189 entity e = WarpZone_FindRadius(this.origin, WEP_CVAR_PRI(electro, midaircombo_radius), true);
191 // loop through nearby orbs and trigger them
194 if(e.classname == "electro_orb")
197 if (this.owner == e.owner)
199 explode = WEP_CVAR_PRI(electro, midaircombo_own);
201 else if (SAME_TEAM(this.owner, e.owner))
203 explode = WEP_CVAR_PRI(electro, midaircombo_teammate);
207 explode = WEP_CVAR_PRI(electro, midaircombo_enemy);
212 // change owner to whoever caused the combo explosion
213 e.realowner = this.realowner;
214 e.takedamage = DAMAGE_NO;
215 e.classname = "electro_orb_chain";
217 // Only first orb explosion uses midaircombo_speed, others use the normal combo_speed.
218 // This allows to avoid the delay on the first explosion which looks better
219 // (the bolt and orb should explode together because they interacted together)
220 // while keeping the chaining delay.
221 setthink(e, W_Electro_ExplodeCombo);
226 (WEP_CVAR_PRI(electro, midaircombo_speed) ?
227 (vlen(e.WarpZone_findradius_dist) / WEP_CVAR_PRI(electro, midaircombo_speed))
240 // if we triggered an orb, should we explode? if not, lets try again next time
241 if(found && WEP_CVAR_PRI(electro, midaircombo_explode))
242 { this.use(this, NULL, NULL); }
244 { this.nextthink = min(time + WEP_CVAR_PRI(electro, midaircombo_interval), this.ltime); }
246 else { this.nextthink = this.ltime; }
247 // this.nextthink = time;
250 void W_Electro_Attack_Bolt(Weapon thiswep, entity actor, .entity weaponentity)
254 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(electro, ammo), weaponentity);
256 W_SetupShot_ProjectileSize(
265 WEP_CVAR_PRI(electro, damage),
269 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
271 proj = new(electro_bolt);
272 proj.owner = proj.realowner = actor;
273 proj.bot_dodge = true;
274 proj.bot_dodgerating = WEP_CVAR_PRI(electro, damage);
275 proj.use = W_Electro_Explode_use;
276 setthink(proj, W_Electro_Bolt_Think);
277 proj.nextthink = time;
278 proj.ltime = time + WEP_CVAR_PRI(electro, lifetime);
279 PROJECTILE_MAKETRIGGER(proj);
280 proj.projectiledeathtype = thiswep.m_id;
281 proj.weaponentity_fld = weaponentity;
282 setorigin(proj, w_shotorg);
285 set_movetype(proj, MOVETYPE_FLY);
286 W_SetupProjVelocity_PRI(proj, electro);
287 proj.angles = vectoangles(proj.velocity);
288 settouch(proj, W_Electro_TouchExplode);
289 setsize(proj, '0 0 -3', '0 0 -3');
290 proj.flags = FL_PROJECTILE;
291 IL_PUSH(g_projectiles, proj);
292 IL_PUSH(g_bot_dodge, proj);
293 proj.missile_flags = MIF_SPLASH;
295 CSQCProjectile(proj, true, PROJECTILE_ELECTRO_BEAM, true);
297 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
298 // proj.com_phys_pos = proj.origin;
299 // proj.com_phys_vel = proj.velocity;
302 void W_Electro_Orb_Stick(entity this, entity to)
304 entity newproj = spawn();
305 newproj.classname = this.classname;
307 newproj.bot_dodge = this.bot_dodge;
308 newproj.bot_dodgerating = this.bot_dodgerating;
310 newproj.owner = this.owner;
311 newproj.realowner = this.realowner;
312 setsize(newproj, this.mins, this.maxs);
313 setorigin(newproj, this.origin);
314 setmodel(newproj, MDL_PROJECTILE_ELECTRO);
315 newproj.angles = vectoangles(-trace_plane_normal); // face against the surface
317 newproj.takedamage = this.takedamage;
318 newproj.damageforcescale = this.damageforcescale;
319 SetResourceExplicit(newproj, RES_HEALTH, GetResource(this, RES_HEALTH));
320 newproj.event_damage = this.event_damage;
321 newproj.spawnshieldtime = this.spawnshieldtime;
322 newproj.damagedbycontents = true;
323 IL_PUSH(g_damagedbycontents, newproj);
325 set_movetype(newproj, MOVETYPE_NONE); // lock the orb in place
326 newproj.projectiledeathtype = this.projectiledeathtype;
327 newproj.weaponentity_fld = this.weaponentity_fld;
329 settouch(newproj, func_null);
330 setthink(newproj, getthink(this));
331 newproj.nextthink = this.nextthink;
332 newproj.use = this.use;
333 newproj.flags = this.flags;
334 IL_PUSH(g_projectiles, newproj);
335 IL_PUSH(g_bot_dodge, newproj);
340 SetMovetypeFollow(newproj, to);
343 void W_Electro_Orb_Touch(entity this, entity toucher)
345 PROJECTILE_TOUCH(this, toucher);
346 if(toucher.takedamage == DAMAGE_AIM && WEP_CVAR_SEC(electro, touchexplode))
347 { W_Electro_Explode(this, toucher); }
348 else if(toucher.owner != this.owner && toucher.classname != this.classname) // don't stick to player's other projectiles!
350 //UpdateCSQCProjectile(this);
351 spamsound(this, CH_SHOTS, SND_ELECTRO_BOUNCE, VOL_BASE, ATTEN_NORM);
352 this.projectiledeathtype |= HITTYPE_BOUNCE;
354 if(WEP_CVAR_SEC(electro, stick))
355 W_Electro_Orb_Stick(this, toucher);
359 void W_Electro_Orb_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
361 if(GetResource(this, RES_HEALTH) <= 0)
364 // note: combos are usually triggered by W_Electro_TriggerCombo, not damage
365 float is_combo = (inflictor.classname == "electro_orb_chain" || inflictor.classname == "electro_bolt");
367 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, (is_combo ? 1 : -1)))
368 return; // g_projectiles_damage says to halt
370 TakeResource(this, RES_HEALTH, damage);
371 if(GetResource(this, RES_HEALTH) <= 0)
373 this.takedamage = DAMAGE_NO;
374 this.nextthink = time;
377 // change owner to whoever caused the combo explosion
378 this.realowner = inflictor.realowner;
379 this.classname = "electro_orb_chain";
380 setthink(this, W_Electro_ExplodeCombo);
381 this.nextthink = time +
383 // bound the length, inflictor may be in a galaxy far far away (warpzones)
385 WEP_CVAR(electro, combo_radius),
386 vlen(this.origin - inflictor.origin)
389 // delay combo chains, looks cooler
390 WEP_CVAR(electro, combo_speed)
395 this.use = W_Electro_Explode_use;
396 setthink(this, adaptor_think2use); // not _hittype_splash, as this runs "immediately"
401 void W_Electro_Attack_Orb(Weapon thiswep, entity actor, .entity weaponentity)
403 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(electro, ammo), weaponentity);
405 W_SetupShot_ProjectileSize(
414 WEP_CVAR_SEC(electro, damage),
415 thiswep.m_id | HITTYPE_SECONDARY
418 w_shotdir = v_forward; // no TrueAim for grenades please
420 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
422 entity proj = new(electro_orb);
423 proj.owner = proj.realowner = actor;
424 proj.use = W_Electro_Explode_use;
425 setthink(proj, adaptor_think2use_hittype_splash);
426 proj.bot_dodge = true;
427 proj.bot_dodgerating = WEP_CVAR_SEC(electro, damage);
428 proj.nextthink = time + WEP_CVAR_SEC(electro, lifetime);
429 PROJECTILE_MAKETRIGGER(proj);
430 proj.projectiledeathtype = thiswep.m_id | HITTYPE_SECONDARY;
431 proj.weaponentity_fld = weaponentity;
432 setorigin(proj, w_shotorg);
434 //proj.glow_size = 50;
435 //proj.glow_color = 45;
436 set_movetype(proj, MOVETYPE_BOUNCE);
437 W_SetupProjVelocity_UP_SEC(proj, electro);
438 settouch(proj, W_Electro_Orb_Touch);
439 setsize(proj, '-4 -4 -4', '4 4 4');
440 proj.takedamage = DAMAGE_YES;
441 proj.damageforcescale = WEP_CVAR_SEC(electro, damageforcescale);
442 SetResourceExplicit(proj, RES_HEALTH, WEP_CVAR_SEC(electro, health));
443 proj.event_damage = W_Electro_Orb_Damage;
444 proj.flags = FL_PROJECTILE;
445 IL_PUSH(g_projectiles, proj);
446 IL_PUSH(g_bot_dodge, proj);
447 proj.damagedbycontents = (WEP_CVAR_SEC(electro, damagedbycontents));
448 if(proj.damagedbycontents)
449 IL_PUSH(g_damagedbycontents, proj);
451 proj.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
452 proj.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
453 proj.missile_flags = MIF_SPLASH | MIF_ARC;
455 CSQCProjectile(proj, true, PROJECTILE_ELECTRO, false); // no culling, it has sound
457 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
460 void W_Electro_CheckAttack(Weapon thiswep, entity actor, .entity weaponentity, int fire)
462 if(actor.(weaponentity).electro_count > 1)
463 if(PHYS_INPUT_BUTTON_ATCK2(actor))
464 if(weapon_prepareattack(thiswep, actor, weaponentity, true, -1))
466 W_Electro_Attack_Orb(thiswep, actor, weaponentity);
467 actor.(weaponentity).electro_count -= 1;
468 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
471 // WEAPONTODO: when the player releases the button, cut down the length of refire2?
472 w_ready(thiswep, actor, weaponentity, fire);
475 .float bot_secondary_electromooth;
477 METHOD(Electro, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
479 PHYS_INPUT_BUTTON_ATCK(actor) = PHYS_INPUT_BUTTON_ATCK2(actor) = false;
480 if(vdist(actor.origin - actor.enemy.origin, >, 1000)) { actor.bot_secondary_electromooth = 0; }
481 if(actor.bot_secondary_electromooth == 0)
485 if(WEP_CVAR_PRI(electro, speed))
486 shoot = bot_aim(actor, weaponentity, WEP_CVAR_PRI(electro, speed), 0, WEP_CVAR_PRI(electro, lifetime), false);
488 shoot = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
492 PHYS_INPUT_BUTTON_ATCK(actor) = true;
493 if(random() < 0.01) actor.bot_secondary_electromooth = 1;
498 if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(electro, speed), WEP_CVAR_SEC(electro, speed_up), WEP_CVAR_SEC(electro, lifetime), true))
500 PHYS_INPUT_BUTTON_ATCK2(actor) = true;
501 if(random() < 0.03) actor.bot_secondary_electromooth = 0;
505 METHOD(Electro, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
507 if(autocvar_g_balance_electro_reload_ammo) // forced reload // WEAPONTODO
509 float ammo_amount = 0;
510 if(actor.(weaponentity).clip_load >= WEP_CVAR_PRI(electro, ammo))
512 if(actor.(weaponentity).clip_load >= WEP_CVAR_SEC(electro, ammo))
517 thiswep.wr_reload(thiswep, actor, weaponentity);
524 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire)))
526 W_Electro_Attack_Bolt(thiswep, actor, weaponentity);
527 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
532 if(time >= actor.(weaponentity).electro_secondarytime)
533 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(electro, refire)))
535 W_Electro_Attack_Orb(thiswep, actor, weaponentity);
536 actor.(weaponentity).electro_count = WEP_CVAR_SEC(electro, count);
537 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
538 actor.(weaponentity).electro_secondarytime = time + WEP_CVAR_SEC(electro, refire2) * W_WeaponRateFactor(actor);
542 METHOD(Electro, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
544 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(electro, ammo);
545 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_PRI(electro, ammo);
548 METHOD(Electro, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
551 if(WEP_CVAR(electro, combo_safeammocheck)) // true if you can fire at least one secondary blob AND one primary shot after it, otherwise false.
553 ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
554 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
558 ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(electro, ammo);
559 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(electro, ammo);
563 METHOD(Electro, wr_resetplayer, void(entity thiswep, entity actor))
565 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
567 .entity weaponentity = weaponentities[slot];
568 actor.(weaponentity).electro_secondarytime = time;
571 METHOD(Electro, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
573 W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(electro, ammo), WEP_CVAR_SEC(electro, ammo)), SND_RELOAD);
575 METHOD(Electro, wr_suicidemessage, Notification(entity thiswep))
577 if(w_deathtype & HITTYPE_SECONDARY)
578 return WEAPON_ELECTRO_SUICIDE_ORBS;
580 return WEAPON_ELECTRO_SUICIDE_BOLT;
582 METHOD(Electro, wr_killmessage, Notification(entity thiswep))
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;
600 METHOD(Electro, wr_impacteffect, void(entity thiswep, entity actor))
603 org2 = w_org + w_backoff * 6;
604 if(w_deathtype & HITTYPE_SECONDARY)
606 pointparticles(EFFECT_ELECTRO_BALLEXPLODE, org2, '0 0 0', 1);
608 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);
612 if(w_deathtype & HITTYPE_SPLASH)
614 org2 = w_org + w_backoff * 2;
615 if(particleeffectnum(EFFECT_ELECTRO_COMBO_LONG) >= 0)
616 pointparticles(EFFECT_ELECTRO_COMBO_LONG, org2, '0 0 0', 1);
618 pointparticles(EFFECT_HOOK_EXPLODE, org2, '0 0 0', 1);
620 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT_COMBO, VOL_BASE, ATTEN_NORM);
622 else if(w_deathtype & HITTYPE_BOUNCE)
624 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
625 pointparticles(EFFECT_ELECTRO_COMBO, org2, '0 0 0', 1);
627 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT_COMBO, VOL_BASE, ATTEN_NORM);
631 pointparticles(EFFECT_ELECTRO_IMPACT, org2, '0 0 0', 1);
633 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);