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; // .velocity must be != '0 0 0' for particle fx and decal to work
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; // .velocity must be != '0 0 0' for particle fx and decal to work
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.clipgroup = CLIPGROUP_UNHITTABLEPROJ;
246 proj.projectiledeathtype = thiswep.m_id;
247 proj.weaponentity_fld = weaponentity;
248 setorigin(proj, w_shotorg);
251 set_movetype(proj, MOVETYPE_FLY);
252 W_SetupProjVelocity_PRI(proj, electro);
253 proj.angles = vectoangles(proj.velocity);
254 settouch(proj, W_Electro_TouchExplode);
255 setsize(proj, BOLT_MINS, BOLT_MAXS);
256 proj.flags = FL_PROJECTILE;
257 IL_PUSH(g_projectiles, proj);
258 IL_PUSH(g_bot_dodge, proj);
259 proj.missile_flags = MIF_SPLASH;
261 CSQCProjectile(proj, true, PROJECTILE_ELECTRO_BEAM, true);
263 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
264 // proj.com_phys_pos = proj.origin;
265 // proj.com_phys_vel = proj.velocity;
268 void W_Electro_Orb_Follow_Think(entity this)
270 if (time > this.death_time)
272 adaptor_think2use_hittype_splash(this);
275 if (this.move_movetype == MOVETYPE_FOLLOW)
277 int lost = LostMovetypeFollow(this);
280 // FIXME if player disconnected, it isn't possible to drop the orb at player's origin
281 // see comment in LostMovetypeFollow implementation
287 // drop the orb at the corpse's location
288 PROJECTILE_MAKETRIGGER(this);
289 set_movetype(this, MOVETYPE_TOSS);
291 setthink(this, adaptor_think2use_hittype_splash);
292 this.nextthink = this.death_time;
296 this.nextthink = time;
299 void W_Electro_Orb_Stick(entity this, entity to)
301 entity newproj = spawn();
302 newproj.classname = this.classname;
304 newproj.bot_dodge = this.bot_dodge;
305 newproj.bot_dodgerating = this.bot_dodgerating;
307 newproj.owner = this.owner;
308 newproj.realowner = this.realowner;
309 setorigin(newproj, this.origin);
310 setmodel(newproj, MDL_PROJECTILE_ELECTRO);
311 setsize(newproj, this.mins, this.maxs);
312 newproj.angles = vectoangles(-trace_plane_normal); // face against the surface
313 newproj.traileffectnum = _particleeffectnum(EFFECT_TR_NEXUIZPLASMA.eent_eff_name);
315 newproj.movedir = -trace_plane_normal;
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 if(WEP_CVAR_SEC(electro, stick_lifetime) > 0){
331 newproj.death_time = time + WEP_CVAR_SEC(electro, stick_lifetime);
333 newproj.death_time = this.death_time;
335 newproj.use = this.use;
336 newproj.flags = this.flags;
337 IL_PUSH(g_projectiles, newproj);
338 IL_PUSH(g_bot_dodge, newproj);
340 // check if limits are enabled (we can tell by checking if the original orb is listed) and push it to the list if so
341 if(LimitedElectroBallRubbleList && IL_CONTAINS(LimitedElectroBallRubbleList, this))
343 ReplaceOldListedChildRubble(LimitedElectroBallRubbleList, newproj, this);
350 SetMovetypeFollow(newproj, to);
352 setthink(newproj, W_Electro_Orb_Follow_Think);
353 newproj.nextthink = time;
357 setthink(newproj, adaptor_think2use_hittype_splash);
358 newproj.nextthink = newproj.death_time;
362 void W_Electro_Orb_Touch(entity this, entity toucher)
364 PROJECTILE_TOUCH(this, toucher);
365 if(toucher.takedamage == DAMAGE_AIM && WEP_CVAR_SEC(electro, touchexplode))
366 { W_Electro_Explode(this, toucher); }
367 else if(toucher.owner != this.owner && toucher.classname != this.classname) // don't stick to player's other projectiles!
369 //UpdateCSQCProjectile(this);
370 spamsound(this, CH_SHOTS, SND_ELECTRO_BOUNCE, VOL_BASE, ATTEN_NORM);
371 this.projectiledeathtype |= HITTYPE_BOUNCE;
373 if(WEP_CVAR_SEC(electro, stick)){
374 if(WEP_CVAR_SEC(electro, stick_lifetime) == 0){
375 W_Electro_Explode(this, toucher);
377 W_Electro_Orb_Stick(this, toucher);
383 void W_Electro_Orb_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
385 if(GetResource(this, RES_HEALTH) <= 0)
388 // note: combos are usually triggered by W_Electro_TriggerCombo, not damage
389 float is_combo = (inflictor.classname == "electro_orb_chain" || inflictor.classname == "electro_bolt");
391 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, (is_combo ? 1 : -1)))
392 return; // g_projectiles_damage says to halt
394 TakeResource(this, RES_HEALTH, damage);
395 if(GetResource(this, RES_HEALTH) <= 0)
397 this.takedamage = DAMAGE_NO;
398 this.nextthink = time;
401 // change owner to whoever caused the combo explosion
402 this.realowner = inflictor.realowner;
403 this.classname = "electro_orb_chain";
404 setthink(this, W_Electro_ExplodeCombo);
405 // delay combo chains, looks cooler
406 // bound the length, inflictor may be in a galaxy far far away (warpzones)
407 float len = min(WEP_CVAR(electro, combo_radius), vlen(this.origin - inflictor.origin));
408 float delay = len / WEP_CVAR(electro, combo_speed);
409 this.nextthink = time + delay;
413 this.use = W_Electro_Explode_use;
414 setthink(this, adaptor_think2use); // not _hittype_splash, as this runs "immediately"
419 void W_Electro_Attack_Orb(Weapon thiswep, entity actor, .entity weaponentity)
421 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(electro, ammo), weaponentity);
423 W_SetupShot_ProjectileSize(
432 WEP_CVAR_SEC(electro, damage),
433 thiswep.m_id | HITTYPE_SECONDARY
436 w_shotdir = v_forward; // no TrueAim for grenades please
438 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
440 entity proj = new(electro_orb);
441 proj.owner = proj.realowner = actor;
442 proj.use = W_Electro_Explode_use;
443 setthink(proj, adaptor_think2use_hittype_splash);
444 proj.bot_dodge = true;
445 proj.bot_dodgerating = WEP_CVAR_SEC(electro, damage);
446 proj.nextthink = time + WEP_CVAR_SEC(electro, lifetime);
447 proj.death_time = time + WEP_CVAR_SEC(electro, lifetime);
448 PROJECTILE_MAKETRIGGER(proj);
449 proj.projectiledeathtype = thiswep.m_id | HITTYPE_SECONDARY;
450 proj.weaponentity_fld = weaponentity;
451 setorigin(proj, w_shotorg);
453 //proj.glow_size = 50;
454 //proj.glow_color = 45;
455 set_movetype(proj, MOVETYPE_BOUNCE);
456 W_SetupProjVelocity_UP_SEC(proj, electro);
457 settouch(proj, W_Electro_Orb_Touch);
458 setsize(proj, ORB_MINS, ORB_MAXS);
459 proj.takedamage = DAMAGE_YES;
460 proj.damageforcescale = WEP_CVAR_SEC(electro, damageforcescale);
461 SetResourceExplicit(proj, RES_HEALTH, WEP_CVAR_SEC(electro, health));
462 proj.event_damage = W_Electro_Orb_Damage;
463 proj.flags = FL_PROJECTILE;
464 IL_PUSH(g_projectiles, proj);
465 IL_PUSH(g_bot_dodge, proj);
466 proj.damagedbycontents = (WEP_CVAR_SEC(electro, damagedbycontents));
467 if(proj.damagedbycontents)
468 IL_PUSH(g_damagedbycontents, proj);
470 proj.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
471 proj.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
472 proj.missile_flags = MIF_SPLASH | MIF_ARC;
474 if(WEP_CVAR_SEC(electro, limit) > 0)
476 if (!LimitedElectroBallRubbleList)
477 LimitedElectroBallRubbleList = IL_NEW();
478 ListNewChildRubble(LimitedElectroBallRubbleList, proj);
479 LimitedChildrenRubble(LimitedElectroBallRubbleList, "electro_orb", WEP_CVAR_SEC(electro, limit), adaptor_think2use_hittype_splash, actor);
482 CSQCProjectile(proj, true, PROJECTILE_ELECTRO, false); // no culling, it has sound
484 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
487 void W_Electro_CheckAttack(Weapon thiswep, entity actor, .entity weaponentity, int fire)
489 if(actor.(weaponentity).electro_count > 1)
490 if(PHYS_INPUT_BUTTON_ATCK2(actor))
491 if(weapon_prepareattack(thiswep, actor, weaponentity, true, -1))
493 W_Electro_Attack_Orb(thiswep, actor, weaponentity);
494 actor.(weaponentity).electro_count -= 1;
495 actor.(weaponentity).electro_secondarytime = time;
496 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
499 w_ready(thiswep, actor, weaponentity, fire);
502 .float bot_secondary_electromooth;
504 METHOD(Electro, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
506 PHYS_INPUT_BUTTON_ATCK(actor) = PHYS_INPUT_BUTTON_ATCK2(actor) = false;
507 if(vdist(actor.origin - actor.enemy.origin, >, 1000)) { actor.bot_secondary_electromooth = 0; }
508 if(actor.bot_secondary_electromooth == 0)
512 if(WEP_CVAR_PRI(electro, speed))
513 shoot = bot_aim(actor, weaponentity, WEP_CVAR_PRI(electro, speed), 0, WEP_CVAR_PRI(electro, lifetime), false, true);
515 shoot = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false, true);
519 PHYS_INPUT_BUTTON_ATCK(actor) = true;
520 if(random() < 0.01) actor.bot_secondary_electromooth = 1;
525 if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(electro, speed), WEP_CVAR_SEC(electro, speed_up), WEP_CVAR_SEC(electro, lifetime), true, true))
527 PHYS_INPUT_BUTTON_ATCK2(actor) = true;
528 if(random() < 0.03) actor.bot_secondary_electromooth = 0;
532 METHOD(Electro, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
534 if(autocvar_g_balance_electro_reload_ammo) // forced reload // WEAPONTODO
536 float ammo_amount = 0;
537 if(actor.(weaponentity).clip_load >= WEP_CVAR_PRI(electro, ammo))
539 if(actor.(weaponentity).clip_load >= WEP_CVAR_SEC(electro, ammo))
544 thiswep.wr_reload(thiswep, actor, weaponentity);
551 if(time >= actor.(weaponentity).electro_secondarytime + WEP_CVAR_SEC(electro, refire2) * W_WeaponRateFactor(actor))
552 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire)))
554 W_Electro_Attack_Bolt(thiswep, actor, weaponentity);
555 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
560 if(time >= actor.(weaponentity).electro_secondarytime + WEP_CVAR_SEC(electro, refire) * W_WeaponRateFactor(actor))
561 if(weapon_prepareattack(thiswep, actor, weaponentity, true, -1))
563 W_Electro_Attack_Orb(thiswep, actor, weaponentity);
564 actor.(weaponentity).electro_count = WEP_CVAR_SEC(electro, count);
565 actor.(weaponentity).electro_secondarytime = time;
566 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
570 METHOD(Electro, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
572 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(electro, ammo);
573 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_PRI(electro, ammo);
576 METHOD(Electro, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
579 if(WEP_CVAR(electro, combo_safeammocheck)) // true if you can fire at least one secondary blob AND one primary shot after it, otherwise false.
581 ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
582 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
586 ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(electro, ammo);
587 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(electro, ammo);
591 METHOD(Electro, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
593 W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(electro, ammo), WEP_CVAR_SEC(electro, ammo)), SND_RELOAD);
595 METHOD(Electro, wr_suicidemessage, Notification(entity thiswep))
597 if(w_deathtype & HITTYPE_SECONDARY)
598 return WEAPON_ELECTRO_SUICIDE_ORBS;
600 return WEAPON_ELECTRO_SUICIDE_BOLT;
602 METHOD(Electro, wr_killmessage, Notification(entity thiswep))
604 if(w_deathtype & HITTYPE_SECONDARY)
606 return WEAPON_ELECTRO_MURDER_ORBS;
610 if(w_deathtype & HITTYPE_BOUNCE)
611 return WEAPON_ELECTRO_MURDER_COMBO;
613 return WEAPON_ELECTRO_MURDER_BOLT;
620 METHOD(Electro, wr_impacteffect, void(entity thiswep, entity actor))
622 vector org2 = w_org + w_backoff * 2;
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);