3 /* ammotype */ ATTRIB(Electro, ammo_field, .int, ammo_cells)
4 /* impulse */ ATTRIB(Electro, impulse, int, 5)
5 /* flags */ ATTRIB(Electro, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH);
6 /* rating */ ATTRIB(Electro, bot_pickupbasevalue, float, BOT_PICKUP_RATING_MID);
7 /* color */ ATTRIB(Electro, wpcolor, vector, '0 0.5 1');
8 /* modelname */ ATTRIB(Electro, mdl, string, "electro");
10 /* model */ ATTRIB(Electro, m_model, Model, MDL_ELECTRO_ITEM);
12 /* crosshair */ ATTRIB(Electro, w_crosshair, string, "gfx/crosshairelectro");
13 /* crosshair */ ATTRIB(Electro, w_crosshair_size, float, 0.6);
14 /* wepimg */ ATTRIB(Electro, model2, string, "weaponelectro");
15 /* refname */ ATTRIB(Electro, netname, string, "electro");
16 /* wepname */ ATTRIB(Electro, m_name, string, _("Electro"));
18 #define X(BEGIN, P, END, class, prefix) \
20 P(class, prefix, ammo, float, BOTH) \
21 P(class, prefix, animtime, float, BOTH) \
22 P(class, prefix, bouncefactor, float, SEC) \
23 P(class, prefix, bouncestop, float, SEC) \
24 P(class, prefix, comboradius, float, PRI) \
25 P(class, prefix, combo_comboradius, float, NONE) \
26 P(class, prefix, combo_comboradius_thruwall, float, NONE) \
27 P(class, prefix, combo_damage, float, NONE) \
28 P(class, prefix, combo_edgedamage, float, NONE) \
29 P(class, prefix, combo_force, float, NONE) \
30 P(class, prefix, combo_radius, float, NONE) \
31 P(class, prefix, combo_safeammocheck, float, NONE) \
32 P(class, prefix, combo_speed, float, NONE) \
33 P(class, prefix, count, float, SEC) \
34 P(class, prefix, damagedbycontents, float, SEC) \
35 P(class, prefix, damageforcescale, float, SEC) \
36 P(class, prefix, damage, float, BOTH) \
37 P(class, prefix, edgedamage, float, BOTH) \
38 P(class, prefix, force, float, BOTH) \
39 P(class, prefix, health, float, SEC) \
40 P(class, prefix, lifetime, float, BOTH) \
41 P(class, prefix, midaircombo_explode, float, PRI) \
42 P(class, prefix, midaircombo_interval, float, PRI) \
43 P(class, prefix, midaircombo_radius, float, PRI) \
44 P(class, prefix, radius, float, BOTH) \
45 P(class, prefix, refire2, float, SEC) \
46 P(class, prefix, refire, float, BOTH) \
47 P(class, prefix, reload_ammo, float, NONE) \
48 P(class, prefix, reload_time, float, NONE) \
49 P(class, prefix, speed, float, BOTH) \
50 P(class, prefix, speed_up, float, SEC) \
51 P(class, prefix, speed_z, float, SEC) \
52 P(class, prefix, spread, float, BOTH) \
53 P(class, prefix, stick, float, SEC) \
54 P(class, prefix, switchdelay_drop, float, NONE) \
55 P(class, prefix, switchdelay_raise, float, NONE) \
56 P(class, prefix, touchexplode, float, SEC) \
57 P(class, prefix, weaponreplace, string,NONE) \
58 P(class, prefix, weaponstartoverride, float, NONE) \
59 P(class, prefix, weaponstart, float, NONE) \
60 P(class, prefix, weaponthrowable, float, NONE) \
62 W_PROPS(X, Electro, electro)
66 REGISTER_WEAPON(ELECTRO, electro, NEW(Electro));
71 .float electro_secondarytime;
72 void W_Electro_ExplodeCombo(entity this);
77 spawnfunc(weapon_electro) { weapon_defaultspawnfunc(this, WEP_ELECTRO); }
79 void W_Electro_TriggerCombo(vector org, float rad, entity own)
81 entity e = WarpZone_FindRadius(org, rad, !WEP_CVAR(electro, combo_comboradius_thruwall));
84 if(e.classname == "electro_orb")
86 // do we allow thruwall triggering?
87 if(WEP_CVAR(electro, combo_comboradius_thruwall))
89 // if distance is greater than thruwall distance, check to make sure it's not through a wall
90 if(vdist(e.WarpZone_findradius_dist, >, WEP_CVAR(electro, combo_comboradius_thruwall)))
92 WarpZone_TraceLine(org, e.origin, MOVE_NOMONSTERS, e);
93 if(trace_fraction != 1)
95 // trigger is through a wall and outside of thruwall range, abort
102 // change owner to whoever caused the combo explosion
104 e.takedamage = DAMAGE_NO;
105 e.classname = "electro_orb_chain";
107 // now set the next one to trigger as well
108 setthink(e, W_Electro_ExplodeCombo);
110 // delay combo chains, looks cooler
115 (WEP_CVAR(electro, combo_speed) ?
116 (vlen(e.WarpZone_findradius_dist) / WEP_CVAR(electro, combo_speed))
126 void W_Electro_ExplodeCombo(entity this)
128 W_Electro_TriggerCombo(this.origin, WEP_CVAR(electro, combo_comboradius), this.realowner);
130 this.event_damage = func_null;
135 WEP_CVAR(electro, combo_damage),
136 WEP_CVAR(electro, combo_edgedamage),
137 WEP_CVAR(electro, combo_radius),
140 WEP_CVAR(electro, combo_force),
141 WEP_ELECTRO.m_id | HITTYPE_BOUNCE, // use THIS type for a combo because primary can't bounce
148 void W_Electro_Explode(entity this, entity directhitentity)
150 if(directhitentity.takedamage == DAMAGE_AIM)
151 if(IS_PLAYER(directhitentity))
152 if(DIFF_TEAM(this.realowner, directhitentity))
153 if(!IS_DEAD(directhitentity))
154 if(IsFlying(directhitentity))
155 Send_Notification(NOTIF_ONE, this.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_ELECTROBITCH);
157 this.event_damage = func_null;
158 this.takedamage = DAMAGE_NO;
160 if(this.move_movetype == MOVETYPE_BOUNCE || this.classname == "electro_orb") // TODO: classname is more reliable anyway?
165 WEP_CVAR_SEC(electro, damage),
166 WEP_CVAR_SEC(electro, edgedamage),
167 WEP_CVAR_SEC(electro, radius),
170 WEP_CVAR_SEC(electro, force),
171 this.projectiledeathtype,
177 W_Electro_TriggerCombo(this.origin, WEP_CVAR_PRI(electro, comboradius), this.realowner);
181 WEP_CVAR_PRI(electro, damage),
182 WEP_CVAR_PRI(electro, edgedamage),
183 WEP_CVAR_PRI(electro, radius),
186 WEP_CVAR_PRI(electro, force),
187 this.projectiledeathtype,
195 void W_Electro_Explode_use(entity this, entity actor, entity trigger)
197 W_Electro_Explode(this, trigger);
200 void W_Electro_TouchExplode(entity this, entity toucher)
202 PROJECTILE_TOUCH(this, toucher);
203 W_Electro_Explode(this, toucher);
207 void sys_phys_update_single(entity this);
209 void W_Electro_Bolt_Think(entity this)
211 // sys_phys_update_single(this);
212 if(time >= this.ltime)
214 this.use(this, NULL, NULL);
218 if(WEP_CVAR_PRI(electro, midaircombo_radius))
221 entity e = WarpZone_FindRadius(this.origin, WEP_CVAR_PRI(electro, midaircombo_radius), true);
223 // loop through nearby orbs and trigger them
226 if(e.classname == "electro_orb")
228 // change owner to whoever caused the combo explosion
229 e.realowner = this.realowner;
230 e.takedamage = DAMAGE_NO;
231 e.classname = "electro_orb_chain";
233 // now set the next one to trigger as well
234 setthink(e, W_Electro_ExplodeCombo);
236 // delay combo chains, looks cooler
241 (WEP_CVAR(electro, combo_speed) ?
242 (vlen(e.WarpZone_findradius_dist) / WEP_CVAR(electro, combo_speed))
253 // if we triggered an orb, should we explode? if not, lets try again next time
254 if(found && WEP_CVAR_PRI(electro, midaircombo_explode))
255 { this.use(this, NULL, NULL); }
257 { this.nextthink = min(time + WEP_CVAR_PRI(electro, midaircombo_interval), this.ltime); }
259 else { this.nextthink = this.ltime; }
260 // this.nextthink = time;
263 void W_Electro_Attack_Bolt(Weapon thiswep, entity actor)
267 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(electro, ammo));
269 W_SetupShot_ProjectileSize(
277 WEP_CVAR_PRI(electro, damage)
280 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
282 proj = new(electro_bolt);
283 proj.owner = proj.realowner = actor;
284 proj.bot_dodge = true;
285 proj.bot_dodgerating = WEP_CVAR_PRI(electro, damage);
286 proj.use = W_Electro_Explode_use;
287 setthink(proj, W_Electro_Bolt_Think);
288 proj.nextthink = time;
289 proj.ltime = time + WEP_CVAR_PRI(electro, lifetime);
290 PROJECTILE_MAKETRIGGER(proj);
291 proj.projectiledeathtype = WEP_ELECTRO.m_id;
292 setorigin(proj, w_shotorg);
295 set_movetype(proj, MOVETYPE_FLY);
296 W_SetupProjVelocity_PRI(proj, electro);
297 proj.angles = vectoangles(proj.velocity);
298 settouch(proj, W_Electro_TouchExplode);
299 setsize(proj, '0 0 -3', '0 0 -3');
300 proj.flags = FL_PROJECTILE;
301 IL_PUSH(g_projectiles, proj);
302 proj.missile_flags = MIF_SPLASH;
304 CSQCProjectile(proj, true, PROJECTILE_ELECTRO_BEAM, true);
306 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
307 // proj.com_phys_pos = proj.origin;
308 // proj.com_phys_vel = proj.velocity;
311 void W_Electro_Orb_Stick(entity this, entity to)
313 entity newproj = spawn();
314 newproj.classname = this.classname;
316 newproj.bot_dodge = this.bot_dodge;
317 newproj.bot_dodgerating = this.bot_dodgerating;
319 newproj.owner = this.owner;
320 newproj.realowner = this.realowner;
321 setsize(newproj, this.mins, this.maxs);
322 setorigin(newproj, this.origin);
323 setmodel(newproj, MDL_PROJECTILE_ELECTRO);
324 newproj.angles = vectoangles(-trace_plane_normal); // face against the surface
326 newproj.takedamage = this.takedamage;
327 newproj.damageforcescale = this.damageforcescale;
328 newproj.health = this.health;
329 newproj.event_damage = this.event_damage;
330 newproj.spawnshieldtime = this.spawnshieldtime;
331 newproj.damagedbycontents = true;
333 set_movetype(newproj, MOVETYPE_NONE); // lock the orb in place
334 newproj.projectiledeathtype = this.projectiledeathtype;
336 settouch(newproj, func_null);
337 setthink(newproj, getthink(this));
338 newproj.nextthink = this.nextthink;
339 newproj.use = this.use;
340 newproj.flags = this.flags;
345 SetMovetypeFollow(this, to);
348 void W_Electro_Orb_Touch(entity this, entity toucher)
350 PROJECTILE_TOUCH(this, toucher);
351 if(toucher.takedamage == DAMAGE_AIM)
352 { if(WEP_CVAR_SEC(electro, touchexplode)) { W_Electro_Explode(this, toucher); } }
355 //UpdateCSQCProjectile(this);
356 spamsound(this, CH_SHOTS, SND(ELECTRO_BOUNCE), VOL_BASE, ATTEN_NORM);
357 this.projectiledeathtype |= HITTYPE_BOUNCE;
359 if(WEP_CVAR_SEC(electro, stick))
360 W_Electro_Orb_Stick(this, toucher);
364 void W_Electro_Orb_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
369 // note: combos are usually triggered by W_Electro_TriggerCombo, not damage
370 float is_combo = (inflictor.classname == "electro_orb_chain" || inflictor.classname == "electro_bolt");
372 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, (is_combo ? 1 : -1)))
373 return; // g_projectiles_damage says to halt
375 this.health = this.health - damage;
378 this.takedamage = DAMAGE_NO;
379 this.nextthink = time;
382 // change owner to whoever caused the combo explosion
383 this.realowner = inflictor.realowner;
384 this.classname = "electro_orb_chain";
385 setthink(this, W_Electro_ExplodeCombo);
386 this.nextthink = time +
388 // bound the length, inflictor may be in a galaxy far far away (warpzones)
390 WEP_CVAR(electro, combo_radius),
391 vlen(this.origin - inflictor.origin)
394 // delay combo chains, looks cooler
395 WEP_CVAR(electro, combo_speed)
400 this.use = W_Electro_Explode_use;
401 setthink(this, adaptor_think2use); // not _hittype_splash, as this runs "immediately"
406 void W_Electro_Attack_Orb(Weapon thiswep, entity actor)
408 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(electro, ammo));
410 W_SetupShot_ProjectileSize(
418 WEP_CVAR_SEC(electro, damage)
421 w_shotdir = v_forward; // no TrueAim for grenades please
423 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
425 entity proj = new(electro_orb);
426 proj.owner = proj.realowner = actor;
427 proj.use = W_Electro_Explode_use;
428 setthink(proj, adaptor_think2use_hittype_splash);
429 proj.bot_dodge = true;
430 proj.bot_dodgerating = WEP_CVAR_SEC(electro, damage);
431 proj.nextthink = time + WEP_CVAR_SEC(electro, lifetime);
432 PROJECTILE_MAKETRIGGER(proj);
433 proj.projectiledeathtype = WEP_ELECTRO.m_id | HITTYPE_SECONDARY;
434 setorigin(proj, w_shotorg);
436 //proj.glow_size = 50;
437 //proj.glow_color = 45;
438 set_movetype(proj, MOVETYPE_BOUNCE);
439 W_SetupProjVelocity_UP_SEC(proj, electro);
440 settouch(proj, W_Electro_Orb_Touch);
441 setsize(proj, '-4 -4 -4', '4 4 4');
442 proj.takedamage = DAMAGE_YES;
443 proj.damageforcescale = WEP_CVAR_SEC(electro, damageforcescale);
444 proj.health = WEP_CVAR_SEC(electro, health);
445 proj.event_damage = W_Electro_Orb_Damage;
446 proj.flags = FL_PROJECTILE;
447 IL_PUSH(g_projectiles, proj);
448 proj.damagedbycontents = (WEP_CVAR_SEC(electro, damagedbycontents));
450 proj.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
451 proj.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
452 proj.missile_flags = MIF_SPLASH | MIF_ARC;
457 copyentity(proj, p2);
458 setmodel(p2, MDL_PROJECTILE_ELECTRO);
459 setsize(p2, proj.mins, proj.maxs);
462 CSQCProjectile(proj, true, PROJECTILE_ELECTRO, false); // no culling, it has sound
464 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
467 void W_Electro_CheckAttack(Weapon thiswep, entity actor, .entity weaponentity, int fire)
469 if(actor.electro_count > 1)
470 if(PHYS_INPUT_BUTTON_ATCK2(actor))
471 if(weapon_prepareattack(thiswep, actor, weaponentity, true, -1))
473 W_Electro_Attack_Orb(WEP_ELECTRO, actor);
474 actor.electro_count -= 1;
475 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
478 // WEAPONTODO: when the player releases the button, cut down the length of refire2?
479 w_ready(thiswep, actor, weaponentity, fire);
482 .float bot_secondary_electromooth;
484 METHOD(Electro, wr_aim, void(entity thiswep, entity actor))
486 PHYS_INPUT_BUTTON_ATCK(actor) = PHYS_INPUT_BUTTON_ATCK2(actor) = false;
487 if(vdist(actor.origin - actor.enemy.origin, >, 1000)) { actor.bot_secondary_electromooth = 0; }
488 if(actor.bot_secondary_electromooth == 0)
492 if(WEP_CVAR_PRI(electro, speed))
493 shoot = bot_aim(actor, WEP_CVAR_PRI(electro, speed), 0, WEP_CVAR_PRI(electro, lifetime), false);
495 shoot = bot_aim(actor, 1000000, 0, 0.001, false);
499 PHYS_INPUT_BUTTON_ATCK(actor) = true;
500 if(random() < 0.01) actor.bot_secondary_electromooth = 1;
505 if(bot_aim(actor, WEP_CVAR_SEC(electro, speed), WEP_CVAR_SEC(electro, speed_up), WEP_CVAR_SEC(electro, lifetime), true))
507 PHYS_INPUT_BUTTON_ATCK2(actor) = true;
508 if(random() < 0.03) actor.bot_secondary_electromooth = 0;
512 METHOD(Electro, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
514 if(autocvar_g_balance_electro_reload_ammo) // forced reload // WEAPONTODO
516 float ammo_amount = 0;
517 if(actor.clip_load >= WEP_CVAR_PRI(electro, ammo))
519 if(actor.clip_load >= WEP_CVAR_SEC(electro, ammo))
524 thiswep.wr_reload(thiswep, actor, weaponentity);
531 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire)))
533 W_Electro_Attack_Bolt(thiswep, actor);
534 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
539 if(time >= actor.electro_secondarytime)
540 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(electro, refire)))
542 W_Electro_Attack_Orb(thiswep, actor);
543 actor.electro_count = WEP_CVAR_SEC(electro, count);
544 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
545 actor.electro_secondarytime = time + WEP_CVAR_SEC(electro, refire2) * W_WeaponRateFactor(actor);
549 METHOD(Electro, wr_checkammo1, bool(entity thiswep, entity actor))
551 float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_PRI(electro, ammo);
552 ammo_amount += actor.(weapon_load[WEP_ELECTRO.m_id]) >= WEP_CVAR_PRI(electro, ammo);
555 METHOD(Electro, wr_checkammo2, bool(entity thiswep, entity actor))
558 if(WEP_CVAR(electro, combo_safeammocheck)) // true if you can fire at least one secondary blob AND one primary shot after it, otherwise false.
560 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
561 ammo_amount += actor.(weapon_load[WEP_ELECTRO.m_id]) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
565 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_SEC(electro, ammo);
566 ammo_amount += actor.(weapon_load[WEP_ELECTRO.m_id]) >= WEP_CVAR_SEC(electro, ammo);
570 METHOD(Electro, wr_resetplayer, void(entity thiswep, entity actor))
572 actor.electro_secondarytime = time;
574 METHOD(Electro, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
576 W_Reload(actor, min(WEP_CVAR_PRI(electro, ammo), WEP_CVAR_SEC(electro, ammo)), SND_RELOAD);
578 METHOD(Electro, wr_suicidemessage, Notification(entity thiswep))
580 if(w_deathtype & HITTYPE_SECONDARY)
581 return WEAPON_ELECTRO_SUICIDE_ORBS;
583 return WEAPON_ELECTRO_SUICIDE_BOLT;
585 METHOD(Electro, wr_killmessage, Notification(entity thiswep))
587 if(w_deathtype & HITTYPE_SECONDARY)
589 return WEAPON_ELECTRO_MURDER_ORBS;
593 if(w_deathtype & HITTYPE_BOUNCE)
594 return WEAPON_ELECTRO_MURDER_COMBO;
596 return WEAPON_ELECTRO_MURDER_BOLT;
603 METHOD(Electro, wr_impacteffect, void(entity thiswep, entity actor))
606 org2 = w_org + w_backoff * 6;
607 if(w_deathtype & HITTYPE_SECONDARY)
609 pointparticles(EFFECT_ELECTRO_BALLEXPLODE, org2, '0 0 0', 1);
611 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);
615 if(w_deathtype & HITTYPE_BOUNCE)
617 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
618 pointparticles(EFFECT_ELECTRO_COMBO, org2, '0 0 0', 1);
620 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT_COMBO, VOL_BASE, ATTEN_NORM);
624 pointparticles(EFFECT_ELECTRO_IMPACT, org2, '0 0 0', 1);
626 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);