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 // do we allow thruwall triggering?
14 if(WEP_CVAR(electro, combo_comboradius_thruwall))
16 // if distance is greater than thruwall distance, check to make sure it's not through a wall
17 if(vdist(e.WarpZone_findradius_dist, >, WEP_CVAR(electro, combo_comboradius_thruwall)))
19 WarpZone_TraceLine(org, e.origin, MOVE_NOMONSTERS, e);
20 if(trace_fraction != 1)
22 // trigger is through a wall and outside of thruwall range, abort
29 // change owner to whoever caused the combo explosion
31 e.takedamage = DAMAGE_NO;
32 e.classname = "electro_orb_chain";
34 // now set the next one to trigger as well
35 setthink(e, W_Electro_ExplodeCombo);
37 // delay combo chains, looks cooler
39 if (WEP_CVAR(electro, combo_speed))
40 delay = vlen(e.WarpZone_findradius_dist) / WEP_CVAR(electro, combo_speed);
41 e.nextthink = time + delay;
47 void W_Electro_ExplodeCombo(entity this)
49 W_Electro_TriggerCombo(this.origin, WEP_CVAR(electro, combo_comboradius), this.realowner);
51 this.event_damage = func_null;
52 this.velocity = this.movedir; // particle fx and decals need .velocity
57 WEP_CVAR(electro, combo_damage),
58 WEP_CVAR(electro, combo_edgedamage),
59 WEP_CVAR(electro, combo_radius),
62 WEP_CVAR(electro, combo_force),
63 WEP_ELECTRO.m_id | HITTYPE_BOUNCE, // use THIS type for a combo because primary can't bounce
64 this.weaponentity_fld,
71 void W_Electro_Explode(entity this, entity directhitentity)
73 if(directhitentity.takedamage == DAMAGE_AIM)
74 if(IS_PLAYER(directhitentity))
75 if(DIFF_TEAM(this.realowner, directhitentity))
76 if(!IS_DEAD(directhitentity))
77 if(IsFlying(directhitentity))
78 Send_Notification(NOTIF_ONE, this.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_ELECTROBITCH);
80 this.event_damage = func_null;
81 this.takedamage = DAMAGE_NO;
82 this.velocity = this.movedir; // particle fx and decals need .velocity
84 if(this.move_movetype == MOVETYPE_BOUNCE || this.classname == "electro_orb") // TODO: classname is more reliable anyway?
89 WEP_CVAR_SEC(electro, damage),
90 WEP_CVAR_SEC(electro, edgedamage),
91 WEP_CVAR_SEC(electro, radius),
94 WEP_CVAR_SEC(electro, force),
95 this.projectiledeathtype,
96 this.weaponentity_fld,
102 W_Electro_TriggerCombo(this.origin, WEP_CVAR_PRI(electro, comboradius), this.realowner);
106 WEP_CVAR_PRI(electro, damage),
107 WEP_CVAR_PRI(electro, edgedamage),
108 WEP_CVAR_PRI(electro, radius),
111 WEP_CVAR_PRI(electro, force),
112 this.projectiledeathtype,
113 this.weaponentity_fld,
121 void W_Electro_Explode_use(entity this, entity actor, entity trigger)
123 W_Electro_Explode(this, trigger);
126 void W_Electro_TouchExplode(entity this, entity toucher)
128 PROJECTILE_TOUCH(this, toucher);
129 W_Electro_Explode(this, toucher);
133 void sys_phys_update_single(entity this);
135 void W_Electro_Bolt_Think(entity this)
137 // sys_phys_update_single(this);
138 if(time >= this.ltime)
140 this.use(this, NULL, NULL);
144 if(WEP_CVAR_PRI(electro, midaircombo_radius))
147 entity e = WarpZone_FindRadius(this.origin, WEP_CVAR_PRI(electro, midaircombo_radius), true);
149 // loop through nearby orbs and trigger them
152 if(e.classname == "electro_orb")
155 if (this.owner == e.owner)
157 explode = WEP_CVAR_PRI(electro, midaircombo_own);
159 else if (SAME_TEAM(this.owner, e.owner))
161 explode = WEP_CVAR_PRI(electro, midaircombo_teammate);
165 explode = WEP_CVAR_PRI(electro, midaircombo_enemy);
170 // change owner to whoever caused the combo explosion
171 e.realowner = this.realowner;
172 e.takedamage = DAMAGE_NO;
173 e.classname = "electro_orb_chain";
175 // Only first orb explosion uses midaircombo_speed, others use the normal combo_speed.
176 // This allows to avoid the delay on the first explosion which looks better
177 // (the bolt and orb should explode together because they interacted together)
178 // while keeping the chaining delay.
179 setthink(e, W_Electro_ExplodeCombo);
181 if (WEP_CVAR_PRI(electro, midaircombo_speed))
182 delay = vlen(e.WarpZone_findradius_dist) / WEP_CVAR_PRI(electro, midaircombo_speed);
183 e.nextthink = time + delay;
191 // if we triggered an orb, should we explode? if not, lets try again next time
192 if(found && WEP_CVAR_PRI(electro, midaircombo_explode))
193 { this.use(this, NULL, NULL); }
195 { this.nextthink = min(time + WEP_CVAR_PRI(electro, midaircombo_interval), this.ltime); }
197 else { this.nextthink = this.ltime; }
198 // this.nextthink = time;
201 void W_Electro_Attack_Bolt(Weapon thiswep, entity actor, .entity weaponentity)
205 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(electro, ammo), weaponentity);
207 W_SetupShot_ProjectileSize(
216 WEP_CVAR_PRI(electro, damage),
220 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
222 proj = new(electro_bolt);
223 proj.owner = proj.realowner = actor;
224 proj.bot_dodge = true;
225 proj.bot_dodgerating = WEP_CVAR_PRI(electro, damage);
226 proj.use = W_Electro_Explode_use;
227 setthink(proj, W_Electro_Bolt_Think);
228 proj.nextthink = time;
229 proj.ltime = time + WEP_CVAR_PRI(electro, lifetime);
230 PROJECTILE_MAKETRIGGER(proj);
231 proj.projectiledeathtype = thiswep.m_id;
232 proj.weaponentity_fld = weaponentity;
233 setorigin(proj, w_shotorg);
236 set_movetype(proj, MOVETYPE_FLY);
237 W_SetupProjVelocity_PRI(proj, electro);
238 proj.angles = vectoangles(proj.velocity);
239 settouch(proj, W_Electro_TouchExplode);
240 setsize(proj, '0 0 -3', '0 0 -3');
241 proj.flags = FL_PROJECTILE;
242 IL_PUSH(g_projectiles, proj);
243 IL_PUSH(g_bot_dodge, proj);
244 proj.missile_flags = MIF_SPLASH;
246 CSQCProjectile(proj, true, PROJECTILE_ELECTRO_BEAM, true);
248 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
249 // proj.com_phys_pos = proj.origin;
250 // proj.com_phys_vel = proj.velocity;
253 void W_Electro_Orb_Follow_Think(entity this)
255 if (time > this.death_time)
257 adaptor_think2use_hittype_splash(this);
260 if (this.move_movetype == MOVETYPE_FOLLOW)
262 int lost = LostMovetypeFollow(this);
265 // FIXME if player disconnected, it isn't possible to drop the orb at player's origin
266 // see comment in LostMovetypeFollow implementation
272 // drop the orb at the corpse's location
273 PROJECTILE_MAKETRIGGER(this);
274 set_movetype(this, MOVETYPE_TOSS);
276 setthink(this, adaptor_think2use_hittype_splash);
277 this.nextthink = this.death_time;
281 this.nextthink = time;
284 void W_Electro_Orb_Stick(entity this, entity to)
286 entity newproj = spawn();
287 newproj.classname = this.classname;
289 newproj.bot_dodge = this.bot_dodge;
290 newproj.bot_dodgerating = this.bot_dodgerating;
292 newproj.owner = this.owner;
293 newproj.realowner = this.realowner;
294 setorigin(newproj, this.origin);
295 setmodel(newproj, MDL_PROJECTILE_ELECTRO);
296 setsize(newproj, this.mins, this.maxs);
297 newproj.angles = vectoangles(-trace_plane_normal); // face against the surface
299 newproj.movedir = -trace_plane_normal;
301 newproj.takedamage = this.takedamage;
302 newproj.damageforcescale = this.damageforcescale;
303 SetResourceExplicit(newproj, RES_HEALTH, GetResource(this, RES_HEALTH));
304 newproj.event_damage = this.event_damage;
305 newproj.spawnshieldtime = this.spawnshieldtime;
306 newproj.damagedbycontents = true;
307 IL_PUSH(g_damagedbycontents, newproj);
309 set_movetype(newproj, MOVETYPE_NONE); // lock the orb in place
310 newproj.projectiledeathtype = this.projectiledeathtype;
311 newproj.weaponentity_fld = this.weaponentity_fld;
313 settouch(newproj, func_null);
314 newproj.death_time = this.death_time;
315 newproj.use = this.use;
316 newproj.flags = this.flags;
317 IL_PUSH(g_projectiles, newproj);
318 IL_PUSH(g_bot_dodge, newproj);
320 // check if limits are enabled (we can tell by checking if the original orb is listed) and push it to the list if so
321 if(LimitedElectroBallRubbleList && IL_CONTAINS(LimitedElectroBallRubbleList, this))
323 ReplaceOldListedChildRubble(LimitedElectroBallRubbleList, newproj, this);
330 SetMovetypeFollow(newproj, to);
332 setthink(newproj, W_Electro_Orb_Follow_Think);
333 newproj.nextthink = time;
337 setthink(newproj, adaptor_think2use_hittype_splash);
338 newproj.nextthink = newproj.death_time;
342 void W_Electro_Orb_Touch(entity this, entity toucher)
344 PROJECTILE_TOUCH(this, toucher);
345 if(toucher.takedamage == DAMAGE_AIM && WEP_CVAR_SEC(electro, touchexplode))
346 { W_Electro_Explode(this, toucher); }
347 else if(toucher.owner != this.owner && toucher.classname != this.classname) // don't stick to player's other projectiles!
349 //UpdateCSQCProjectile(this);
350 spamsound(this, CH_SHOTS, SND_ELECTRO_BOUNCE, VOL_BASE, ATTEN_NORM);
351 this.projectiledeathtype |= HITTYPE_BOUNCE;
353 if(WEP_CVAR_SEC(electro, stick))
354 W_Electro_Orb_Stick(this, toucher);
358 void W_Electro_Orb_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
360 if(GetResource(this, RES_HEALTH) <= 0)
363 // note: combos are usually triggered by W_Electro_TriggerCombo, not damage
364 float is_combo = (inflictor.classname == "electro_orb_chain" || inflictor.classname == "electro_bolt");
366 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, (is_combo ? 1 : -1)))
367 return; // g_projectiles_damage says to halt
369 TakeResource(this, RES_HEALTH, damage);
370 if(GetResource(this, RES_HEALTH) <= 0)
372 this.takedamage = DAMAGE_NO;
373 this.nextthink = time;
376 // change owner to whoever caused the combo explosion
377 this.realowner = inflictor.realowner;
378 this.classname = "electro_orb_chain";
379 setthink(this, W_Electro_ExplodeCombo);
380 // delay combo chains, looks cooler
381 // bound the length, inflictor may be in a galaxy far far away (warpzones)
382 float len = min(WEP_CVAR(electro, combo_radius), vlen(this.origin - inflictor.origin));
383 float delay = len / WEP_CVAR(electro, combo_speed);
384 this.nextthink = time + delay;
388 this.use = W_Electro_Explode_use;
389 setthink(this, adaptor_think2use); // not _hittype_splash, as this runs "immediately"
394 void W_Electro_Attack_Orb(Weapon thiswep, entity actor, .entity weaponentity)
396 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(electro, ammo), weaponentity);
398 W_SetupShot_ProjectileSize(
407 WEP_CVAR_SEC(electro, damage),
408 thiswep.m_id | HITTYPE_SECONDARY
411 w_shotdir = v_forward; // no TrueAim for grenades please
413 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
415 entity proj = new(electro_orb);
416 proj.owner = proj.realowner = actor;
417 proj.use = W_Electro_Explode_use;
418 setthink(proj, adaptor_think2use_hittype_splash);
419 proj.bot_dodge = true;
420 proj.bot_dodgerating = WEP_CVAR_SEC(electro, damage);
421 proj.nextthink = time + WEP_CVAR_SEC(electro, lifetime);
422 proj.death_time = time + WEP_CVAR_SEC(electro, lifetime);
423 PROJECTILE_MAKETRIGGER(proj);
424 proj.projectiledeathtype = thiswep.m_id | HITTYPE_SECONDARY;
425 proj.weaponentity_fld = weaponentity;
426 setorigin(proj, w_shotorg);
428 //proj.glow_size = 50;
429 //proj.glow_color = 45;
430 set_movetype(proj, MOVETYPE_BOUNCE);
431 W_SetupProjVelocity_UP_SEC(proj, electro);
432 settouch(proj, W_Electro_Orb_Touch);
433 setsize(proj, '-4 -4 -4', '4 4 4');
434 proj.takedamage = DAMAGE_YES;
435 proj.damageforcescale = WEP_CVAR_SEC(electro, damageforcescale);
436 SetResourceExplicit(proj, RES_HEALTH, WEP_CVAR_SEC(electro, health));
437 proj.event_damage = W_Electro_Orb_Damage;
438 proj.flags = FL_PROJECTILE;
439 IL_PUSH(g_projectiles, proj);
440 IL_PUSH(g_bot_dodge, proj);
441 proj.damagedbycontents = (WEP_CVAR_SEC(electro, damagedbycontents));
442 if(proj.damagedbycontents)
443 IL_PUSH(g_damagedbycontents, proj);
445 proj.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
446 proj.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
447 proj.missile_flags = MIF_SPLASH | MIF_ARC;
449 if(WEP_CVAR_SEC(electro, limit) > 0)
451 if (!LimitedElectroBallRubbleList)
452 LimitedElectroBallRubbleList = IL_NEW();
453 ListNewChildRubble(LimitedElectroBallRubbleList, proj);
454 LimitedChildrenRubble(LimitedElectroBallRubbleList, "electro_orb", WEP_CVAR_SEC(electro, limit), adaptor_think2use_hittype_splash, actor);
457 CSQCProjectile(proj, true, PROJECTILE_ELECTRO, false); // no culling, it has sound
459 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
462 void W_Electro_CheckAttack(Weapon thiswep, entity actor, .entity weaponentity, int fire)
464 if(actor.(weaponentity).electro_count > 1)
465 if(PHYS_INPUT_BUTTON_ATCK2(actor))
466 if(weapon_prepareattack(thiswep, actor, weaponentity, true, -1))
468 W_Electro_Attack_Orb(thiswep, actor, weaponentity);
469 actor.(weaponentity).electro_count -= 1;
470 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
473 // WEAPONTODO: when the player releases the button, cut down the length of refire2?
474 w_ready(thiswep, actor, weaponentity, fire);
477 .float bot_secondary_electromooth;
479 METHOD(Electro, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
481 PHYS_INPUT_BUTTON_ATCK(actor) = PHYS_INPUT_BUTTON_ATCK2(actor) = false;
482 if(vdist(actor.origin - actor.enemy.origin, >, 1000)) { actor.bot_secondary_electromooth = 0; }
483 if(actor.bot_secondary_electromooth == 0)
487 if(WEP_CVAR_PRI(electro, speed))
488 shoot = bot_aim(actor, weaponentity, WEP_CVAR_PRI(electro, speed), 0, WEP_CVAR_PRI(electro, lifetime), false);
490 shoot = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
494 PHYS_INPUT_BUTTON_ATCK(actor) = true;
495 if(random() < 0.01) actor.bot_secondary_electromooth = 1;
500 if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(electro, speed), WEP_CVAR_SEC(electro, speed_up), WEP_CVAR_SEC(electro, lifetime), true))
502 PHYS_INPUT_BUTTON_ATCK2(actor) = true;
503 if(random() < 0.03) actor.bot_secondary_electromooth = 0;
507 METHOD(Electro, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
509 if(autocvar_g_balance_electro_reload_ammo) // forced reload // WEAPONTODO
511 float ammo_amount = 0;
512 if(actor.(weaponentity).clip_load >= WEP_CVAR_PRI(electro, ammo))
514 if(actor.(weaponentity).clip_load >= WEP_CVAR_SEC(electro, ammo))
519 thiswep.wr_reload(thiswep, actor, weaponentity);
526 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire)))
528 W_Electro_Attack_Bolt(thiswep, actor, weaponentity);
529 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
534 if(time >= actor.(weaponentity).electro_secondarytime)
535 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(electro, refire)))
537 W_Electro_Attack_Orb(thiswep, actor, weaponentity);
538 actor.(weaponentity).electro_count = WEP_CVAR_SEC(electro, count);
539 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
540 actor.(weaponentity).electro_secondarytime = time + WEP_CVAR_SEC(electro, refire2) * W_WeaponRateFactor(actor);
544 METHOD(Electro, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
546 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(electro, ammo);
547 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_PRI(electro, ammo);
550 METHOD(Electro, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
553 if(WEP_CVAR(electro, combo_safeammocheck)) // true if you can fire at least one secondary blob AND one primary shot after it, otherwise false.
555 ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
556 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
560 ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(electro, ammo);
561 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(electro, ammo);
565 METHOD(Electro, wr_resetplayer, void(entity thiswep, entity actor))
567 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
569 .entity weaponentity = weaponentities[slot];
570 actor.(weaponentity).electro_secondarytime = time;
573 METHOD(Electro, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
575 W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(electro, ammo), WEP_CVAR_SEC(electro, ammo)), SND_RELOAD);
577 METHOD(Electro, wr_suicidemessage, Notification(entity thiswep))
579 if(w_deathtype & HITTYPE_SECONDARY)
580 return WEAPON_ELECTRO_SUICIDE_ORBS;
582 return WEAPON_ELECTRO_SUICIDE_BOLT;
584 METHOD(Electro, wr_killmessage, Notification(entity thiswep))
586 if(w_deathtype & HITTYPE_SECONDARY)
588 return WEAPON_ELECTRO_MURDER_ORBS;
592 if(w_deathtype & HITTYPE_BOUNCE)
593 return WEAPON_ELECTRO_MURDER_COMBO;
595 return WEAPON_ELECTRO_MURDER_BOLT;
602 METHOD(Electro, wr_impacteffect, void(entity thiswep, entity actor))
605 org2 = w_org + w_backoff * 6;
606 if(w_deathtype & HITTYPE_SECONDARY)
608 pointparticles(EFFECT_ELECTRO_BALLEXPLODE, org2, '0 0 0', 1);
610 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);
614 if(w_deathtype & HITTYPE_BOUNCE)
616 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
617 pointparticles(EFFECT_ELECTRO_COMBO, org2, '0 0 0', 1);
619 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT_COMBO, VOL_BASE, ATTEN_NORM);
623 pointparticles(EFFECT_ELECTRO_IMPACT, org2, '0 0 0', 1);
625 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);