4 #include <common/effects/qc/_mod.qh>
6 void W_Electro_TriggerCombo(vector org, float rad, entity own)
8 entity e = WarpZone_FindRadius(org, rad, !WEP_CVAR(electro, combo_comboradius_thruwall));
11 if(e.classname == "electro_orb")
13 // check if the ball we are exploding is not owned by an
14 // independent player which is not the player who shot the ball
15 if(IS_INDEPENDENT_PLAYER(e.realowner) && own != e.realowner)
20 // do we allow thruwall triggering?
21 if(WEP_CVAR(electro, combo_comboradius_thruwall))
23 // if distance is greater than thruwall distance, check to make sure it's not through a wall
24 if(vdist(e.WarpZone_findradius_dist, >, WEP_CVAR(electro, combo_comboradius_thruwall)))
26 WarpZone_TraceLine(org, e.origin, MOVE_NOMONSTERS, e);
27 if(trace_fraction != 1)
29 // trigger is through a wall and outside of thruwall range, abort
36 // change owner to whoever caused the combo explosion
38 e.takedamage = DAMAGE_NO;
39 e.classname = "electro_orb_chain";
41 // now set the next one to trigger as well
42 setthink(e, W_Electro_ExplodeCombo);
44 // delay combo chains, looks cooler
46 if (WEP_CVAR(electro, combo_speed))
47 delay = vlen(e.WarpZone_findradius_dist) / WEP_CVAR(electro, combo_speed);
48 e.nextthink = time + delay;
54 void W_Electro_ExplodeCombo(entity this)
56 W_Electro_TriggerCombo(this.origin, WEP_CVAR(electro, combo_comboradius), this.realowner);
58 this.event_damage = func_null;
59 this.velocity = this.movedir; // particle fx and decals need .velocity
64 WEP_CVAR(electro, combo_damage),
65 WEP_CVAR(electro, combo_edgedamage),
66 WEP_CVAR(electro, combo_radius),
69 WEP_CVAR(electro, combo_force),
70 WEP_ELECTRO.m_id | HITTYPE_BOUNCE, // use THIS type for a combo because primary can't bounce
71 this.weaponentity_fld,
78 void W_Electro_Explode(entity this, entity directhitentity)
80 if(directhitentity.takedamage == DAMAGE_AIM)
81 if(IS_PLAYER(directhitentity))
82 if(DIFF_TEAM(this.realowner, directhitentity))
83 if(!IS_DEAD(directhitentity))
84 if(IsFlying(directhitentity))
85 Send_Notification(NOTIF_ONE, this.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_ELECTROBITCH);
87 this.event_damage = func_null;
88 this.takedamage = DAMAGE_NO;
89 this.velocity = this.movedir; // particle fx and decals need .velocity
91 if(this.move_movetype == MOVETYPE_BOUNCE || this.classname == "electro_orb") // TODO: classname is more reliable anyway?
96 WEP_CVAR_SEC(electro, damage),
97 WEP_CVAR_SEC(electro, edgedamage),
98 WEP_CVAR_SEC(electro, radius),
101 WEP_CVAR_SEC(electro, force),
102 this.projectiledeathtype,
103 this.weaponentity_fld,
109 W_Electro_TriggerCombo(this.origin, WEP_CVAR_PRI(electro, comboradius), this.realowner);
113 WEP_CVAR_PRI(electro, damage),
114 WEP_CVAR_PRI(electro, edgedamage),
115 WEP_CVAR_PRI(electro, radius),
118 WEP_CVAR_PRI(electro, force),
119 this.projectiledeathtype,
120 this.weaponentity_fld,
128 void W_Electro_Explode_use(entity this, entity actor, entity trigger)
130 W_Electro_Explode(this, trigger);
133 void W_Electro_TouchExplode(entity this, entity toucher)
135 PROJECTILE_TOUCH(this, toucher);
136 W_Electro_Explode(this, toucher);
140 //void sys_phys_update_single(entity this);
142 void W_Electro_Bolt_Think(entity this)
144 // sys_phys_update_single(this);
145 if(time >= this.ltime)
147 this.use(this, NULL, NULL);
151 if(WEP_CVAR_PRI(electro, midaircombo_radius))
154 entity e = WarpZone_FindRadius(this.origin, WEP_CVAR_PRI(electro, midaircombo_radius), true);
156 // loop through nearby orbs and trigger them
159 if(e.classname == "electro_orb")
161 // check if the ball we are exploding is not owned by an
162 // independent player which is not the player who shot the ball
163 if(IS_INDEPENDENT_PLAYER(e.realowner) && this.realowner != e.realowner)
169 if (this.owner == e.owner)
171 explode = WEP_CVAR_PRI(electro, midaircombo_own);
173 else if (SAME_TEAM(this.owner, e.owner))
175 explode = WEP_CVAR_PRI(electro, midaircombo_teammate);
179 explode = WEP_CVAR_PRI(electro, midaircombo_enemy);
184 // change owner to whoever caused the combo explosion
185 e.realowner = this.realowner;
186 e.takedamage = DAMAGE_NO;
187 e.classname = "electro_orb_chain";
189 // Only first orb explosion uses midaircombo_speed, others use the normal combo_speed.
190 // This allows to avoid the delay on the first explosion which looks better
191 // (the bolt and orb should explode together because they interacted together)
192 // while keeping the chaining delay.
193 setthink(e, W_Electro_ExplodeCombo);
195 if (WEP_CVAR_PRI(electro, midaircombo_speed))
196 delay = vlen(e.WarpZone_findradius_dist) / WEP_CVAR_PRI(electro, midaircombo_speed);
197 e.nextthink = time + delay;
205 // if we triggered an orb, should we explode? if not, lets try again next time
206 if(found && WEP_CVAR_PRI(electro, midaircombo_explode))
207 { this.use(this, NULL, NULL); }
209 { this.nextthink = min(time + WEP_CVAR_PRI(electro, midaircombo_interval), this.ltime); }
211 else { this.nextthink = this.ltime; }
212 // this.nextthink = time;
215 void W_Electro_Attack_Bolt(Weapon thiswep, entity actor, .entity weaponentity)
219 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(electro, ammo), weaponentity);
221 W_SetupShot_ProjectileSize(
230 WEP_CVAR_PRI(electro, damage),
234 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
236 proj = new(electro_bolt);
237 proj.owner = proj.realowner = actor;
238 proj.bot_dodge = true;
239 proj.bot_dodgerating = WEP_CVAR_PRI(electro, damage);
240 proj.use = W_Electro_Explode_use;
241 setthink(proj, W_Electro_Bolt_Think);
242 proj.nextthink = time;
243 proj.ltime = time + WEP_CVAR_PRI(electro, lifetime);
244 PROJECTILE_MAKETRIGGER(proj);
245 proj.projectiledeathtype = thiswep.m_id;
246 proj.weaponentity_fld = weaponentity;
247 setorigin(proj, w_shotorg);
250 set_movetype(proj, MOVETYPE_FLY);
251 W_SetupProjVelocity_PRI(proj, electro);
252 proj.angles = vectoangles(proj.velocity);
253 settouch(proj, W_Electro_TouchExplode);
254 setsize(proj, '0 0 -3', '0 0 -3');
255 proj.flags = FL_PROJECTILE;
256 IL_PUSH(g_projectiles, proj);
257 IL_PUSH(g_bot_dodge, proj);
258 proj.missile_flags = MIF_SPLASH;
260 CSQCProjectile(proj, true, PROJECTILE_ELECTRO_BEAM, true);
262 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
263 // proj.com_phys_pos = proj.origin;
264 // proj.com_phys_vel = proj.velocity;
267 void W_Electro_Orb_Follow_Think(entity this)
269 if (time > this.death_time)
271 adaptor_think2use_hittype_splash(this);
274 if (this.move_movetype == MOVETYPE_FOLLOW)
276 int lost = LostMovetypeFollow(this);
279 // FIXME if player disconnected, it isn't possible to drop the orb at player's origin
280 // see comment in LostMovetypeFollow implementation
286 // drop the orb at the corpse's location
287 PROJECTILE_MAKETRIGGER(this);
288 set_movetype(this, MOVETYPE_TOSS);
290 setthink(this, adaptor_think2use_hittype_splash);
291 this.nextthink = this.death_time;
295 this.nextthink = time;
298 void W_Electro_Orb_Stick(entity this, entity to)
300 entity newproj = spawn();
301 newproj.classname = this.classname;
303 newproj.bot_dodge = this.bot_dodge;
304 newproj.bot_dodgerating = this.bot_dodgerating;
306 newproj.owner = this.owner;
307 newproj.realowner = this.realowner;
308 setorigin(newproj, this.origin);
309 setmodel(newproj, MDL_PROJECTILE_ELECTRO);
310 setsize(newproj, this.mins, this.maxs);
311 newproj.angles = vectoangles(-trace_plane_normal); // face against the surface
312 newproj.traileffectnum = _particleeffectnum(EFFECT_TR_NEXUIZPLASMA.eent_eff_name);
314 newproj.movedir = -trace_plane_normal;
316 newproj.takedamage = this.takedamage;
317 newproj.damageforcescale = this.damageforcescale;
318 SetResourceExplicit(newproj, RES_HEALTH, GetResource(this, RES_HEALTH));
319 newproj.event_damage = this.event_damage;
320 newproj.spawnshieldtime = this.spawnshieldtime;
321 newproj.damagedbycontents = true;
322 IL_PUSH(g_damagedbycontents, newproj);
324 set_movetype(newproj, MOVETYPE_NONE); // lock the orb in place
325 newproj.projectiledeathtype = this.projectiledeathtype;
326 newproj.weaponentity_fld = this.weaponentity_fld;
328 settouch(newproj, func_null);
329 if(WEP_CVAR_SEC(electro, stick_lifetime) > 0){
330 newproj.death_time = time + WEP_CVAR_SEC(electro, stick_lifetime);
332 newproj.death_time = this.death_time;
334 newproj.use = this.use;
335 newproj.flags = this.flags;
336 IL_PUSH(g_projectiles, newproj);
337 IL_PUSH(g_bot_dodge, newproj);
339 // check if limits are enabled (we can tell by checking if the original orb is listed) and push it to the list if so
340 if(LimitedElectroBallRubbleList && IL_CONTAINS(LimitedElectroBallRubbleList, this))
342 ReplaceOldListedChildRubble(LimitedElectroBallRubbleList, newproj, this);
349 SetMovetypeFollow(newproj, to);
351 setthink(newproj, W_Electro_Orb_Follow_Think);
352 newproj.nextthink = time;
356 setthink(newproj, adaptor_think2use_hittype_splash);
357 newproj.nextthink = newproj.death_time;
361 void W_Electro_Orb_Touch(entity this, entity toucher)
363 PROJECTILE_TOUCH(this, toucher);
364 if(toucher.takedamage == DAMAGE_AIM && WEP_CVAR_SEC(electro, touchexplode))
365 { W_Electro_Explode(this, toucher); }
366 else if(toucher.owner != this.owner && toucher.classname != this.classname) // don't stick to player's other projectiles!
368 //UpdateCSQCProjectile(this);
369 spamsound(this, CH_SHOTS, SND_ELECTRO_BOUNCE, VOL_BASE, ATTEN_NORM);
370 this.projectiledeathtype |= HITTYPE_BOUNCE;
372 if(WEP_CVAR_SEC(electro, stick)){
373 if(WEP_CVAR_SEC(electro, stick_lifetime) == 0){
374 W_Electro_Explode(this, toucher);
376 W_Electro_Orb_Stick(this, toucher);
382 void W_Electro_Orb_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
384 if(GetResource(this, RES_HEALTH) <= 0)
387 // note: combos are usually triggered by W_Electro_TriggerCombo, not damage
388 float is_combo = (inflictor.classname == "electro_orb_chain" || inflictor.classname == "electro_bolt");
390 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, (is_combo ? 1 : -1)))
391 return; // g_projectiles_damage says to halt
393 TakeResource(this, RES_HEALTH, damage);
394 if(GetResource(this, RES_HEALTH) <= 0)
396 this.takedamage = DAMAGE_NO;
397 this.nextthink = time;
400 // change owner to whoever caused the combo explosion
401 this.realowner = inflictor.realowner;
402 this.classname = "electro_orb_chain";
403 setthink(this, W_Electro_ExplodeCombo);
404 // delay combo chains, looks cooler
405 // bound the length, inflictor may be in a galaxy far far away (warpzones)
406 float len = min(WEP_CVAR(electro, combo_radius), vlen(this.origin - inflictor.origin));
407 float delay = len / WEP_CVAR(electro, combo_speed);
408 this.nextthink = time + delay;
412 this.use = W_Electro_Explode_use;
413 setthink(this, adaptor_think2use); // not _hittype_splash, as this runs "immediately"
418 void W_Electro_Attack_Orb(Weapon thiswep, entity actor, .entity weaponentity)
420 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(electro, ammo), weaponentity);
422 W_SetupShot_ProjectileSize(
431 WEP_CVAR_SEC(electro, damage),
432 thiswep.m_id | HITTYPE_SECONDARY
435 w_shotdir = v_forward; // no TrueAim for grenades please
437 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
439 entity proj = new(electro_orb);
440 proj.owner = proj.realowner = actor;
441 proj.use = W_Electro_Explode_use;
442 setthink(proj, adaptor_think2use_hittype_splash);
443 proj.bot_dodge = true;
444 proj.bot_dodgerating = WEP_CVAR_SEC(electro, damage);
445 proj.nextthink = time + WEP_CVAR_SEC(electro, lifetime);
446 proj.death_time = time + WEP_CVAR_SEC(electro, lifetime);
447 PROJECTILE_MAKETRIGGER(proj);
448 proj.projectiledeathtype = thiswep.m_id | HITTYPE_SECONDARY;
449 proj.weaponentity_fld = weaponentity;
450 setorigin(proj, w_shotorg);
452 //proj.glow_size = 50;
453 //proj.glow_color = 45;
454 set_movetype(proj, MOVETYPE_BOUNCE);
455 W_SetupProjVelocity_UP_SEC(proj, electro);
456 settouch(proj, W_Electro_Orb_Touch);
457 setsize(proj, '-4 -4 -4', '4 4 4');
458 proj.takedamage = DAMAGE_YES;
459 proj.damageforcescale = WEP_CVAR_SEC(electro, damageforcescale);
460 SetResourceExplicit(proj, RES_HEALTH, WEP_CVAR_SEC(electro, health));
461 proj.event_damage = W_Electro_Orb_Damage;
462 proj.flags = FL_PROJECTILE;
463 IL_PUSH(g_projectiles, proj);
464 IL_PUSH(g_bot_dodge, proj);
465 proj.damagedbycontents = (WEP_CVAR_SEC(electro, damagedbycontents));
466 if(proj.damagedbycontents)
467 IL_PUSH(g_damagedbycontents, proj);
469 proj.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
470 proj.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
471 proj.missile_flags = MIF_SPLASH | MIF_ARC;
473 if(WEP_CVAR_SEC(electro, limit) > 0)
475 if (!LimitedElectroBallRubbleList)
476 LimitedElectroBallRubbleList = IL_NEW();
477 ListNewChildRubble(LimitedElectroBallRubbleList, proj);
478 LimitedChildrenRubble(LimitedElectroBallRubbleList, "electro_orb", WEP_CVAR_SEC(electro, limit), adaptor_think2use_hittype_splash, actor);
481 CSQCProjectile(proj, true, PROJECTILE_ELECTRO, false); // no culling, it has sound
483 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
486 void W_Electro_CheckAttack(Weapon thiswep, entity actor, .entity weaponentity, int fire)
488 if(actor.(weaponentity).electro_count > 1)
489 if(PHYS_INPUT_BUTTON_ATCK2(actor))
490 if(weapon_prepareattack(thiswep, actor, weaponentity, true, -1))
492 W_Electro_Attack_Orb(thiswep, actor, weaponentity);
493 actor.(weaponentity).electro_count -= 1;
494 actor.(weaponentity).electro_secondarytime = time;
495 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
498 w_ready(thiswep, actor, weaponentity, fire);
501 .float bot_secondary_electromooth;
503 METHOD(Electro, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
505 PHYS_INPUT_BUTTON_ATCK(actor) = PHYS_INPUT_BUTTON_ATCK2(actor) = false;
506 if(vdist(actor.origin - actor.enemy.origin, >, 1000)) { actor.bot_secondary_electromooth = 0; }
507 if(actor.bot_secondary_electromooth == 0)
511 if(WEP_CVAR_PRI(electro, speed))
512 shoot = bot_aim(actor, weaponentity, WEP_CVAR_PRI(electro, speed), 0, WEP_CVAR_PRI(electro, lifetime), false, true);
514 shoot = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false, true);
518 PHYS_INPUT_BUTTON_ATCK(actor) = true;
519 if(random() < 0.01) actor.bot_secondary_electromooth = 1;
524 if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(electro, speed), WEP_CVAR_SEC(electro, speed_up), WEP_CVAR_SEC(electro, lifetime), true, true))
526 PHYS_INPUT_BUTTON_ATCK2(actor) = true;
527 if(random() < 0.03) actor.bot_secondary_electromooth = 0;
531 METHOD(Electro, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
533 if(autocvar_g_balance_electro_reload_ammo) // forced reload // WEAPONTODO
535 float ammo_amount = 0;
536 if(actor.(weaponentity).clip_load >= WEP_CVAR_PRI(electro, ammo))
538 if(actor.(weaponentity).clip_load >= WEP_CVAR_SEC(electro, ammo))
543 thiswep.wr_reload(thiswep, actor, weaponentity);
550 if(time >= actor.(weaponentity).electro_secondarytime + WEP_CVAR_SEC(electro, refire2) * W_WeaponRateFactor(actor))
551 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire)))
553 W_Electro_Attack_Bolt(thiswep, actor, weaponentity);
554 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
559 if(time >= actor.(weaponentity).electro_secondarytime + WEP_CVAR_SEC(electro, refire) * W_WeaponRateFactor(actor))
560 if(weapon_prepareattack(thiswep, actor, weaponentity, true, -1))
562 W_Electro_Attack_Orb(thiswep, actor, weaponentity);
563 actor.(weaponentity).electro_count = WEP_CVAR_SEC(electro, count);
564 actor.(weaponentity).electro_secondarytime = time;
565 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
569 METHOD(Electro, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
571 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(electro, ammo);
572 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_PRI(electro, ammo);
575 METHOD(Electro, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
578 if(WEP_CVAR(electro, combo_safeammocheck)) // true if you can fire at least one secondary blob AND one primary shot after it, otherwise false.
580 ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
581 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
585 ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(electro, ammo);
586 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(electro, ammo);
590 METHOD(Electro, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
592 W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(electro, ammo), WEP_CVAR_SEC(electro, ammo)), SND_RELOAD);
594 METHOD(Electro, wr_suicidemessage, Notification(entity thiswep))
596 if(w_deathtype & HITTYPE_SECONDARY)
597 return WEAPON_ELECTRO_SUICIDE_ORBS;
599 return WEAPON_ELECTRO_SUICIDE_BOLT;
601 METHOD(Electro, wr_killmessage, Notification(entity thiswep))
603 if(w_deathtype & HITTYPE_SECONDARY)
605 return WEAPON_ELECTRO_MURDER_ORBS;
609 if(w_deathtype & HITTYPE_BOUNCE)
610 return WEAPON_ELECTRO_MURDER_COMBO;
612 return WEAPON_ELECTRO_MURDER_BOLT;
619 METHOD(Electro, wr_impacteffect, void(entity thiswep, entity actor))
622 org2 = w_org + w_backoff * 6;
623 if(w_deathtype & HITTYPE_SECONDARY)
625 pointparticles(EFFECT_ELECTRO_BALLEXPLODE, org2, '0 0 0', 1);
627 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);
631 if(w_deathtype & HITTYPE_BOUNCE)
633 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
634 pointparticles(EFFECT_ELECTRO_COMBO, org2, '0 0 0', 1);
636 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT_COMBO, VOL_BASE, ATTEN_NORM);
640 pointparticles(EFFECT_ELECTRO_IMPACT, org2, '0 0 0', 1);
642 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);