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, message, 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(WEP_ELECTRO.m_id); }
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);
268 proj.classname = "electro_bolt";
269 proj.owner = proj.realowner = self;
270 proj.bot_dodge = true;
271 proj.bot_dodgerating = WEP_CVAR_PRI(electro, damage);
272 proj.use = W_Electro_Explode;
273 proj.think = W_Electro_Bolt_Think;
274 proj.nextthink = time;
275 proj.ltime = time + WEP_CVAR_PRI(electro, lifetime);
276 PROJECTILE_MAKETRIGGER(proj);
277 proj.projectiledeathtype = WEP_ELECTRO.m_id;
278 setorigin(proj, w_shotorg);
280 proj.movetype = MOVETYPE_FLY;
281 W_SetupProjVelocity_PRI(proj, electro);
282 proj.angles = vectoangles(proj.velocity);
283 proj.touch = W_Electro_TouchExplode;
284 setsize(proj, '0 0 -3', '0 0 -3');
285 proj.flags = FL_PROJECTILE;
286 proj.missile_flags = MIF_SPLASH;
288 CSQCProjectile(proj, true, PROJECTILE_ELECTRO_BEAM, true);
290 MUTATOR_CALLHOOK(EditProjectile, self, proj);
293 void W_Electro_Orb_Touch(void)
296 if(other.takedamage == DAMAGE_AIM)
297 { if(WEP_CVAR_SEC(electro, touchexplode)) { W_Electro_Explode(); } }
300 //UpdateCSQCProjectile(self);
301 spamsound(self, CH_SHOTS, SND(ELECTRO_BOUNCE), VOL_BASE, ATTEN_NORM);
302 self.projectiledeathtype |= HITTYPE_BOUNCE;
306 void W_Electro_Orb_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
311 // note: combos are usually triggered by W_Electro_TriggerCombo, not damage
312 float is_combo = (inflictor.classname == "electro_orb_chain" || inflictor.classname == "electro_bolt");
314 if(!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, (is_combo ? 1 : -1)))
315 return; // g_projectiles_damage says to halt
317 self.health = self.health - damage;
320 self.takedamage = DAMAGE_NO;
321 self.nextthink = time;
324 // change owner to whoever caused the combo explosion
325 self.realowner = inflictor.realowner;
326 self.classname = "electro_orb_chain";
327 self.think = W_Electro_ExplodeCombo;
328 self.nextthink = time +
330 // bound the length, inflictor may be in a galaxy far far away (warpzones)
332 WEP_CVAR(electro, combo_radius),
333 vlen(self.origin - inflictor.origin)
336 // delay combo chains, looks cooler
337 WEP_CVAR(electro, combo_speed)
342 self.use = W_Electro_Explode;
343 self.think = adaptor_think2use; // not _hittype_splash, as this runs "immediately"
348 void W_Electro_Attack_Orb(Weapon thiswep)
350 W_DecreaseAmmo(thiswep, self, WEP_CVAR_SEC(electro, ammo));
352 W_SetupShot_ProjectileSize(
360 WEP_CVAR_SEC(electro, damage)
363 w_shotdir = v_forward; // no TrueAim for grenades please
365 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
367 entity proj = spawn();
368 proj.classname = "electro_orb";
369 proj.owner = proj.realowner = self;
370 proj.use = W_Electro_Explode;
371 proj.think = adaptor_think2use_hittype_splash;
372 proj.bot_dodge = true;
373 proj.bot_dodgerating = WEP_CVAR_SEC(electro, damage);
374 proj.nextthink = time + WEP_CVAR_SEC(electro, lifetime);
375 PROJECTILE_MAKETRIGGER(proj);
376 proj.projectiledeathtype = WEP_ELECTRO.m_id | HITTYPE_SECONDARY;
377 setorigin(proj, w_shotorg);
379 //proj.glow_size = 50;
380 //proj.glow_color = 45;
381 proj.movetype = MOVETYPE_BOUNCE;
382 W_SetupProjVelocity_UP_SEC(proj, electro);
383 proj.touch = W_Electro_Orb_Touch;
384 setsize(proj, '0 0 -4', '0 0 -4');
385 proj.takedamage = DAMAGE_YES;
386 proj.damageforcescale = WEP_CVAR_SEC(electro, damageforcescale);
387 proj.health = WEP_CVAR_SEC(electro, health);
388 proj.event_damage = W_Electro_Orb_Damage;
389 proj.flags = FL_PROJECTILE;
390 proj.damagedbycontents = (WEP_CVAR_SEC(electro, damagedbycontents));
392 proj.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
393 proj.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
394 proj.missile_flags = MIF_SPLASH | MIF_ARC;
399 copyentity(proj, p2);
400 setmodel(p2, MDL_PROJECTILE_ELECTRO);
401 setsize(p2, proj.mins, proj.maxs);
404 CSQCProjectile(proj, true, PROJECTILE_ELECTRO, false); // no culling, it has sound
406 MUTATOR_CALLHOOK(EditProjectile, self, proj);
409 void W_Electro_CheckAttack(Weapon thiswep, entity actor, bool fire1, bool fire2)
411 if(self.electro_count > 1)
412 if(self.BUTTON_ATCK2)
413 if(weapon_prepareattack(actor, true, -1))
415 W_Electro_Attack_Orb(WEP_ELECTRO);
416 self.electro_count -= 1;
417 weapon_thinkf(actor, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
420 // WEAPONTODO: when the player releases the button, cut down the length of refire2?
421 w_ready(thiswep, actor, fire1, fire2);
424 .float bot_secondary_electromooth;
426 METHOD(Electro, wr_aim, void(entity thiswep))
428 self.BUTTON_ATCK = self.BUTTON_ATCK2 = false;
429 if(vlen(self.origin-self.enemy.origin) > 1000) { self.bot_secondary_electromooth = 0; }
430 if(self.bot_secondary_electromooth == 0)
434 if(WEP_CVAR_PRI(electro, speed))
435 shoot = bot_aim(WEP_CVAR_PRI(electro, speed), 0, WEP_CVAR_PRI(electro, lifetime), false);
437 shoot = bot_aim(1000000, 0, 0.001, false);
441 self.BUTTON_ATCK = true;
442 if(random() < 0.01) self.bot_secondary_electromooth = 1;
447 if(bot_aim(WEP_CVAR_SEC(electro, speed), WEP_CVAR_SEC(electro, speed_up), WEP_CVAR_SEC(electro, lifetime), true))
449 self.BUTTON_ATCK2 = true;
450 if(random() < 0.03) self.bot_secondary_electromooth = 0;
454 METHOD(Electro, wr_think, void(entity thiswep, entity actor, bool fire1, bool fire2))
456 if(autocvar_g_balance_electro_reload_ammo) // forced reload // WEAPONTODO
458 float ammo_amount = 0;
459 if(actor.clip_load >= WEP_CVAR_PRI(electro, ammo))
461 if(actor.clip_load >= WEP_CVAR_SEC(electro, ammo))
466 Weapon w = get_weaponinfo(actor.weapon);
474 if(weapon_prepareattack(actor, false, WEP_CVAR_PRI(electro, refire)))
476 W_Electro_Attack_Bolt(thiswep);
477 weapon_thinkf(actor, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
482 if(time >= actor.electro_secondarytime)
483 if(weapon_prepareattack(actor, true, WEP_CVAR_SEC(electro, refire)))
485 W_Electro_Attack_Orb(thiswep);
486 actor.electro_count = WEP_CVAR_SEC(electro, count);
487 weapon_thinkf(actor, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
488 actor.electro_secondarytime = time + WEP_CVAR_SEC(electro, refire2) * W_WeaponRateFactor();
492 METHOD(Electro, wr_init, void(entity thiswep))
494 ELECTRO_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
496 METHOD(Electro, wr_checkammo1, bool(entity thiswep))
498 float ammo_amount = self.WEP_AMMO(ELECTRO) >= WEP_CVAR_PRI(electro, ammo);
499 ammo_amount += self.(weapon_load[WEP_ELECTRO.m_id]) >= WEP_CVAR_PRI(electro, ammo);
502 METHOD(Electro, wr_checkammo2, bool(entity thiswep))
505 if(WEP_CVAR(electro, combo_safeammocheck)) // true if you can fire at least one secondary blob AND one primary shot after it, otherwise false.
507 ammo_amount = self.WEP_AMMO(ELECTRO) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
508 ammo_amount += self.(weapon_load[WEP_ELECTRO.m_id]) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
512 ammo_amount = self.WEP_AMMO(ELECTRO) >= WEP_CVAR_SEC(electro, ammo);
513 ammo_amount += self.(weapon_load[WEP_ELECTRO.m_id]) >= WEP_CVAR_SEC(electro, ammo);
517 METHOD(Electro, wr_config, void(entity thiswep))
519 ELECTRO_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
521 METHOD(Electro, wr_resetplayer, void(entity thiswep))
523 self.electro_secondarytime = time;
525 METHOD(Electro, wr_reload, void(entity thiswep))
527 W_Reload(self, min(WEP_CVAR_PRI(electro, ammo), WEP_CVAR_SEC(electro, ammo)), SND(RELOAD));
529 METHOD(Electro, wr_suicidemessage, int(entity thiswep))
531 if(w_deathtype & HITTYPE_SECONDARY)
532 return WEAPON_ELECTRO_SUICIDE_ORBS;
534 return WEAPON_ELECTRO_SUICIDE_BOLT;
536 METHOD(Electro, wr_killmessage, int(entity thiswep))
538 if(w_deathtype & HITTYPE_SECONDARY)
540 return WEAPON_ELECTRO_MURDER_ORBS;
544 if(w_deathtype & HITTYPE_BOUNCE)
545 return WEAPON_ELECTRO_MURDER_COMBO;
547 return WEAPON_ELECTRO_MURDER_BOLT;
554 METHOD(Electro, wr_impacteffect, void(entity thiswep))
557 org2 = w_org + w_backoff * 6;
558 if(w_deathtype & HITTYPE_SECONDARY)
560 pointparticles(particleeffectnum(EFFECT_ELECTRO_BALLEXPLODE), org2, '0 0 0', 1);
562 sound(self, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);
566 if(w_deathtype & HITTYPE_BOUNCE)
568 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
569 pointparticles(particleeffectnum(EFFECT_ELECTRO_COMBO), org2, '0 0 0', 1);
571 sound(self, CH_SHOTS, SND_ELECTRO_IMPACT_COMBO, VOL_BASE, ATTEN_NORM);
575 pointparticles(particleeffectnum(EFFECT_ELECTRO_IMPACT), org2, '0 0 0', 1);
577 sound(self, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);