4 spawnfunc(weapon_electro) { weapon_defaultspawnfunc(this, WEP_ELECTRO); }
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
75 void W_Electro_Explode(entity this, entity directhitentity)
77 if(directhitentity.takedamage == DAMAGE_AIM)
78 if(IS_PLAYER(directhitentity))
79 if(DIFF_TEAM(this.realowner, directhitentity))
80 if(!IS_DEAD(directhitentity))
81 if(IsFlying(directhitentity))
82 Send_Notification(NOTIF_ONE, this.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_ELECTROBITCH);
84 this.event_damage = func_null;
85 this.takedamage = DAMAGE_NO;
87 if(this.move_movetype == MOVETYPE_BOUNCE || this.classname == "electro_orb") // TODO: classname is more reliable anyway?
92 WEP_CVAR_SEC(electro, damage),
93 WEP_CVAR_SEC(electro, edgedamage),
94 WEP_CVAR_SEC(electro, radius),
97 WEP_CVAR_SEC(electro, force),
98 this.projectiledeathtype,
104 W_Electro_TriggerCombo(this.origin, WEP_CVAR_PRI(electro, comboradius), this.realowner);
108 WEP_CVAR_PRI(electro, damage),
109 WEP_CVAR_PRI(electro, edgedamage),
110 WEP_CVAR_PRI(electro, radius),
113 WEP_CVAR_PRI(electro, force),
114 this.projectiledeathtype,
122 void W_Electro_Explode_use(entity this, entity actor, entity trigger)
124 W_Electro_Explode(this, trigger);
127 void W_Electro_TouchExplode(entity this, entity toucher)
129 PROJECTILE_TOUCH(this, toucher);
130 W_Electro_Explode(this, toucher);
134 void sys_phys_update_single(entity this);
136 void W_Electro_Bolt_Think(entity this)
138 // sys_phys_update_single(this);
139 if(time >= this.ltime)
141 this.use(this, NULL, NULL);
145 if(WEP_CVAR_PRI(electro, midaircombo_radius))
148 entity e = WarpZone_FindRadius(this.origin, WEP_CVAR_PRI(electro, midaircombo_radius), true);
150 // loop through nearby orbs and trigger them
153 if(e.classname == "electro_orb")
155 // change owner to whoever caused the combo explosion
156 e.realowner = this.realowner;
157 e.takedamage = DAMAGE_NO;
158 e.classname = "electro_orb_chain";
160 // now set the next one to trigger as well
161 setthink(e, W_Electro_ExplodeCombo);
163 // delay combo chains, looks cooler
168 (WEP_CVAR(electro, combo_speed) ?
169 (vlen(e.WarpZone_findradius_dist) / WEP_CVAR(electro, combo_speed))
180 // if we triggered an orb, should we explode? if not, lets try again next time
181 if(found && WEP_CVAR_PRI(electro, midaircombo_explode))
182 { this.use(this, NULL, NULL); }
184 { this.nextthink = min(time + WEP_CVAR_PRI(electro, midaircombo_interval), this.ltime); }
186 else { this.nextthink = this.ltime; }
187 // this.nextthink = time;
190 void W_Electro_Attack_Bolt(Weapon thiswep, entity actor, .entity weaponentity)
194 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(electro, ammo), weaponentity);
196 W_SetupShot_ProjectileSize(
205 WEP_CVAR_PRI(electro, damage)
208 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
210 proj = new(electro_bolt);
211 proj.owner = proj.realowner = actor;
212 proj.bot_dodge = true;
213 proj.bot_dodgerating = WEP_CVAR_PRI(electro, damage);
214 proj.use = W_Electro_Explode_use;
215 setthink(proj, W_Electro_Bolt_Think);
216 proj.nextthink = time;
217 proj.ltime = time + WEP_CVAR_PRI(electro, lifetime);
218 PROJECTILE_MAKETRIGGER(proj);
219 proj.projectiledeathtype = WEP_ELECTRO.m_id;
220 setorigin(proj, w_shotorg);
223 set_movetype(proj, MOVETYPE_FLY);
224 W_SetupProjVelocity_PRI(proj, electro);
225 proj.angles = vectoangles(proj.velocity);
226 settouch(proj, W_Electro_TouchExplode);
227 setsize(proj, '0 0 -3', '0 0 -3');
228 proj.flags = FL_PROJECTILE;
229 IL_PUSH(g_projectiles, proj);
230 IL_PUSH(g_bot_dodge, proj);
231 proj.missile_flags = MIF_SPLASH;
233 CSQCProjectile(proj, true, PROJECTILE_ELECTRO_BEAM, true);
235 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
236 // proj.com_phys_pos = proj.origin;
237 // proj.com_phys_vel = proj.velocity;
240 void W_Electro_Orb_Stick(entity this, entity to)
242 entity newproj = spawn();
243 newproj.classname = this.classname;
245 newproj.bot_dodge = this.bot_dodge;
246 newproj.bot_dodgerating = this.bot_dodgerating;
248 newproj.owner = this.owner;
249 newproj.realowner = this.realowner;
250 setsize(newproj, this.mins, this.maxs);
251 setorigin(newproj, this.origin);
252 setmodel(newproj, MDL_PROJECTILE_ELECTRO);
253 newproj.angles = vectoangles(-trace_plane_normal); // face against the surface
255 newproj.takedamage = this.takedamage;
256 newproj.damageforcescale = this.damageforcescale;
257 newproj.health = this.health;
258 newproj.event_damage = this.event_damage;
259 newproj.spawnshieldtime = this.spawnshieldtime;
260 newproj.damagedbycontents = true;
261 IL_PUSH(g_damagedbycontents, newproj);
263 set_movetype(newproj, MOVETYPE_NONE); // lock the orb in place
264 newproj.projectiledeathtype = this.projectiledeathtype;
266 settouch(newproj, func_null);
267 setthink(newproj, getthink(this));
268 newproj.nextthink = this.nextthink;
269 newproj.use = this.use;
270 newproj.flags = this.flags;
271 IL_PUSH(g_projectiles, newproj);
272 IL_PUSH(g_bot_dodge, newproj);
277 SetMovetypeFollow(this, to);
280 void W_Electro_Orb_Touch(entity this, entity toucher)
282 PROJECTILE_TOUCH(this, toucher);
283 if(toucher.takedamage == DAMAGE_AIM)
284 { if(WEP_CVAR_SEC(electro, touchexplode)) { W_Electro_Explode(this, toucher); } }
287 //UpdateCSQCProjectile(this);
288 spamsound(this, CH_SHOTS, SND_ELECTRO_BOUNCE, VOL_BASE, ATTEN_NORM);
289 this.projectiledeathtype |= HITTYPE_BOUNCE;
291 if(WEP_CVAR_SEC(electro, stick))
292 W_Electro_Orb_Stick(this, toucher);
296 void W_Electro_Orb_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
301 // note: combos are usually triggered by W_Electro_TriggerCombo, not damage
302 float is_combo = (inflictor.classname == "electro_orb_chain" || inflictor.classname == "electro_bolt");
304 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, (is_combo ? 1 : -1)))
305 return; // g_projectiles_damage says to halt
307 this.health = this.health - damage;
310 this.takedamage = DAMAGE_NO;
311 this.nextthink = time;
314 // change owner to whoever caused the combo explosion
315 this.realowner = inflictor.realowner;
316 this.classname = "electro_orb_chain";
317 setthink(this, W_Electro_ExplodeCombo);
318 this.nextthink = time +
320 // bound the length, inflictor may be in a galaxy far far away (warpzones)
322 WEP_CVAR(electro, combo_radius),
323 vlen(this.origin - inflictor.origin)
326 // delay combo chains, looks cooler
327 WEP_CVAR(electro, combo_speed)
332 this.use = W_Electro_Explode_use;
333 setthink(this, adaptor_think2use); // not _hittype_splash, as this runs "immediately"
338 void W_Electro_Attack_Orb(Weapon thiswep, entity actor, .entity weaponentity)
340 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(electro, ammo), weaponentity);
342 W_SetupShot_ProjectileSize(
351 WEP_CVAR_SEC(electro, damage)
354 w_shotdir = v_forward; // no TrueAim for grenades please
356 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
358 entity proj = new(electro_orb);
359 proj.owner = proj.realowner = actor;
360 proj.use = W_Electro_Explode_use;
361 setthink(proj, adaptor_think2use_hittype_splash);
362 proj.bot_dodge = true;
363 proj.bot_dodgerating = WEP_CVAR_SEC(electro, damage);
364 proj.nextthink = time + WEP_CVAR_SEC(electro, lifetime);
365 PROJECTILE_MAKETRIGGER(proj);
366 proj.projectiledeathtype = WEP_ELECTRO.m_id | HITTYPE_SECONDARY;
367 setorigin(proj, w_shotorg);
369 //proj.glow_size = 50;
370 //proj.glow_color = 45;
371 set_movetype(proj, MOVETYPE_BOUNCE);
372 W_SetupProjVelocity_UP_SEC(proj, electro);
373 settouch(proj, W_Electro_Orb_Touch);
374 setsize(proj, '-4 -4 -4', '4 4 4');
375 proj.takedamage = DAMAGE_YES;
376 proj.damageforcescale = WEP_CVAR_SEC(electro, damageforcescale);
377 proj.health = WEP_CVAR_SEC(electro, health);
378 proj.event_damage = W_Electro_Orb_Damage;
379 proj.flags = FL_PROJECTILE;
380 IL_PUSH(g_projectiles, proj);
381 IL_PUSH(g_bot_dodge, proj);
382 proj.damagedbycontents = (WEP_CVAR_SEC(electro, damagedbycontents));
383 if(proj.damagedbycontents)
384 IL_PUSH(g_damagedbycontents, proj);
386 proj.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
387 proj.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
388 proj.missile_flags = MIF_SPLASH | MIF_ARC;
393 copyentity(proj, p2);
394 setmodel(p2, MDL_PROJECTILE_ELECTRO);
395 setsize(p2, proj.mins, proj.maxs);
398 CSQCProjectile(proj, true, PROJECTILE_ELECTRO, false); // no culling, it has sound
400 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
403 void W_Electro_CheckAttack(Weapon thiswep, entity actor, .entity weaponentity, int fire)
405 if(actor.(weaponentity).electro_count > 1)
406 if(PHYS_INPUT_BUTTON_ATCK2(actor))
407 if(weapon_prepareattack(thiswep, actor, weaponentity, true, -1))
409 W_Electro_Attack_Orb(WEP_ELECTRO, actor, weaponentity);
410 actor.(weaponentity).electro_count -= 1;
411 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
414 // WEAPONTODO: when the player releases the button, cut down the length of refire2?
415 w_ready(thiswep, actor, weaponentity, fire);
418 .float bot_secondary_electromooth;
420 METHOD(Electro, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
422 PHYS_INPUT_BUTTON_ATCK(actor) = PHYS_INPUT_BUTTON_ATCK2(actor) = false;
423 if(vdist(actor.origin - actor.enemy.origin, >, 1000)) { actor.bot_secondary_electromooth = 0; }
424 if(actor.bot_secondary_electromooth == 0)
428 if(WEP_CVAR_PRI(electro, speed))
429 shoot = bot_aim(actor, weaponentity, WEP_CVAR_PRI(electro, speed), 0, WEP_CVAR_PRI(electro, lifetime), false);
431 shoot = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
435 PHYS_INPUT_BUTTON_ATCK(actor) = true;
436 if(random() < 0.01) actor.bot_secondary_electromooth = 1;
441 if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(electro, speed), WEP_CVAR_SEC(electro, speed_up), WEP_CVAR_SEC(electro, lifetime), true))
443 PHYS_INPUT_BUTTON_ATCK2(actor) = true;
444 if(random() < 0.03) actor.bot_secondary_electromooth = 0;
448 METHOD(Electro, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
450 if(autocvar_g_balance_electro_reload_ammo) // forced reload // WEAPONTODO
452 float ammo_amount = 0;
453 if(actor.(weaponentity).clip_load >= WEP_CVAR_PRI(electro, ammo))
455 if(actor.(weaponentity).clip_load >= WEP_CVAR_SEC(electro, ammo))
460 thiswep.wr_reload(thiswep, actor, weaponentity);
467 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire)))
469 W_Electro_Attack_Bolt(thiswep, actor, weaponentity);
470 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
475 if(time >= actor.(weaponentity).electro_secondarytime)
476 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(electro, refire)))
478 W_Electro_Attack_Orb(thiswep, actor, weaponentity);
479 actor.(weaponentity).electro_count = WEP_CVAR_SEC(electro, count);
480 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
481 actor.(weaponentity).electro_secondarytime = time + WEP_CVAR_SEC(electro, refire2) * W_WeaponRateFactor(actor);
485 METHOD(Electro, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
487 float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_PRI(electro, ammo);
488 ammo_amount += actor.(weaponentity).(weapon_load[WEP_ELECTRO.m_id]) >= WEP_CVAR_PRI(electro, ammo);
491 METHOD(Electro, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
494 if(WEP_CVAR(electro, combo_safeammocheck)) // true if you can fire at least one secondary blob AND one primary shot after it, otherwise false.
496 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
497 ammo_amount += actor.(weaponentity).(weapon_load[WEP_ELECTRO.m_id]) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
501 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_SEC(electro, ammo);
502 ammo_amount += actor.(weaponentity).(weapon_load[WEP_ELECTRO.m_id]) >= WEP_CVAR_SEC(electro, ammo);
506 METHOD(Electro, wr_resetplayer, void(entity thiswep, entity actor))
508 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
510 .entity weaponentity = weaponentities[slot];
511 actor.(weaponentity).electro_secondarytime = time;
514 METHOD(Electro, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
516 W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(electro, ammo), WEP_CVAR_SEC(electro, ammo)), SND_RELOAD);
518 METHOD(Electro, wr_suicidemessage, Notification(entity thiswep))
520 if(w_deathtype & HITTYPE_SECONDARY)
521 return WEAPON_ELECTRO_SUICIDE_ORBS;
523 return WEAPON_ELECTRO_SUICIDE_BOLT;
525 METHOD(Electro, wr_killmessage, Notification(entity thiswep))
527 if(w_deathtype & HITTYPE_SECONDARY)
529 return WEAPON_ELECTRO_MURDER_ORBS;
533 if(w_deathtype & HITTYPE_BOUNCE)
534 return WEAPON_ELECTRO_MURDER_COMBO;
536 return WEAPON_ELECTRO_MURDER_BOLT;
543 METHOD(Electro, wr_impacteffect, void(entity thiswep, entity actor))
546 org2 = w_org + w_backoff * 6;
547 if(w_deathtype & HITTYPE_SECONDARY)
549 pointparticles(EFFECT_ELECTRO_BALLEXPLODE, org2, '0 0 0', 1);
551 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);
555 if(w_deathtype & HITTYPE_BOUNCE)
557 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
558 pointparticles(EFFECT_ELECTRO_COMBO, org2, '0 0 0', 1);
560 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT_COMBO, VOL_BASE, ATTEN_NORM);
564 pointparticles(EFFECT_ELECTRO_IMPACT, org2, '0 0 0', 1);
566 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);