4 /* ammotype */ ATTRIB(Electro, ammo_field, .int, ammo_cells);
5 /* impulse */ ATTRIB(Electro, impulse, int, 5);
6 /* flags */ ATTRIB(Electro, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH);
7 /* rating */ ATTRIB(Electro, bot_pickupbasevalue, float, 5000);
8 /* color */ ATTRIB(Electro, wpcolor, vector, '0 0.5 1');
9 /* modelname */ ATTRIB(Electro, mdl, string, "electro");
11 /* model */ ATTRIB(Electro, m_model, Model, MDL_ELECTRO_ITEM);
13 /* crosshair */ ATTRIB(Electro, w_crosshair, string, "gfx/crosshairelectro");
14 /* crosshair */ ATTRIB(Electro, w_crosshair_size, float, 0.6);
15 /* wepimg */ ATTRIB(Electro, model2, string, "weaponelectro");
16 /* refname */ ATTRIB(Electro, netname, string, "electro");
17 /* wepname */ ATTRIB(Electro, m_name, string, _("Electro"));
19 #define X(BEGIN, P, END, class, prefix) \
21 P(class, prefix, ammo, float, BOTH) \
22 P(class, prefix, animtime, float, BOTH) \
23 P(class, prefix, bouncefactor, float, SEC) \
24 P(class, prefix, bouncestop, float, SEC) \
25 P(class, prefix, comboradius, float, PRI) \
26 P(class, prefix, combo_comboradius, float, NONE) \
27 P(class, prefix, combo_comboradius_thruwall, float, NONE) \
28 P(class, prefix, combo_damage, float, NONE) \
29 P(class, prefix, combo_edgedamage, float, NONE) \
30 P(class, prefix, combo_force, float, NONE) \
31 P(class, prefix, combo_radius, float, NONE) \
32 P(class, prefix, combo_safeammocheck, float, NONE) \
33 P(class, prefix, combo_speed, float, NONE) \
34 P(class, prefix, count, float, SEC) \
35 P(class, prefix, damagedbycontents, float, SEC) \
36 P(class, prefix, damageforcescale, float, SEC) \
37 P(class, prefix, damage, float, BOTH) \
38 P(class, prefix, edgedamage, float, BOTH) \
39 P(class, prefix, force, float, BOTH) \
40 P(class, prefix, health, float, SEC) \
41 P(class, prefix, lifetime, float, BOTH) \
42 P(class, prefix, midaircombo_explode, float, PRI) \
43 P(class, prefix, midaircombo_interval, float, PRI) \
44 P(class, prefix, midaircombo_radius, float, PRI) \
45 P(class, prefix, radius, float, BOTH) \
46 P(class, prefix, refire2, float, SEC) \
47 P(class, prefix, refire, float, BOTH) \
48 P(class, prefix, reload_ammo, float, NONE) \
49 P(class, prefix, reload_time, float, NONE) \
50 P(class, prefix, speed, float, BOTH) \
51 P(class, prefix, speed_up, float, SEC) \
52 P(class, prefix, speed_z, float, SEC) \
53 P(class, prefix, spread, float, BOTH) \
54 P(class, prefix, stick, float, SEC) \
55 P(class, prefix, switchdelay_drop, float, NONE) \
56 P(class, prefix, switchdelay_raise, float, NONE) \
57 P(class, prefix, touchexplode, float, SEC) \
58 P(class, prefix, weaponreplace, string,NONE) \
59 P(class, prefix, weaponstartoverride, float, NONE) \
60 P(class, prefix, weaponstart, float, NONE) \
61 P(class, prefix, weaponthrowable, float, NONE) \
63 W_PROPS(X, Electro, electro)
67 REGISTER_WEAPON(ELECTRO, electro, NEW(Electro));
72 .float electro_secondarytime;
73 void W_Electro_ExplodeCombo(entity this);
78 spawnfunc(weapon_electro) { weapon_defaultspawnfunc(this, WEP_ELECTRO); }
80 void W_Electro_TriggerCombo(vector org, float rad, entity own)
82 entity e = WarpZone_FindRadius(org, rad, !WEP_CVAR(electro, combo_comboradius_thruwall));
85 if(e.classname == "electro_orb")
87 // do we allow thruwall triggering?
88 if(WEP_CVAR(electro, combo_comboradius_thruwall))
90 // if distance is greater than thruwall distance, check to make sure it's not through a wall
91 if(vdist(e.WarpZone_findradius_dist, >, WEP_CVAR(electro, combo_comboradius_thruwall)))
93 WarpZone_TraceLine(org, e.origin, MOVE_NOMONSTERS, e);
94 if(trace_fraction != 1)
96 // trigger is through a wall and outside of thruwall range, abort
103 // change owner to whoever caused the combo explosion
105 e.takedamage = DAMAGE_NO;
106 e.classname = "electro_orb_chain";
108 // now set the next one to trigger as well
109 setthink(e, W_Electro_ExplodeCombo);
111 // delay combo chains, looks cooler
116 (WEP_CVAR(electro, combo_speed) ?
117 (vlen(e.WarpZone_findradius_dist) / WEP_CVAR(electro, combo_speed))
127 void W_Electro_ExplodeCombo(entity this)
129 W_Electro_TriggerCombo(this.origin, WEP_CVAR(electro, combo_comboradius), this.realowner);
131 this.event_damage = func_null;
136 WEP_CVAR(electro, combo_damage),
137 WEP_CVAR(electro, combo_edgedamage),
138 WEP_CVAR(electro, combo_radius),
141 WEP_CVAR(electro, combo_force),
142 WEP_ELECTRO.m_id | HITTYPE_BOUNCE, // use THIS type for a combo because primary can't bounce
149 void W_Electro_Explode(entity this, entity directhitentity)
151 if(directhitentity.takedamage == DAMAGE_AIM)
152 if(IS_PLAYER(directhitentity))
153 if(DIFF_TEAM(this.realowner, directhitentity))
154 if(!IS_DEAD(directhitentity))
155 if(IsFlying(directhitentity))
156 Send_Notification(NOTIF_ONE, this.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_ELECTROBITCH);
158 this.event_damage = func_null;
159 this.takedamage = DAMAGE_NO;
161 if(this.move_movetype == MOVETYPE_BOUNCE || this.classname == "electro_orb") // TODO: classname is more reliable anyway?
166 WEP_CVAR_SEC(electro, damage),
167 WEP_CVAR_SEC(electro, edgedamage),
168 WEP_CVAR_SEC(electro, radius),
171 WEP_CVAR_SEC(electro, force),
172 this.projectiledeathtype,
178 W_Electro_TriggerCombo(this.origin, WEP_CVAR_PRI(electro, comboradius), this.realowner);
182 WEP_CVAR_PRI(electro, damage),
183 WEP_CVAR_PRI(electro, edgedamage),
184 WEP_CVAR_PRI(electro, radius),
187 WEP_CVAR_PRI(electro, force),
188 this.projectiledeathtype,
196 void W_Electro_Explode_use(entity this, entity actor, entity trigger)
198 W_Electro_Explode(this, trigger);
201 void W_Electro_TouchExplode(entity this, entity toucher)
203 PROJECTILE_TOUCH(this, toucher);
204 W_Electro_Explode(this, toucher);
208 void sys_phys_update_single(entity this);
210 void W_Electro_Bolt_Think(entity this)
212 // sys_phys_update_single(this);
213 if(time >= this.ltime)
215 this.use(this, NULL, NULL);
219 if(WEP_CVAR_PRI(electro, midaircombo_radius))
222 entity e = WarpZone_FindRadius(this.origin, WEP_CVAR_PRI(electro, midaircombo_radius), true);
224 // loop through nearby orbs and trigger them
227 if(e.classname == "electro_orb")
229 // change owner to whoever caused the combo explosion
230 e.realowner = this.realowner;
231 e.takedamage = DAMAGE_NO;
232 e.classname = "electro_orb_chain";
234 // now set the next one to trigger as well
235 setthink(e, W_Electro_ExplodeCombo);
237 // delay combo chains, looks cooler
242 (WEP_CVAR(electro, combo_speed) ?
243 (vlen(e.WarpZone_findradius_dist) / WEP_CVAR(electro, combo_speed))
254 // if we triggered an orb, should we explode? if not, lets try again next time
255 if(found && WEP_CVAR_PRI(electro, midaircombo_explode))
256 { this.use(this, NULL, NULL); }
258 { this.nextthink = min(time + WEP_CVAR_PRI(electro, midaircombo_interval), this.ltime); }
260 else { this.nextthink = this.ltime; }
261 // this.nextthink = time;
264 void W_Electro_Attack_Bolt(Weapon thiswep, entity actor, .entity weaponentity)
268 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(electro, ammo), weaponentity);
270 W_SetupShot_ProjectileSize(
279 WEP_CVAR_PRI(electro, damage)
282 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
284 proj = new(electro_bolt);
285 proj.owner = proj.realowner = actor;
286 proj.bot_dodge = true;
287 proj.bot_dodgerating = WEP_CVAR_PRI(electro, damage);
288 proj.use = W_Electro_Explode_use;
289 setthink(proj, W_Electro_Bolt_Think);
290 proj.nextthink = time;
291 proj.ltime = time + WEP_CVAR_PRI(electro, lifetime);
292 PROJECTILE_MAKETRIGGER(proj);
293 proj.projectiledeathtype = WEP_ELECTRO.m_id;
294 setorigin(proj, w_shotorg);
297 set_movetype(proj, MOVETYPE_FLY);
298 W_SetupProjVelocity_PRI(proj, electro);
299 proj.angles = vectoangles(proj.velocity);
300 settouch(proj, W_Electro_TouchExplode);
301 setsize(proj, '0 0 -3', '0 0 -3');
302 proj.flags = FL_PROJECTILE;
303 IL_PUSH(g_projectiles, proj);
304 IL_PUSH(g_bot_dodge, proj);
305 proj.missile_flags = MIF_SPLASH;
307 CSQCProjectile(proj, true, PROJECTILE_ELECTRO_BEAM, true);
309 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
310 // proj.com_phys_pos = proj.origin;
311 // proj.com_phys_vel = proj.velocity;
314 void W_Electro_Orb_Stick(entity this, entity to)
316 entity newproj = spawn();
317 newproj.classname = this.classname;
319 newproj.bot_dodge = this.bot_dodge;
320 newproj.bot_dodgerating = this.bot_dodgerating;
322 newproj.owner = this.owner;
323 newproj.realowner = this.realowner;
324 setsize(newproj, this.mins, this.maxs);
325 setorigin(newproj, this.origin);
326 setmodel(newproj, MDL_PROJECTILE_ELECTRO);
327 newproj.angles = vectoangles(-trace_plane_normal); // face against the surface
329 newproj.takedamage = this.takedamage;
330 newproj.damageforcescale = this.damageforcescale;
331 newproj.health = this.health;
332 newproj.event_damage = this.event_damage;
333 newproj.spawnshieldtime = this.spawnshieldtime;
334 newproj.damagedbycontents = true;
335 IL_PUSH(g_damagedbycontents, newproj);
337 set_movetype(newproj, MOVETYPE_NONE); // lock the orb in place
338 newproj.projectiledeathtype = this.projectiledeathtype;
340 settouch(newproj, func_null);
341 setthink(newproj, getthink(this));
342 newproj.nextthink = this.nextthink;
343 newproj.use = this.use;
344 newproj.flags = this.flags;
345 IL_PUSH(g_projectiles, newproj);
346 IL_PUSH(g_bot_dodge, newproj);
351 SetMovetypeFollow(this, to);
354 void W_Electro_Orb_Touch(entity this, entity toucher)
356 PROJECTILE_TOUCH(this, toucher);
357 if(toucher.takedamage == DAMAGE_AIM)
358 { if(WEP_CVAR_SEC(electro, touchexplode)) { W_Electro_Explode(this, toucher); } }
361 //UpdateCSQCProjectile(this);
362 spamsound(this, CH_SHOTS, SND_ELECTRO_BOUNCE, VOL_BASE, ATTEN_NORM);
363 this.projectiledeathtype |= HITTYPE_BOUNCE;
365 if(WEP_CVAR_SEC(electro, stick))
366 W_Electro_Orb_Stick(this, toucher);
370 void W_Electro_Orb_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
375 // note: combos are usually triggered by W_Electro_TriggerCombo, not damage
376 float is_combo = (inflictor.classname == "electro_orb_chain" || inflictor.classname == "electro_bolt");
378 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, (is_combo ? 1 : -1)))
379 return; // g_projectiles_damage says to halt
381 this.health = this.health - damage;
384 this.takedamage = DAMAGE_NO;
385 this.nextthink = time;
388 // change owner to whoever caused the combo explosion
389 this.realowner = inflictor.realowner;
390 this.classname = "electro_orb_chain";
391 setthink(this, W_Electro_ExplodeCombo);
392 this.nextthink = time +
394 // bound the length, inflictor may be in a galaxy far far away (warpzones)
396 WEP_CVAR(electro, combo_radius),
397 vlen(this.origin - inflictor.origin)
400 // delay combo chains, looks cooler
401 WEP_CVAR(electro, combo_speed)
406 this.use = W_Electro_Explode_use;
407 setthink(this, adaptor_think2use); // not _hittype_splash, as this runs "immediately"
412 void W_Electro_Attack_Orb(Weapon thiswep, entity actor, .entity weaponentity)
414 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(electro, ammo), weaponentity);
416 W_SetupShot_ProjectileSize(
425 WEP_CVAR_SEC(electro, damage)
428 w_shotdir = v_forward; // no TrueAim for grenades please
430 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
432 entity proj = new(electro_orb);
433 proj.owner = proj.realowner = actor;
434 proj.use = W_Electro_Explode_use;
435 setthink(proj, adaptor_think2use_hittype_splash);
436 proj.bot_dodge = true;
437 proj.bot_dodgerating = WEP_CVAR_SEC(electro, damage);
438 proj.nextthink = time + WEP_CVAR_SEC(electro, lifetime);
439 PROJECTILE_MAKETRIGGER(proj);
440 proj.projectiledeathtype = WEP_ELECTRO.m_id | HITTYPE_SECONDARY;
441 setorigin(proj, w_shotorg);
443 //proj.glow_size = 50;
444 //proj.glow_color = 45;
445 set_movetype(proj, MOVETYPE_BOUNCE);
446 W_SetupProjVelocity_UP_SEC(proj, electro);
447 settouch(proj, W_Electro_Orb_Touch);
448 setsize(proj, '-4 -4 -4', '4 4 4');
449 proj.takedamage = DAMAGE_YES;
450 proj.damageforcescale = WEP_CVAR_SEC(electro, damageforcescale);
451 proj.health = WEP_CVAR_SEC(electro, health);
452 proj.event_damage = W_Electro_Orb_Damage;
453 proj.flags = FL_PROJECTILE;
454 IL_PUSH(g_projectiles, proj);
455 IL_PUSH(g_bot_dodge, proj);
456 proj.damagedbycontents = (WEP_CVAR_SEC(electro, damagedbycontents));
457 if(proj.damagedbycontents)
458 IL_PUSH(g_damagedbycontents, proj);
460 proj.bouncefactor = WEP_CVAR_SEC(electro, bouncefactor);
461 proj.bouncestop = WEP_CVAR_SEC(electro, bouncestop);
462 proj.missile_flags = MIF_SPLASH | MIF_ARC;
467 copyentity(proj, p2);
468 setmodel(p2, MDL_PROJECTILE_ELECTRO);
469 setsize(p2, proj.mins, proj.maxs);
472 CSQCProjectile(proj, true, PROJECTILE_ELECTRO, false); // no culling, it has sound
474 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
477 void W_Electro_CheckAttack(Weapon thiswep, entity actor, .entity weaponentity, int fire)
479 if(actor.(weaponentity).electro_count > 1)
480 if(PHYS_INPUT_BUTTON_ATCK2(actor))
481 if(weapon_prepareattack(thiswep, actor, weaponentity, true, -1))
483 W_Electro_Attack_Orb(WEP_ELECTRO, actor, weaponentity);
484 actor.(weaponentity).electro_count -= 1;
485 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
488 // WEAPONTODO: when the player releases the button, cut down the length of refire2?
489 w_ready(thiswep, actor, weaponentity, fire);
492 .float bot_secondary_electromooth;
494 METHOD(Electro, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
496 PHYS_INPUT_BUTTON_ATCK(actor) = PHYS_INPUT_BUTTON_ATCK2(actor) = false;
497 if(vdist(actor.origin - actor.enemy.origin, >, 1000)) { actor.bot_secondary_electromooth = 0; }
498 if(actor.bot_secondary_electromooth == 0)
502 if(WEP_CVAR_PRI(electro, speed))
503 shoot = bot_aim(actor, weaponentity, WEP_CVAR_PRI(electro, speed), 0, WEP_CVAR_PRI(electro, lifetime), false);
505 shoot = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
509 PHYS_INPUT_BUTTON_ATCK(actor) = true;
510 if(random() < 0.01) actor.bot_secondary_electromooth = 1;
515 if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(electro, speed), WEP_CVAR_SEC(electro, speed_up), WEP_CVAR_SEC(electro, lifetime), true))
517 PHYS_INPUT_BUTTON_ATCK2(actor) = true;
518 if(random() < 0.03) actor.bot_secondary_electromooth = 0;
522 METHOD(Electro, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
524 if(autocvar_g_balance_electro_reload_ammo) // forced reload // WEAPONTODO
526 float ammo_amount = 0;
527 if(actor.(weaponentity).clip_load >= WEP_CVAR_PRI(electro, ammo))
529 if(actor.(weaponentity).clip_load >= WEP_CVAR_SEC(electro, ammo))
534 thiswep.wr_reload(thiswep, actor, weaponentity);
541 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire)))
543 W_Electro_Attack_Bolt(thiswep, actor, weaponentity);
544 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
549 if(time >= actor.(weaponentity).electro_secondarytime)
550 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(electro, refire)))
552 W_Electro_Attack_Orb(thiswep, actor, weaponentity);
553 actor.(weaponentity).electro_count = WEP_CVAR_SEC(electro, count);
554 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(electro, animtime), W_Electro_CheckAttack);
555 actor.(weaponentity).electro_secondarytime = time + WEP_CVAR_SEC(electro, refire2) * W_WeaponRateFactor(actor);
559 METHOD(Electro, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
561 float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_PRI(electro, ammo);
562 ammo_amount += actor.(weaponentity).(weapon_load[WEP_ELECTRO.m_id]) >= WEP_CVAR_PRI(electro, ammo);
565 METHOD(Electro, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
568 if(WEP_CVAR(electro, combo_safeammocheck)) // true if you can fire at least one secondary blob AND one primary shot after it, otherwise false.
570 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
571 ammo_amount += actor.(weaponentity).(weapon_load[WEP_ELECTRO.m_id]) >= WEP_CVAR_SEC(electro, ammo) + WEP_CVAR_PRI(electro, ammo);
575 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_SEC(electro, ammo);
576 ammo_amount += actor.(weaponentity).(weapon_load[WEP_ELECTRO.m_id]) >= WEP_CVAR_SEC(electro, ammo);
580 METHOD(Electro, wr_resetplayer, void(entity thiswep, entity actor))
582 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
584 .entity weaponentity = weaponentities[slot];
585 actor.(weaponentity).electro_secondarytime = time;
588 METHOD(Electro, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
590 W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(electro, ammo), WEP_CVAR_SEC(electro, ammo)), SND_RELOAD);
592 METHOD(Electro, wr_suicidemessage, Notification(entity thiswep))
594 if(w_deathtype & HITTYPE_SECONDARY)
595 return WEAPON_ELECTRO_SUICIDE_ORBS;
597 return WEAPON_ELECTRO_SUICIDE_BOLT;
599 METHOD(Electro, wr_killmessage, Notification(entity thiswep))
601 if(w_deathtype & HITTYPE_SECONDARY)
603 return WEAPON_ELECTRO_MURDER_ORBS;
607 if(w_deathtype & HITTYPE_BOUNCE)
608 return WEAPON_ELECTRO_MURDER_COMBO;
610 return WEAPON_ELECTRO_MURDER_BOLT;
617 METHOD(Electro, wr_impacteffect, void(entity thiswep, entity actor))
620 org2 = w_org + w_backoff * 6;
621 if(w_deathtype & HITTYPE_SECONDARY)
623 pointparticles(EFFECT_ELECTRO_BALLEXPLODE, org2, '0 0 0', 1);
625 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);
629 if(w_deathtype & HITTYPE_BOUNCE)
631 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
632 pointparticles(EFFECT_ELECTRO_COMBO, org2, '0 0 0', 1);
634 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT_COMBO, VOL_BASE, ATTEN_NORM);
638 pointparticles(EFFECT_ELECTRO_IMPACT, org2, '0 0 0', 1);
640 sound(actor, CH_SHOTS, SND_ELECTRO_IMPACT, VOL_BASE, ATTEN_NORM);