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 REGISTER_WEAPON(ELECTRO, NEW(Electro));
20 #define ELECTRO_SETTINGS(w_cvar,w_prop) ELECTRO_SETTINGS_LIST(w_cvar, w_prop, ELECTRO, electro)
21 #define ELECTRO_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
22 w_cvar(id, sn, BOTH, ammo) \
23 w_cvar(id, sn, BOTH, animtime) \
24 w_cvar(id, sn, BOTH, damage) \
25 w_cvar(id, sn, BOTH, edgedamage) \
26 w_cvar(id, sn, BOTH, force) \
27 w_cvar(id, sn, BOTH, radius) \
28 w_cvar(id, sn, BOTH, refire) \
29 w_cvar(id, sn, BOTH, speed) \
30 w_cvar(id, sn, BOTH, spread) \
31 w_cvar(id, sn, BOTH, lifetime) \
32 w_cvar(id, sn, PRI, comboradius) \
33 w_cvar(id, sn, PRI, midaircombo_explode) \
34 w_cvar(id, sn, PRI, midaircombo_interval) \
35 w_cvar(id, sn, PRI, midaircombo_radius) \
36 w_cvar(id, sn, SEC, bouncefactor) \
37 w_cvar(id, sn, SEC, bouncestop) \
38 w_cvar(id, sn, SEC, count) \
39 w_cvar(id, sn, SEC, damageforcescale) \
40 w_cvar(id, sn, SEC, damagedbycontents) \
41 w_cvar(id, sn, SEC, health) \
42 w_cvar(id, sn, SEC, refire2) \
43 w_cvar(id, sn, SEC, speed_up) \
44 w_cvar(id, sn, SEC, speed_z) \
45 w_cvar(id, sn, SEC, touchexplode) \
46 w_cvar(id, sn, NONE, combo_comboradius) \
47 w_cvar(id, sn, NONE, combo_comboradius_thruwall) \
48 w_cvar(id, sn, NONE, combo_damage) \
49 w_cvar(id, sn, NONE, combo_edgedamage) \
50 w_cvar(id, sn, NONE, combo_force) \
51 w_cvar(id, sn, NONE, combo_radius) \
52 w_cvar(id, sn, NONE, combo_speed) \
53 w_cvar(id, sn, NONE, combo_safeammocheck) \
54 w_prop(id, sn, float, reloading_ammo, reload_ammo) \
55 w_prop(id, sn, float, reloading_time, reload_time) \
56 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
57 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
58 w_prop(id, sn, string, weaponreplace, weaponreplace) \
59 w_prop(id, sn, float, weaponstart, weaponstart) \
60 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
61 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
64 ELECTRO_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
66 .float electro_secondarytime;
67 void W_Electro_ExplodeCombo(void);
72 spawnfunc(weapon_electro) { weapon_defaultspawnfunc(this, WEP_ELECTRO); }
74 void W_Electro_TriggerCombo(vector org, float rad, entity own)
76 entity e = WarpZone_FindRadius(org, rad, !WEP_CVAR(electro, combo_comboradius_thruwall));
79 if(e.classname == "electro_orb")
81 // do we allow thruwall triggering?
82 if(WEP_CVAR(electro, combo_comboradius_thruwall))
84 // if distance is greater than thruwall distance, check to make sure it's not through a wall
85 if(vlen(e.WarpZone_findradius_dist) > WEP_CVAR(electro, combo_comboradius_thruwall))
87 WarpZone_TraceLine(org, e.origin, MOVE_NOMONSTERS, e);
88 if(trace_fraction != 1)
90 // trigger is through a wall and outside of thruwall range, abort
97 // change owner to whoever caused the combo explosion
99 e.takedamage = DAMAGE_NO;
100 e.classname = "electro_orb_chain";
102 // now set the next one to trigger as well
103 e.think = W_Electro_ExplodeCombo;
105 // delay combo chains, looks cooler
110 (WEP_CVAR(electro, combo_speed) ?
111 (vlen(e.WarpZone_findradius_dist) / WEP_CVAR(electro, combo_speed))
121 void W_Electro_ExplodeCombo(void)
123 W_Electro_TriggerCombo(self.origin, WEP_CVAR(electro, combo_comboradius), self.realowner);
125 self.event_damage = func_null;
130 WEP_CVAR(electro, combo_damage),
131 WEP_CVAR(electro, combo_edgedamage),
132 WEP_CVAR(electro, combo_radius),
135 WEP_CVAR(electro, combo_force),
136 WEP_ELECTRO.m_id | HITTYPE_BOUNCE, // use THIS type for a combo because primary can't bounce
143 void W_Electro_Explode(void)
145 if(other.takedamage == DAMAGE_AIM)
147 if(DIFF_TEAM(self.realowner, other))
148 if(other.deadflag == DEAD_NO)
150 Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_ELECTROBITCH);
152 self.event_damage = func_null;
153 self.takedamage = DAMAGE_NO;
155 if(self.movetype == MOVETYPE_BOUNCE)
160 WEP_CVAR_SEC(electro, damage),
161 WEP_CVAR_SEC(electro, edgedamage),
162 WEP_CVAR_SEC(electro, radius),
165 WEP_CVAR_SEC(electro, force),
166 self.projectiledeathtype,
172 W_Electro_TriggerCombo(self.origin, WEP_CVAR_PRI(electro, comboradius), self.realowner);
176 WEP_CVAR_PRI(electro, damage),
177 WEP_CVAR_PRI(electro, edgedamage),
178 WEP_CVAR_PRI(electro, radius),
181 WEP_CVAR_PRI(electro, force),
182 self.projectiledeathtype,
190 void W_Electro_TouchExplode(void)
196 void W_Electro_Bolt_Think(void)
198 if(time >= self.ltime)
204 if(WEP_CVAR_PRI(electro, midaircombo_radius))
207 entity e = WarpZone_FindRadius(self.origin, WEP_CVAR_PRI(electro, midaircombo_radius), true);
209 // loop through nearby orbs and trigger them
212 if(e.classname == "electro_orb")
214 // change owner to whoever caused the combo explosion
215 e.realowner = self.realowner;
216 e.takedamage = DAMAGE_NO;
217 e.classname = "electro_orb_chain";
219 // now set the next one to trigger as well
220 e.think = W_Electro_ExplodeCombo;
222 // delay combo chains, looks cooler
227 (WEP_CVAR(electro, combo_speed) ?
228 (vlen(e.WarpZone_findradius_dist) / WEP_CVAR(electro, combo_speed))
239 // if we triggered an orb, should we explode? if not, lets try again next time
240 if(found && WEP_CVAR_PRI(electro, midaircombo_explode))
243 { self.nextthink = min(time + WEP_CVAR_PRI(electro, midaircombo_interval), self.ltime); }
245 else { self.nextthink = self.ltime; }
248 void W_Electro_Attack_Bolt(Weapon thiswep)
252 W_DecreaseAmmo(thiswep, self, WEP_CVAR_PRI(electro, ammo));
254 W_SetupShot_ProjectileSize(
262 WEP_CVAR_PRI(electro, damage)
265 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
267 proj = new(electro_bolt);
268 proj.owner = proj.realowner = self;
269 proj.bot_dodge = true;
270 proj.bot_dodgerating = WEP_CVAR_PRI(electro, damage);
271 proj.use = W_Electro_Explode;
272 proj.think = W_Electro_Bolt_Think;
273 proj.nextthink = time;
274 proj.ltime = time + WEP_CVAR_PRI(electro, lifetime);
275 PROJECTILE_MAKETRIGGER(proj);
276 proj.projectiledeathtype = WEP_ELECTRO.m_id;
277 setorigin(proj, w_shotorg);
279 proj.movetype = MOVETYPE_FLY;
280 W_SetupProjVelocity_PRI(proj, electro);
281 proj.angles = vectoangles(proj.velocity);
282 proj.touch = W_Electro_TouchExplode;
283 setsize(proj, '0 0 -3', '0 0 -3');
284 proj.flags = FL_PROJECTILE;
285 proj.missile_flags = MIF_SPLASH;
287 CSQCProjectile(proj, true, PROJECTILE_ELECTRO_BEAM, true);
289 MUTATOR_CALLHOOK(EditProjectile, self, proj);
292 void W_Electro_Orb_Touch(void)
295 if(other.takedamage == DAMAGE_AIM)
296 { if(WEP_CVAR_SEC(electro, touchexplode)) { W_Electro_Explode(); } }
299 //UpdateCSQCProjectile(self);
300 spamsound(self, CH_SHOTS, SND(ELECTRO_BOUNCE), VOL_BASE, ATTEN_NORM);
301 self.projectiledeathtype |= HITTYPE_BOUNCE;
305 void W_Electro_Orb_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
310 // note: combos are usually triggered by W_Electro_TriggerCombo, not damage
311 float is_combo = (inflictor.classname == "electro_orb_chain" || inflictor.classname == "electro_bolt");
313 if(!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, (is_combo ? 1 : -1)))
314 return; // g_projectiles_damage says to halt
316 self.health = self.health - damage;
319 self.takedamage = DAMAGE_NO;
320 self.nextthink = time;
323 // change owner to whoever caused the combo explosion
324 self.realowner = inflictor.realowner;
325 self.classname = "electro_orb_chain";
326 self.think = W_Electro_ExplodeCombo;
327 self.nextthink = time +
329 // bound the length, inflictor may be in a galaxy far far away (warpzones)
331 WEP_CVAR(electro, combo_radius),
332 vlen(self.origin - inflictor.origin)
335 // delay combo chains, looks cooler
336 WEP_CVAR(electro, combo_speed)
341 self.use = W_Electro_Explode;
342 self.think = adaptor_think2use; // not _hittype_splash, as this runs "immediately"
347 void W_Electro_Attack_Orb(Weapon thiswep)
349 W_DecreaseAmmo(thiswep, self, WEP_CVAR_SEC(electro, ammo));
351 W_SetupShot_ProjectileSize(
359 WEP_CVAR_SEC(electro, damage)
362 w_shotdir = v_forward; // no TrueAim for grenades please
364 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
366 entity proj = new(electro_orb);
367 proj.owner = proj.realowner = self;
368 proj.use = W_Electro_Explode;
369 proj.think = adaptor_think2use_hittype_splash;
370 proj.bot_dodge = true;
371 proj.bot_dodgerating = WEP_CVAR_SEC(electro, damage);
372 proj.nextthink = time + WEP_CVAR_SEC(electro, lifetime);
373 PROJECTILE_MAKETRIGGER(proj);
374 proj.projectiledeathtype = WEP_ELECTRO.m_id | HITTYPE_SECONDARY;
375 setorigin(proj, w_shotorg);
377 //proj.glow_size = 50;
378 //proj.glow_color = 45;
379 proj.movetype = MOVETYPE_BOUNCE;
380 W_SetupProjVelocity_UP_SEC(proj, electro);
381 proj.touch = W_Electro_Orb_Touch;
382 setsize(proj, '0 0 -4', '0 0 -4');
383 proj.takedamage = DAMAGE_YES;
384 proj.damageforcescale = WEP_CVAR_SEC(electro, damageforcescale);
385 proj.health = WEP_CVAR_SEC(electro, health);
386 proj.event_damage = W_Electro_Orb_Damage;
387 proj.flags = FL_PROJECTILE;
388 proj.damagedbycontents = (WEP_CVAR_SEC(electro, damagedbycontents));
390 proj.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
391 proj.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
392 proj.missile_flags = MIF_SPLASH | MIF_ARC;
397 copyentity(proj, p2);
398 setmodel(p2, MDL_PROJECTILE_ELECTRO);
399 setsize(p2, proj.mins, proj.maxs);
402 CSQCProjectile(proj, true, PROJECTILE_ELECTRO, false); // no culling, it has sound
404 MUTATOR_CALLHOOK(EditProjectile, self, proj);
407 void W_Electro_CheckAttack(Weapon thiswep, entity actor, int slot, int fire)
409 if(self.electro_count > 1)
410 if(self.BUTTON_ATCK2)
411 if(weapon_prepareattack(thiswep, actor, slot, true, -1))
413 W_Electro_Attack_Orb(WEP_ELECTRO);
414 self.electro_count -= 1;
415 weapon_thinkf(actor, slot, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
418 // WEAPONTODO: when the player releases the button, cut down the length of refire2?
419 w_ready(thiswep, actor, slot, fire);
422 .float bot_secondary_electromooth;
424 METHOD(Electro, wr_aim, void(entity thiswep))
426 self.BUTTON_ATCK = self.BUTTON_ATCK2 = false;
427 if(vlen(self.origin-self.enemy.origin) > 1000) { self.bot_secondary_electromooth = 0; }
428 if(self.bot_secondary_electromooth == 0)
432 if(WEP_CVAR_PRI(electro, speed))
433 shoot = bot_aim(WEP_CVAR_PRI(electro, speed), 0, WEP_CVAR_PRI(electro, lifetime), false);
435 shoot = bot_aim(1000000, 0, 0.001, false);
439 self.BUTTON_ATCK = true;
440 if(random() < 0.01) self.bot_secondary_electromooth = 1;
445 if(bot_aim(WEP_CVAR_SEC(electro, speed), WEP_CVAR_SEC(electro, speed_up), WEP_CVAR_SEC(electro, lifetime), true))
447 self.BUTTON_ATCK2 = true;
448 if(random() < 0.03) self.bot_secondary_electromooth = 0;
452 METHOD(Electro, wr_think, void(entity thiswep, entity actor, int slot, int fire))
454 if(autocvar_g_balance_electro_reload_ammo) // forced reload // WEAPONTODO
456 float ammo_amount = 0;
457 if(actor.clip_load >= WEP_CVAR_PRI(electro, ammo))
459 if(actor.clip_load >= WEP_CVAR_SEC(electro, ammo))
464 Weapon w = get_weaponinfo(actor.weapon);
472 if(weapon_prepareattack(thiswep, actor, slot, false, WEP_CVAR_PRI(electro, refire)))
474 W_Electro_Attack_Bolt(thiswep);
475 weapon_thinkf(actor, slot, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
480 if(time >= actor.electro_secondarytime)
481 if(weapon_prepareattack(thiswep, actor, slot, true, WEP_CVAR_SEC(electro, refire)))
483 W_Electro_Attack_Orb(thiswep);
484 actor.electro_count = WEP_CVAR_SEC(electro, count);
485 weapon_thinkf(actor, slot, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
486 actor.electro_secondarytime = time + WEP_CVAR_SEC(electro, refire2) * W_WeaponRateFactor();
490 METHOD(Electro, wr_init, void(entity thiswep))
492 ELECTRO_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
494 METHOD(Electro, wr_checkammo1, bool(entity thiswep))
496 float ammo_amount = self.WEP_AMMO(ELECTRO) >= WEP_CVAR_PRI(electro, ammo);
497 ammo_amount += self.(weapon_load[WEP_ELECTRO.m_id]) >= WEP_CVAR_PRI(electro, ammo);
500 METHOD(Electro, wr_checkammo2, bool(entity thiswep))
503 if(WEP_CVAR(electro, combo_safeammocheck)) // true if you can fire at least one secondary blob AND one primary shot after it, otherwise false.
505 ammo_amount = self.WEP_AMMO(ELECTRO) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
506 ammo_amount += self.(weapon_load[WEP_ELECTRO.m_id]) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
510 ammo_amount = self.WEP_AMMO(ELECTRO) >= WEP_CVAR_SEC(electro, ammo);
511 ammo_amount += self.(weapon_load[WEP_ELECTRO.m_id]) >= WEP_CVAR_SEC(electro, ammo);
515 METHOD(Electro, wr_config, void(entity thiswep))
517 ELECTRO_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
519 METHOD(Electro, wr_resetplayer, void(entity thiswep))
521 self.electro_secondarytime = time;
523 METHOD(Electro, wr_reload, void(entity thiswep))
525 W_Reload(self, min(WEP_CVAR_PRI(electro, ammo), WEP_CVAR_SEC(electro, ammo)), SND(RELOAD));
527 METHOD(Electro, wr_suicidemessage, int(entity thiswep))
529 if(w_deathtype & HITTYPE_SECONDARY)
530 return WEAPON_ELECTRO_SUICIDE_ORBS;
532 return WEAPON_ELECTRO_SUICIDE_BOLT;
534 METHOD(Electro, wr_killmessage, int(entity thiswep))
536 if(w_deathtype & HITTYPE_SECONDARY)
538 return WEAPON_ELECTRO_MURDER_ORBS;
542 if(w_deathtype & HITTYPE_BOUNCE)
543 return WEAPON_ELECTRO_MURDER_COMBO;
545 return WEAPON_ELECTRO_MURDER_BOLT;
552 METHOD(Electro, wr_impacteffect, void(entity thiswep))
555 org2 = w_org + w_backoff * 6;
556 if(w_deathtype & HITTYPE_SECONDARY)
558 pointparticles(particleeffectnum(EFFECT_ELECTRO_BALLEXPLODE), org2, '0 0 0', 1);
560 sound(self, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);
564 if(w_deathtype & HITTYPE_BOUNCE)
566 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
567 pointparticles(particleeffectnum(EFFECT_ELECTRO_COMBO), org2, '0 0 0', 1);
569 sound(self, CH_SHOTS, SND_ELECTRO_IMPACT_COMBO, VOL_BASE, ATTEN_NORM);
573 pointparticles(particleeffectnum(EFFECT_ELECTRO_IMPACT), org2, '0 0 0', 1);
575 sound(self, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);