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;
56 WEP_CVAR(electro, combo_damage),
57 WEP_CVAR(electro, combo_edgedamage),
58 WEP_CVAR(electro, combo_radius),
61 WEP_CVAR(electro, combo_force),
62 WEP_ELECTRO.m_id | HITTYPE_BOUNCE, // use THIS type for a combo because primary can't bounce
63 this.weaponentity_fld,
70 void W_Electro_Explode(entity this, entity directhitentity)
72 if(directhitentity.takedamage == DAMAGE_AIM)
73 if(IS_PLAYER(directhitentity))
74 if(DIFF_TEAM(this.realowner, directhitentity))
75 if(!IS_DEAD(directhitentity))
76 if(IsFlying(directhitentity))
77 Send_Notification(NOTIF_ONE, this.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_ELECTROBITCH);
79 this.event_damage = func_null;
80 this.takedamage = DAMAGE_NO;
82 if(this.move_movetype == MOVETYPE_BOUNCE || this.classname == "electro_orb") // TODO: classname is more reliable anyway?
87 WEP_CVAR_SEC(electro, damage),
88 WEP_CVAR_SEC(electro, edgedamage),
89 WEP_CVAR_SEC(electro, radius),
92 WEP_CVAR_SEC(electro, force),
93 this.projectiledeathtype,
94 this.weaponentity_fld,
100 W_Electro_TriggerCombo(this.origin, WEP_CVAR_PRI(electro, comboradius), this.realowner);
104 WEP_CVAR_PRI(electro, damage),
105 WEP_CVAR_PRI(electro, edgedamage),
106 WEP_CVAR_PRI(electro, radius),
109 WEP_CVAR_PRI(electro, force),
110 this.projectiledeathtype,
111 this.weaponentity_fld,
119 void W_Electro_Explode_use(entity this, entity actor, entity trigger)
121 W_Electro_Explode(this, trigger);
124 void W_Electro_TouchExplode(entity this, entity toucher)
126 PROJECTILE_TOUCH(this, toucher);
127 W_Electro_Explode(this, toucher);
131 void sys_phys_update_single(entity this);
133 void W_Electro_Bolt_Think(entity this)
135 // sys_phys_update_single(this);
136 if(time >= this.ltime)
138 this.use(this, NULL, NULL);
142 if(WEP_CVAR_PRI(electro, midaircombo_radius))
145 entity e = WarpZone_FindRadius(this.origin, WEP_CVAR_PRI(electro, midaircombo_radius), true);
147 // loop through nearby orbs and trigger them
150 if(e.classname == "electro_orb")
153 if (this.owner == e.owner)
155 explode = WEP_CVAR_PRI(electro, midaircombo_own);
157 else if (SAME_TEAM(this.owner, e.owner))
159 explode = WEP_CVAR_PRI(electro, midaircombo_teammate);
163 explode = WEP_CVAR_PRI(electro, midaircombo_enemy);
168 // change owner to whoever caused the combo explosion
169 e.realowner = this.realowner;
170 e.takedamage = DAMAGE_NO;
171 e.classname = "electro_orb_chain";
173 // Only first orb explosion uses midaircombo_speed, others use the normal combo_speed.
174 // This allows to avoid the delay on the first explosion which looks better
175 // (the bolt and orb should explode together because they interacted together)
176 // while keeping the chaining delay.
177 setthink(e, W_Electro_ExplodeCombo);
179 if (WEP_CVAR_PRI(electro, midaircombo_speed))
180 delay = vlen(e.WarpZone_findradius_dist) / WEP_CVAR_PRI(electro, midaircombo_speed);
181 e.nextthink = time + delay;
189 // if we triggered an orb, should we explode? if not, lets try again next time
190 if(found && WEP_CVAR_PRI(electro, midaircombo_explode))
191 { this.use(this, NULL, NULL); }
193 { this.nextthink = min(time + WEP_CVAR_PRI(electro, midaircombo_interval), this.ltime); }
195 else { this.nextthink = this.ltime; }
196 // this.nextthink = time;
199 void W_Electro_Attack_Bolt(Weapon thiswep, entity actor, .entity weaponentity)
203 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(electro, ammo), weaponentity);
205 W_SetupShot_ProjectileSize(
214 WEP_CVAR_PRI(electro, damage),
218 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
220 proj = new(electro_bolt);
221 proj.owner = proj.realowner = actor;
222 proj.bot_dodge = true;
223 proj.bot_dodgerating = WEP_CVAR_PRI(electro, damage);
224 proj.use = W_Electro_Explode_use;
225 setthink(proj, W_Electro_Bolt_Think);
226 proj.nextthink = time;
227 proj.ltime = time + WEP_CVAR_PRI(electro, lifetime);
228 PROJECTILE_MAKETRIGGER(proj);
229 proj.projectiledeathtype = thiswep.m_id;
230 proj.weaponentity_fld = weaponentity;
231 setorigin(proj, w_shotorg);
234 set_movetype(proj, MOVETYPE_FLY);
235 W_SetupProjVelocity_PRI(proj, electro);
236 proj.angles = vectoangles(proj.velocity);
237 settouch(proj, W_Electro_TouchExplode);
238 setsize(proj, '0 0 -3', '0 0 -3');
239 proj.flags = FL_PROJECTILE;
240 IL_PUSH(g_projectiles, proj);
241 IL_PUSH(g_bot_dodge, proj);
242 proj.missile_flags = MIF_SPLASH;
244 CSQCProjectile(proj, true, PROJECTILE_ELECTRO_BEAM, true);
246 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
247 // proj.com_phys_pos = proj.origin;
248 // proj.com_phys_vel = proj.velocity;
251 void W_Electro_Orb_Stick(entity this, entity to)
253 entity newproj = spawn();
254 newproj.classname = this.classname;
256 newproj.bot_dodge = this.bot_dodge;
257 newproj.bot_dodgerating = this.bot_dodgerating;
259 newproj.owner = this.owner;
260 newproj.realowner = this.realowner;
261 setorigin(newproj, this.origin);
262 setmodel(newproj, MDL_PROJECTILE_ELECTRO);
263 setsize(newproj, this.mins, this.maxs);
264 newproj.angles = vectoangles(-trace_plane_normal); // face against the surface
266 newproj.takedamage = this.takedamage;
267 newproj.damageforcescale = this.damageforcescale;
268 SetResourceExplicit(newproj, RES_HEALTH, GetResource(this, RES_HEALTH));
269 newproj.event_damage = this.event_damage;
270 newproj.spawnshieldtime = this.spawnshieldtime;
271 newproj.damagedbycontents = true;
272 IL_PUSH(g_damagedbycontents, newproj);
274 set_movetype(newproj, MOVETYPE_NONE); // lock the orb in place
275 newproj.projectiledeathtype = this.projectiledeathtype;
276 newproj.weaponentity_fld = this.weaponentity_fld;
278 settouch(newproj, func_null);
279 setthink(newproj, getthink(this));
280 newproj.nextthink = this.nextthink;
281 newproj.use = this.use;
282 newproj.flags = this.flags;
283 IL_PUSH(g_projectiles, newproj);
284 IL_PUSH(g_bot_dodge, newproj);
286 // check if limits are enabled (we can tell by checking if the original orb is listed) and push it to the list if so
287 if(LimitedElectroBallRubbleList && IL_CONTAINS(LimitedElectroBallRubbleList, this))
289 ReplaceOldListedChildRubble(LimitedElectroBallRubbleList, newproj, this);
295 SetMovetypeFollow(newproj, to);
298 void W_Electro_Orb_Touch(entity this, entity toucher)
300 PROJECTILE_TOUCH(this, toucher);
301 if(toucher.takedamage == DAMAGE_AIM && WEP_CVAR_SEC(electro, touchexplode))
302 { W_Electro_Explode(this, toucher); }
303 else if(toucher.owner != this.owner && toucher.classname != this.classname) // don't stick to player's other projectiles!
305 //UpdateCSQCProjectile(this);
306 spamsound(this, CH_SHOTS, SND_ELECTRO_BOUNCE, VOL_BASE, ATTEN_NORM);
307 this.projectiledeathtype |= HITTYPE_BOUNCE;
309 if(WEP_CVAR_SEC(electro, stick))
310 W_Electro_Orb_Stick(this, toucher);
314 void W_Electro_Orb_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
316 if(GetResource(this, RES_HEALTH) <= 0)
319 // note: combos are usually triggered by W_Electro_TriggerCombo, not damage
320 float is_combo = (inflictor.classname == "electro_orb_chain" || inflictor.classname == "electro_bolt");
322 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, (is_combo ? 1 : -1)))
323 return; // g_projectiles_damage says to halt
325 TakeResource(this, RES_HEALTH, damage);
326 if(GetResource(this, RES_HEALTH) <= 0)
328 this.takedamage = DAMAGE_NO;
329 this.nextthink = time;
332 // change owner to whoever caused the combo explosion
333 this.realowner = inflictor.realowner;
334 this.classname = "electro_orb_chain";
335 setthink(this, W_Electro_ExplodeCombo);
336 // delay combo chains, looks cooler
337 // bound the length, inflictor may be in a galaxy far far away (warpzones)
338 float len = min(WEP_CVAR(electro, combo_radius), vlen(this.origin - inflictor.origin));
339 float delay = len / WEP_CVAR(electro, combo_speed);
340 this.nextthink = time + delay;
344 this.use = W_Electro_Explode_use;
345 setthink(this, adaptor_think2use); // not _hittype_splash, as this runs "immediately"
350 void W_Electro_Attack_Orb(Weapon thiswep, entity actor, .entity weaponentity)
352 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(electro, ammo), weaponentity);
354 W_SetupShot_ProjectileSize(
363 WEP_CVAR_SEC(electro, damage),
364 thiswep.m_id | HITTYPE_SECONDARY
367 w_shotdir = v_forward; // no TrueAim for grenades please
369 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
371 entity proj = new(electro_orb);
372 proj.owner = proj.realowner = actor;
373 proj.use = W_Electro_Explode_use;
374 setthink(proj, adaptor_think2use_hittype_splash);
375 proj.bot_dodge = true;
376 proj.bot_dodgerating = WEP_CVAR_SEC(electro, damage);
377 proj.nextthink = time + WEP_CVAR_SEC(electro, lifetime);
378 PROJECTILE_MAKETRIGGER(proj);
379 proj.projectiledeathtype = thiswep.m_id | HITTYPE_SECONDARY;
380 proj.weaponentity_fld = weaponentity;
381 setorigin(proj, w_shotorg);
383 //proj.glow_size = 50;
384 //proj.glow_color = 45;
385 set_movetype(proj, MOVETYPE_BOUNCE);
386 W_SetupProjVelocity_UP_SEC(proj, electro);
387 settouch(proj, W_Electro_Orb_Touch);
388 setsize(proj, '-4 -4 -4', '4 4 4');
389 proj.takedamage = DAMAGE_YES;
390 proj.damageforcescale = WEP_CVAR_SEC(electro, damageforcescale);
391 SetResourceExplicit(proj, RES_HEALTH, WEP_CVAR_SEC(electro, health));
392 proj.event_damage = W_Electro_Orb_Damage;
393 proj.flags = FL_PROJECTILE;
394 IL_PUSH(g_projectiles, proj);
395 IL_PUSH(g_bot_dodge, proj);
396 proj.damagedbycontents = (WEP_CVAR_SEC(electro, damagedbycontents));
397 if(proj.damagedbycontents)
398 IL_PUSH(g_damagedbycontents, proj);
400 proj.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
401 proj.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
402 proj.missile_flags = MIF_SPLASH | MIF_ARC;
404 if(WEP_CVAR_SEC(electro, limit) > 0)
406 if (!LimitedElectroBallRubbleList)
407 LimitedElectroBallRubbleList = IL_NEW();
408 ListNewChildRubble(LimitedElectroBallRubbleList, proj);
409 LimitedChildrenRubble(LimitedElectroBallRubbleList, "electro_orb", WEP_CVAR_SEC(electro, limit), adaptor_think2use_hittype_splash, actor);
412 CSQCProjectile(proj, true, PROJECTILE_ELECTRO, false); // no culling, it has sound
414 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
417 void W_Electro_CheckAttack(Weapon thiswep, entity actor, .entity weaponentity, int fire)
419 if(actor.(weaponentity).electro_count > 1)
420 if(PHYS_INPUT_BUTTON_ATCK2(actor))
421 if(weapon_prepareattack(thiswep, actor, weaponentity, true, -1))
423 W_Electro_Attack_Orb(thiswep, actor, weaponentity);
424 actor.(weaponentity).electro_count -= 1;
425 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
428 // WEAPONTODO: when the player releases the button, cut down the length of refire2?
429 w_ready(thiswep, actor, weaponentity, fire);
432 .float bot_secondary_electromooth;
434 METHOD(Electro, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
436 PHYS_INPUT_BUTTON_ATCK(actor) = PHYS_INPUT_BUTTON_ATCK2(actor) = false;
437 if(vdist(actor.origin - actor.enemy.origin, >, 1000)) { actor.bot_secondary_electromooth = 0; }
438 if(actor.bot_secondary_electromooth == 0)
442 if(WEP_CVAR_PRI(electro, speed))
443 shoot = bot_aim(actor, weaponentity, WEP_CVAR_PRI(electro, speed), 0, WEP_CVAR_PRI(electro, lifetime), false);
445 shoot = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
449 PHYS_INPUT_BUTTON_ATCK(actor) = true;
450 if(random() < 0.01) actor.bot_secondary_electromooth = 1;
455 if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(electro, speed), WEP_CVAR_SEC(electro, speed_up), WEP_CVAR_SEC(electro, lifetime), true))
457 PHYS_INPUT_BUTTON_ATCK2(actor) = true;
458 if(random() < 0.03) actor.bot_secondary_electromooth = 0;
462 METHOD(Electro, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
464 if(autocvar_g_balance_electro_reload_ammo) // forced reload // WEAPONTODO
466 float ammo_amount = 0;
467 if(actor.(weaponentity).clip_load >= WEP_CVAR_PRI(electro, ammo))
469 if(actor.(weaponentity).clip_load >= WEP_CVAR_SEC(electro, ammo))
474 thiswep.wr_reload(thiswep, actor, weaponentity);
481 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire)))
483 W_Electro_Attack_Bolt(thiswep, actor, weaponentity);
484 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
489 if(time >= actor.(weaponentity).electro_secondarytime)
490 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(electro, refire)))
492 W_Electro_Attack_Orb(thiswep, actor, weaponentity);
493 actor.(weaponentity).electro_count = WEP_CVAR_SEC(electro, count);
494 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
495 actor.(weaponentity).electro_secondarytime = time + WEP_CVAR_SEC(electro, refire2) * W_WeaponRateFactor(actor);
499 METHOD(Electro, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
501 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(electro, ammo);
502 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_PRI(electro, ammo);
505 METHOD(Electro, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
508 if(WEP_CVAR(electro, combo_safeammocheck)) // true if you can fire at least one secondary blob AND one primary shot after it, otherwise false.
510 ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
511 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
515 ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(electro, ammo);
516 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(electro, ammo);
520 METHOD(Electro, wr_resetplayer, void(entity thiswep, entity actor))
522 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
524 .entity weaponentity = weaponentities[slot];
525 actor.(weaponentity).electro_secondarytime = time;
528 METHOD(Electro, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
530 W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(electro, ammo), WEP_CVAR_SEC(electro, ammo)), SND_RELOAD);
532 METHOD(Electro, wr_suicidemessage, Notification(entity thiswep))
534 if(w_deathtype & HITTYPE_SECONDARY)
535 return WEAPON_ELECTRO_SUICIDE_ORBS;
537 return WEAPON_ELECTRO_SUICIDE_BOLT;
539 METHOD(Electro, wr_killmessage, Notification(entity thiswep))
541 if(w_deathtype & HITTYPE_SECONDARY)
543 return WEAPON_ELECTRO_MURDER_ORBS;
547 if(w_deathtype & HITTYPE_BOUNCE)
548 return WEAPON_ELECTRO_MURDER_COMBO;
550 return WEAPON_ELECTRO_MURDER_BOLT;
557 METHOD(Electro, wr_impacteffect, void(entity thiswep, entity actor))
560 org2 = w_org + w_backoff * 6;
561 if(w_deathtype & HITTYPE_SECONDARY)
563 pointparticles(EFFECT_ELECTRO_BALLEXPLODE, org2, '0 0 0', 1);
565 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);
569 if(w_deathtype & HITTYPE_BOUNCE)
571 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
572 pointparticles(EFFECT_ELECTRO_COMBO, org2, '0 0 0', 1);
574 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT_COMBO, VOL_BASE, ATTEN_NORM);
578 pointparticles(EFFECT_ELECTRO_IMPACT, org2, '0 0 0', 1);
580 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);