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
42 (WEP_CVAR(electro, combo_speed) ?
43 (vlen(e.WarpZone_findradius_dist) / WEP_CVAR(electro, combo_speed))
53 void W_Electro_ExplodeCombo(entity this)
55 W_Electro_TriggerCombo(this.origin, WEP_CVAR(electro, combo_comboradius), this.realowner);
57 this.event_damage = func_null;
62 WEP_CVAR(electro, combo_damage),
63 WEP_CVAR(electro, combo_edgedamage),
64 WEP_CVAR(electro, combo_radius),
67 WEP_CVAR(electro, combo_force),
68 WEP_ELECTRO.m_id | HITTYPE_BOUNCE, // use THIS type for a combo because primary can't bounce
69 this.weaponentity_fld,
76 void W_Electro_Explode(entity this, entity directhitentity)
78 if(directhitentity.takedamage == DAMAGE_AIM)
79 if(IS_PLAYER(directhitentity))
80 if(DIFF_TEAM(this.realowner, directhitentity))
81 if(!IS_DEAD(directhitentity))
82 if(IsFlying(directhitentity))
83 Send_Notification(NOTIF_ONE, this.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_ELECTROBITCH);
85 this.event_damage = func_null;
86 this.takedamage = DAMAGE_NO;
88 if(this.move_movetype == MOVETYPE_BOUNCE || this.classname == "electro_orb") // TODO: classname is more reliable anyway?
93 WEP_CVAR_SEC(electro, damage),
94 WEP_CVAR_SEC(electro, edgedamage),
95 WEP_CVAR_SEC(electro, radius),
98 WEP_CVAR_SEC(electro, force),
99 this.projectiledeathtype,
100 this.weaponentity_fld,
106 W_Electro_TriggerCombo(this.origin, WEP_CVAR_PRI(electro, comboradius), this.realowner);
110 WEP_CVAR_PRI(electro, damage),
111 WEP_CVAR_PRI(electro, edgedamage),
112 WEP_CVAR_PRI(electro, radius),
115 WEP_CVAR_PRI(electro, force),
116 this.projectiledeathtype,
117 this.weaponentity_fld,
125 void W_Electro_Explode_use(entity this, entity actor, entity trigger)
127 W_Electro_Explode(this, trigger);
130 void W_Electro_TouchExplode(entity this, entity toucher)
132 PROJECTILE_TOUCH(this, toucher);
133 W_Electro_Explode(this, toucher);
137 void sys_phys_update_single(entity this);
139 void W_Electro_Bolt_Think(entity this)
141 // sys_phys_update_single(this);
142 if(time >= this.ltime)
144 this.use(this, NULL, NULL);
148 if(WEP_CVAR_PRI(electro, midaircombo_radius))
151 entity e = WarpZone_FindRadius(this.origin, WEP_CVAR_PRI(electro, midaircombo_radius), true);
153 // loop through nearby orbs and trigger them
156 if(e.classname == "electro_orb")
159 if (this.owner == e.owner)
161 explode = WEP_CVAR_PRI(electro, midaircombo_own);
163 else if (SAME_TEAM(this.owner, e.owner))
165 explode = WEP_CVAR_PRI(electro, midaircombo_teammate);
169 explode = WEP_CVAR_PRI(electro, midaircombo_enemy);
174 // change owner to whoever caused the combo explosion
175 e.realowner = this.realowner;
176 e.takedamage = DAMAGE_NO;
177 e.classname = "electro_orb_chain";
179 // Only first orb explosion uses midaircombo_speed, others use the normal combo_speed.
180 // This allows to avoid the delay on the first explosion which looks better
181 // (the bolt and orb should explode together because they interacted together)
182 // while keeping the chaining delay.
183 setthink(e, W_Electro_ExplodeCombo);
188 (WEP_CVAR_PRI(electro, midaircombo_speed) ?
189 (vlen(e.WarpZone_findradius_dist) / WEP_CVAR_PRI(electro, midaircombo_speed))
202 // if we triggered an orb, should we explode? if not, lets try again next time
203 if(found && WEP_CVAR_PRI(electro, midaircombo_explode))
204 { this.use(this, NULL, NULL); }
206 { this.nextthink = min(time + WEP_CVAR_PRI(electro, midaircombo_interval), this.ltime); }
208 else { this.nextthink = this.ltime; }
209 // this.nextthink = time;
212 void W_Electro_Attack_Bolt(Weapon thiswep, entity actor, .entity weaponentity)
216 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(electro, ammo), weaponentity);
218 W_SetupShot_ProjectileSize(
227 WEP_CVAR_PRI(electro, damage),
231 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
233 proj = new(electro_bolt);
234 proj.owner = proj.realowner = actor;
235 proj.bot_dodge = true;
236 proj.bot_dodgerating = WEP_CVAR_PRI(electro, damage);
237 proj.use = W_Electro_Explode_use;
238 setthink(proj, W_Electro_Bolt_Think);
239 proj.nextthink = time;
240 proj.ltime = time + WEP_CVAR_PRI(electro, lifetime);
241 PROJECTILE_MAKETRIGGER(proj);
242 proj.projectiledeathtype = thiswep.m_id;
243 proj.weaponentity_fld = weaponentity;
244 setorigin(proj, w_shotorg);
247 set_movetype(proj, MOVETYPE_FLY);
248 W_SetupProjVelocity_PRI(proj, electro);
249 proj.angles = vectoangles(proj.velocity);
250 settouch(proj, W_Electro_TouchExplode);
251 setsize(proj, '0 0 -3', '0 0 -3');
252 proj.flags = FL_PROJECTILE;
253 IL_PUSH(g_projectiles, proj);
254 IL_PUSH(g_bot_dodge, proj);
255 proj.missile_flags = MIF_SPLASH;
257 CSQCProjectile(proj, true, PROJECTILE_ELECTRO_BEAM, true);
259 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
260 // proj.com_phys_pos = proj.origin;
261 // proj.com_phys_vel = proj.velocity;
264 void W_Electro_Orb_Stick(entity this, entity to)
266 entity newproj = spawn();
267 newproj.classname = this.classname;
269 newproj.bot_dodge = this.bot_dodge;
270 newproj.bot_dodgerating = this.bot_dodgerating;
272 newproj.owner = this.owner;
273 newproj.realowner = this.realowner;
274 setsize(newproj, this.mins, this.maxs);
275 setorigin(newproj, this.origin);
276 setmodel(newproj, MDL_PROJECTILE_ELECTRO);
277 newproj.angles = vectoangles(-trace_plane_normal); // face against the surface
279 newproj.takedamage = this.takedamage;
280 newproj.damageforcescale = this.damageforcescale;
281 SetResourceExplicit(newproj, RES_HEALTH, GetResource(this, RES_HEALTH));
282 newproj.event_damage = this.event_damage;
283 newproj.spawnshieldtime = this.spawnshieldtime;
284 newproj.damagedbycontents = true;
285 IL_PUSH(g_damagedbycontents, newproj);
287 set_movetype(newproj, MOVETYPE_NONE); // lock the orb in place
288 newproj.projectiledeathtype = this.projectiledeathtype;
289 newproj.weaponentity_fld = this.weaponentity_fld;
291 settouch(newproj, func_null);
292 setthink(newproj, getthink(this));
293 newproj.nextthink = this.nextthink;
294 newproj.use = this.use;
295 newproj.flags = this.flags;
296 IL_PUSH(g_projectiles, newproj);
297 IL_PUSH(g_bot_dodge, newproj);
299 // check if limits are enabled (we can tell by checking if the original orb is listed) and push it to the list if so
300 if(IL_CONTAINS(g_rubble, this))
302 newproj.creationtime = this.creationtime;
303 IL_PUSH(g_rubble, newproj);
309 SetMovetypeFollow(newproj, to);
312 void W_Electro_Orb_Touch(entity this, entity toucher)
314 PROJECTILE_TOUCH(this, toucher);
315 if(toucher.takedamage == DAMAGE_AIM && WEP_CVAR_SEC(electro, touchexplode))
316 { W_Electro_Explode(this, toucher); }
317 else if(toucher.owner != this.owner && toucher.classname != this.classname) // don't stick to player's other projectiles!
319 //UpdateCSQCProjectile(this);
320 spamsound(this, CH_SHOTS, SND_ELECTRO_BOUNCE, VOL_BASE, ATTEN_NORM);
321 this.projectiledeathtype |= HITTYPE_BOUNCE;
323 if(WEP_CVAR_SEC(electro, stick))
324 W_Electro_Orb_Stick(this, toucher);
328 void W_Electro_Orb_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
330 if(GetResource(this, RES_HEALTH) <= 0)
333 // note: combos are usually triggered by W_Electro_TriggerCombo, not damage
334 float is_combo = (inflictor.classname == "electro_orb_chain" || inflictor.classname == "electro_bolt");
336 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, (is_combo ? 1 : -1)))
337 return; // g_projectiles_damage says to halt
339 TakeResource(this, RES_HEALTH, damage);
340 if(GetResource(this, RES_HEALTH) <= 0)
342 this.takedamage = DAMAGE_NO;
343 this.nextthink = time;
346 // change owner to whoever caused the combo explosion
347 this.realowner = inflictor.realowner;
348 this.classname = "electro_orb_chain";
349 setthink(this, W_Electro_ExplodeCombo);
350 this.nextthink = time +
352 // bound the length, inflictor may be in a galaxy far far away (warpzones)
354 WEP_CVAR(electro, combo_radius),
355 vlen(this.origin - inflictor.origin)
358 // delay combo chains, looks cooler
359 WEP_CVAR(electro, combo_speed)
364 this.use = W_Electro_Explode_use;
365 setthink(this, adaptor_think2use); // not _hittype_splash, as this runs "immediately"
370 void W_Electro_Attack_Orb(Weapon thiswep, entity actor, .entity weaponentity)
372 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(electro, ammo), weaponentity);
374 W_SetupShot_ProjectileSize(
383 WEP_CVAR_SEC(electro, damage),
384 thiswep.m_id | HITTYPE_SECONDARY
387 w_shotdir = v_forward; // no TrueAim for grenades please
389 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
391 entity proj = new(electro_orb);
392 proj.owner = proj.realowner = actor;
393 proj.use = W_Electro_Explode_use;
394 setthink(proj, adaptor_think2use_hittype_splash);
395 proj.bot_dodge = true;
396 proj.bot_dodgerating = WEP_CVAR_SEC(electro, damage);
397 proj.nextthink = time + WEP_CVAR_SEC(electro, lifetime);
398 PROJECTILE_MAKETRIGGER(proj);
399 proj.projectiledeathtype = thiswep.m_id | HITTYPE_SECONDARY;
400 proj.weaponentity_fld = weaponentity;
401 setorigin(proj, w_shotorg);
403 //proj.glow_size = 50;
404 //proj.glow_color = 45;
405 set_movetype(proj, MOVETYPE_BOUNCE);
406 W_SetupProjVelocity_UP_SEC(proj, electro);
407 settouch(proj, W_Electro_Orb_Touch);
408 setsize(proj, '-4 -4 -4', '4 4 4');
409 proj.takedamage = DAMAGE_YES;
410 proj.damageforcescale = WEP_CVAR_SEC(electro, damageforcescale);
411 SetResourceExplicit(proj, RES_HEALTH, WEP_CVAR_SEC(electro, health));
412 proj.event_damage = W_Electro_Orb_Damage;
413 proj.flags = FL_PROJECTILE;
414 IL_PUSH(g_projectiles, proj);
415 IL_PUSH(g_bot_dodge, proj);
416 proj.damagedbycontents = (WEP_CVAR_SEC(electro, damagedbycontents));
417 if(proj.damagedbycontents)
418 IL_PUSH(g_damagedbycontents, proj);
420 proj.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
421 proj.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
422 proj.missile_flags = MIF_SPLASH | MIF_ARC;
424 if(WEP_CVAR_SEC(electro, limit) > 0)
427 RubbleLimit("electro_orb", WEP_CVAR_SEC(electro, limit), adaptor_think2use_hittype_splash);
430 CSQCProjectile(proj, true, PROJECTILE_ELECTRO, false); // no culling, it has sound
432 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
435 void W_Electro_CheckAttack(Weapon thiswep, entity actor, .entity weaponentity, int fire)
437 if(actor.(weaponentity).electro_count > 1)
438 if(PHYS_INPUT_BUTTON_ATCK2(actor))
439 if(weapon_prepareattack(thiswep, actor, weaponentity, true, -1))
441 W_Electro_Attack_Orb(thiswep, actor, weaponentity);
442 actor.(weaponentity).electro_count -= 1;
443 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
446 // WEAPONTODO: when the player releases the button, cut down the length of refire2?
447 w_ready(thiswep, actor, weaponentity, fire);
450 .float bot_secondary_electromooth;
452 METHOD(Electro, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
454 PHYS_INPUT_BUTTON_ATCK(actor) = PHYS_INPUT_BUTTON_ATCK2(actor) = false;
455 if(vdist(actor.origin - actor.enemy.origin, >, 1000)) { actor.bot_secondary_electromooth = 0; }
456 if(actor.bot_secondary_electromooth == 0)
460 if(WEP_CVAR_PRI(electro, speed))
461 shoot = bot_aim(actor, weaponentity, WEP_CVAR_PRI(electro, speed), 0, WEP_CVAR_PRI(electro, lifetime), false);
463 shoot = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
467 PHYS_INPUT_BUTTON_ATCK(actor) = true;
468 if(random() < 0.01) actor.bot_secondary_electromooth = 1;
473 if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(electro, speed), WEP_CVAR_SEC(electro, speed_up), WEP_CVAR_SEC(electro, lifetime), true))
475 PHYS_INPUT_BUTTON_ATCK2(actor) = true;
476 if(random() < 0.03) actor.bot_secondary_electromooth = 0;
480 METHOD(Electro, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
482 if(autocvar_g_balance_electro_reload_ammo) // forced reload // WEAPONTODO
484 float ammo_amount = 0;
485 if(actor.(weaponentity).clip_load >= WEP_CVAR_PRI(electro, ammo))
487 if(actor.(weaponentity).clip_load >= WEP_CVAR_SEC(electro, ammo))
492 thiswep.wr_reload(thiswep, actor, weaponentity);
499 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire)))
501 W_Electro_Attack_Bolt(thiswep, actor, weaponentity);
502 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
507 if(time >= actor.(weaponentity).electro_secondarytime)
508 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(electro, refire)))
510 W_Electro_Attack_Orb(thiswep, actor, weaponentity);
511 actor.(weaponentity).electro_count = WEP_CVAR_SEC(electro, count);
512 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
513 actor.(weaponentity).electro_secondarytime = time + WEP_CVAR_SEC(electro, refire2) * W_WeaponRateFactor(actor);
517 METHOD(Electro, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
519 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(electro, ammo);
520 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_PRI(electro, ammo);
523 METHOD(Electro, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
526 if(WEP_CVAR(electro, combo_safeammocheck)) // true if you can fire at least one secondary blob AND one primary shot after it, otherwise false.
528 ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
529 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
533 ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(electro, ammo);
534 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(electro, ammo);
538 METHOD(Electro, wr_resetplayer, void(entity thiswep, entity actor))
540 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
542 .entity weaponentity = weaponentities[slot];
543 actor.(weaponentity).electro_secondarytime = time;
546 METHOD(Electro, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
548 W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(electro, ammo), WEP_CVAR_SEC(electro, ammo)), SND_RELOAD);
550 METHOD(Electro, wr_suicidemessage, Notification(entity thiswep))
552 if(w_deathtype & HITTYPE_SECONDARY)
553 return WEAPON_ELECTRO_SUICIDE_ORBS;
555 return WEAPON_ELECTRO_SUICIDE_BOLT;
557 METHOD(Electro, wr_killmessage, Notification(entity thiswep))
559 if(w_deathtype & HITTYPE_SECONDARY)
561 return WEAPON_ELECTRO_MURDER_ORBS;
565 if(w_deathtype & HITTYPE_BOUNCE)
566 return WEAPON_ELECTRO_MURDER_COMBO;
568 return WEAPON_ELECTRO_MURDER_BOLT;
575 METHOD(Electro, wr_impacteffect, void(entity thiswep, entity actor))
578 org2 = w_org + w_backoff * 6;
579 if(w_deathtype & HITTYPE_SECONDARY)
581 pointparticles(EFFECT_ELECTRO_BALLEXPLODE, org2, '0 0 0', 1);
583 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);
587 if(w_deathtype & HITTYPE_BOUNCE)
589 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
590 pointparticles(EFFECT_ELECTRO_COMBO, org2, '0 0 0', 1);
592 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT_COMBO, VOL_BASE, ATTEN_NORM);
596 pointparticles(EFFECT_ELECTRO_IMPACT, org2, '0 0 0', 1);
598 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);