Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
tesla_weapon.qc
Go to the documentation of this file.
1#include "tesla_weapon.qh"
2
3#ifdef SVQC
4
5entity toast(entity actor, entity from, float range, float damage);
6SOUND(TeslaCoilTurretAttack_FIRE, W_Sound("electro_fire"));
7METHOD(TeslaCoilTurretAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
8{
9 bool isPlayer = IS_PLAYER(actor);
10 if (fire & 1)
11 if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, 1))
12 {
13 if (isPlayer)
14 {
15 turret_initparams(actor);
16 W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_TeslaCoilTurretAttack_FIRE, CH_WEAPON_B, 0, DEATH_TURRET_TESLA.m_id);
17 actor.tur_shotdir_updated = w_shotdir;
18 actor.tur_shotorg = w_shotorg;
19 actor.tur_head = actor;
20 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0.5, w_ready);
21 }
22
23 float d = actor.shot_dmg;
24 float r = actor.target_range;
25 entity e = spawn();
26 setorigin(e, actor.tur_shotorg);
27
29
30 entity t = toast(actor, e, r, d);
31 delete(e);
32
33 if (t == NULL)
34 return;
35
37
38 actor.attack_finished_single[0] = time + actor.shot_refire;
39 for (int i = 0; i < 10; ++i)
40 {
41 d *= 0.75;
42 r *= 0.85;
43 t = toast(actor, t, r, d);
44 if (t == NULL)
45 break;
46 }
47
48 IL_EACH(g_railgunhit, it.railgunhit, it.railgunhit = false);
50 }
51}
52
53entity toast(entity actor, entity from, float range, float damage)
54{
55 float dd = range + 1;
56 entity etarget = NULL;
57 FOREACH_ENTITY_RADIUS(from.origin, range, it != from && !it.railgunhit,
58 {
59 float r = turret_validate_target(actor, it, actor.target_validate_flags);
60 if (r > 0)
61 {
62 traceline(from.origin, 0.5 * (it.absmin + it.absmax), MOVE_WORLDONLY, from);
63 if (trace_fraction == 1.0)
64 {
65 float d = vlen(it.origin - from.origin);
66 if (d < dd)
67 {
68 dd = d;
69 etarget = it;
70 }
71 }
72 }
73 });
74
75 if (etarget)
76 {
77 te_csqc_lightningarc(from.origin, etarget.origin);
78 if (etarget != actor.realowner)
79 Damage(etarget, actor, actor,
80 damage,
81 DEATH_TURRET_TESLA.m_id,
83 etarget.origin,
84 '0 0 0'
85 );
86 etarget.railgunhit = true;
87 IL_PUSH(g_railgunhit, etarget);
88 }
89
90 return etarget;
91}
92
93#endif // SVQC
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define IS_PLAYER(s)
Definition player.qh:242
float time
vector v_forward
#define spawn
void Damage(entity targ, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector force)
Definition damage.qc:493
#define DMG_NOWEP
Definition damage.qh:104
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
#define IL_EACH(this, cond, body)
#define IL_CLEAR(this)
Remove all elements.
#define FOREACH_ENTITY_RADIUS(org, dist, cond, body)
Definition iter.qh:160
void te_csqc_lightningarc(vector from, vector to)
#define METHOD(cname, name, prototype)
Definition oo.qh:269
#define NULL
Definition post.qh:14
const int CH_WEAPON_B
Definition sound.qh:8
string W_Sound(string w_snd)
Definition all.qc:226
#define SOUND(name, path)
Definition all.qh:30
void turret_initparams(entity tur)
entity toast(entity actor, entity from, float range, float damage)
IntrusiveList g_railgunhit
Definition tracing.qh:89
vector w_shotdir
Definition tracing.qh:20
vector w_shotorg
Definition tracing.qh:19
#define W_SetupShot_Dir(ent, wepent, s_forward, antilag, recoil, snd, chan, maxdamage, deathtype)
Definition tracing.qh:32
const int TFL_TARGETSELECT_TEAMCHECK
don't attack teammates
Definition turret.qh:88
const int TFL_TARGETSELECT_PLAYERS
target players
Definition turret.qh:83
const int TFL_TARGETSELECT_RANGELIMITS
limit target selection range
Definition turret.qh:87
const int TFL_TARGETSELECT_MISSILES
target projectiles
Definition turret.qh:84
void weapon_thinkf(entity actor,.entity weaponentity, WFRAME fr, float t, void(Weapon thiswep, entity actor,.entity weaponentity, int fire) func)
bool weapon_prepareattack(Weapon thiswep, entity actor,.entity weaponentity, bool secondary, float attacktime)
void w_ready(Weapon thiswep, entity actor,.entity weaponentity, int fire)