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(LimitedElectroBallRubbleList && IL_CONTAINS(LimitedElectroBallRubbleList, this))
302 ReplaceOldListedChildRubble(LimitedElectroBallRubbleList, newproj, this);
308 SetMovetypeFollow(newproj, to);
311 void W_Electro_Orb_Touch(entity this, entity toucher)
313 PROJECTILE_TOUCH(this, toucher);
314 if(toucher.takedamage == DAMAGE_AIM && WEP_CVAR_SEC(electro, touchexplode))
315 { W_Electro_Explode(this, toucher); }
316 else if(toucher.owner != this.owner && toucher.classname != this.classname) // don't stick to player's other projectiles!
318 //UpdateCSQCProjectile(this);
319 spamsound(this, CH_SHOTS, SND_ELECTRO_BOUNCE, VOL_BASE, ATTEN_NORM);
320 this.projectiledeathtype |= HITTYPE_BOUNCE;
322 if(WEP_CVAR_SEC(electro, stick))
323 W_Electro_Orb_Stick(this, toucher);
327 void W_Electro_Orb_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
329 if(GetResource(this, RES_HEALTH) <= 0)
332 // note: combos are usually triggered by W_Electro_TriggerCombo, not damage
333 float is_combo = (inflictor.classname == "electro_orb_chain" || inflictor.classname == "electro_bolt");
335 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, (is_combo ? 1 : -1)))
336 return; // g_projectiles_damage says to halt
338 TakeResource(this, RES_HEALTH, damage);
339 if(GetResource(this, RES_HEALTH) <= 0)
341 this.takedamage = DAMAGE_NO;
342 this.nextthink = time;
345 // change owner to whoever caused the combo explosion
346 this.realowner = inflictor.realowner;
347 this.classname = "electro_orb_chain";
348 setthink(this, W_Electro_ExplodeCombo);
349 this.nextthink = time +
351 // bound the length, inflictor may be in a galaxy far far away (warpzones)
353 WEP_CVAR(electro, combo_radius),
354 vlen(this.origin - inflictor.origin)
357 // delay combo chains, looks cooler
358 WEP_CVAR(electro, combo_speed)
363 this.use = W_Electro_Explode_use;
364 setthink(this, adaptor_think2use); // not _hittype_splash, as this runs "immediately"
369 void W_Electro_Attack_Orb(Weapon thiswep, entity actor, .entity weaponentity)
371 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(electro, ammo), weaponentity);
373 W_SetupShot_ProjectileSize(
382 WEP_CVAR_SEC(electro, damage),
383 thiswep.m_id | HITTYPE_SECONDARY
386 w_shotdir = v_forward; // no TrueAim for grenades please
388 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
390 entity proj = new(electro_orb);
391 proj.owner = proj.realowner = actor;
392 proj.use = W_Electro_Explode_use;
393 setthink(proj, adaptor_think2use_hittype_splash);
394 proj.bot_dodge = true;
395 proj.bot_dodgerating = WEP_CVAR_SEC(electro, damage);
396 proj.nextthink = time + WEP_CVAR_SEC(electro, lifetime);
397 PROJECTILE_MAKETRIGGER(proj);
398 proj.projectiledeathtype = thiswep.m_id | HITTYPE_SECONDARY;
399 proj.weaponentity_fld = weaponentity;
400 setorigin(proj, w_shotorg);
402 //proj.glow_size = 50;
403 //proj.glow_color = 45;
404 set_movetype(proj, MOVETYPE_BOUNCE);
405 W_SetupProjVelocity_UP_SEC(proj, electro);
406 settouch(proj, W_Electro_Orb_Touch);
407 setsize(proj, '-4 -4 -4', '4 4 4');
408 proj.takedamage = DAMAGE_YES;
409 proj.damageforcescale = WEP_CVAR_SEC(electro, damageforcescale);
410 SetResourceExplicit(proj, RES_HEALTH, WEP_CVAR_SEC(electro, health));
411 proj.event_damage = W_Electro_Orb_Damage;
412 proj.flags = FL_PROJECTILE;
413 IL_PUSH(g_projectiles, proj);
414 IL_PUSH(g_bot_dodge, proj);
415 proj.damagedbycontents = (WEP_CVAR_SEC(electro, damagedbycontents));
416 if(proj.damagedbycontents)
417 IL_PUSH(g_damagedbycontents, proj);
419 proj.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
420 proj.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
421 proj.missile_flags = MIF_SPLASH | MIF_ARC;
423 if(WEP_CVAR_SEC(electro, limit) > 0)
425 if (!LimitedElectroBallRubbleList)
426 LimitedElectroBallRubbleList = IL_NEW();
427 ListNewChildRubble(LimitedElectroBallRubbleList, proj);
428 LimitedChildrenRubble(LimitedElectroBallRubbleList, "electro_orb", WEP_CVAR_SEC(electro, limit), adaptor_think2use_hittype_splash, actor);
431 CSQCProjectile(proj, true, PROJECTILE_ELECTRO, false); // no culling, it has sound
433 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
436 void W_Electro_CheckAttack(Weapon thiswep, entity actor, .entity weaponentity, int fire)
438 if(actor.(weaponentity).electro_count > 1)
439 if(PHYS_INPUT_BUTTON_ATCK2(actor))
440 if(weapon_prepareattack(thiswep, actor, weaponentity, true, -1))
442 W_Electro_Attack_Orb(thiswep, actor, weaponentity);
443 actor.(weaponentity).electro_count -= 1;
444 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
447 // WEAPONTODO: when the player releases the button, cut down the length of refire2?
448 w_ready(thiswep, actor, weaponentity, fire);
451 .float bot_secondary_electromooth;
453 METHOD(Electro, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
455 PHYS_INPUT_BUTTON_ATCK(actor) = PHYS_INPUT_BUTTON_ATCK2(actor) = false;
456 if(vdist(actor.origin - actor.enemy.origin, >, 1000)) { actor.bot_secondary_electromooth = 0; }
457 if(actor.bot_secondary_electromooth == 0)
461 if(WEP_CVAR_PRI(electro, speed))
462 shoot = bot_aim(actor, weaponentity, WEP_CVAR_PRI(electro, speed), 0, WEP_CVAR_PRI(electro, lifetime), false);
464 shoot = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
468 PHYS_INPUT_BUTTON_ATCK(actor) = true;
469 if(random() < 0.01) actor.bot_secondary_electromooth = 1;
474 if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(electro, speed), WEP_CVAR_SEC(electro, speed_up), WEP_CVAR_SEC(electro, lifetime), true))
476 PHYS_INPUT_BUTTON_ATCK2(actor) = true;
477 if(random() < 0.03) actor.bot_secondary_electromooth = 0;
481 METHOD(Electro, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
483 if(autocvar_g_balance_electro_reload_ammo) // forced reload // WEAPONTODO
485 float ammo_amount = 0;
486 if(actor.(weaponentity).clip_load >= WEP_CVAR_PRI(electro, ammo))
488 if(actor.(weaponentity).clip_load >= WEP_CVAR_SEC(electro, ammo))
493 thiswep.wr_reload(thiswep, actor, weaponentity);
500 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire)))
502 W_Electro_Attack_Bolt(thiswep, actor, weaponentity);
503 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
508 if(time >= actor.(weaponentity).electro_secondarytime)
509 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(electro, refire)))
511 W_Electro_Attack_Orb(thiswep, actor, weaponentity);
512 actor.(weaponentity).electro_count = WEP_CVAR_SEC(electro, count);
513 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
514 actor.(weaponentity).electro_secondarytime = time + WEP_CVAR_SEC(electro, refire2) * W_WeaponRateFactor(actor);
518 METHOD(Electro, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
520 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(electro, ammo);
521 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_PRI(electro, ammo);
524 METHOD(Electro, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
527 if(WEP_CVAR(electro, combo_safeammocheck)) // true if you can fire at least one secondary blob AND one primary shot after it, otherwise false.
529 ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
530 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
534 ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(electro, ammo);
535 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(electro, ammo);
539 METHOD(Electro, wr_resetplayer, void(entity thiswep, entity actor))
541 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
543 .entity weaponentity = weaponentities[slot];
544 actor.(weaponentity).electro_secondarytime = time;
547 METHOD(Electro, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
549 W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(electro, ammo), WEP_CVAR_SEC(electro, ammo)), SND_RELOAD);
551 METHOD(Electro, wr_suicidemessage, Notification(entity thiswep))
553 if(w_deathtype & HITTYPE_SECONDARY)
554 return WEAPON_ELECTRO_SUICIDE_ORBS;
556 return WEAPON_ELECTRO_SUICIDE_BOLT;
558 METHOD(Electro, wr_killmessage, Notification(entity thiswep))
560 if(w_deathtype & HITTYPE_SECONDARY)
562 return WEAPON_ELECTRO_MURDER_ORBS;
566 if(w_deathtype & HITTYPE_BOUNCE)
567 return WEAPON_ELECTRO_MURDER_COMBO;
569 return WEAPON_ELECTRO_MURDER_BOLT;
576 METHOD(Electro, wr_impacteffect, void(entity thiswep, entity actor))
579 org2 = w_org + w_backoff * 6;
580 if(w_deathtype & HITTYPE_SECONDARY)
582 pointparticles(EFFECT_ELECTRO_BALLEXPLODE, org2, '0 0 0', 1);
584 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);
588 if(w_deathtype & HITTYPE_BOUNCE)
590 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
591 pointparticles(EFFECT_ELECTRO_COMBO, org2, '0 0 0', 1);
593 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT_COMBO, VOL_BASE, ATTEN_NORM);
597 pointparticles(EFFECT_ELECTRO_IMPACT, org2, '0 0 0', 1);
599 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);