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 bool isPlayer = IS_PLAYER(actor);
9 if (fire & 1)
10 if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, 1)) {
11 if (isPlayer) {
12 turret_initparams(actor);
13 W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_TeslaCoilTurretAttack_FIRE, CH_WEAPON_B, 0, DEATH_TURRET_TESLA.m_id);
14 actor.tur_shotdir_updated = w_shotdir;
15 actor.tur_shotorg = w_shotorg;
16 actor.tur_head = actor;
17 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0.5, w_ready);
18 }
19
20 float d = actor.shot_dmg;
21 float r = actor.target_range;
22 entity e = spawn();
23 setorigin(e, actor.tur_shotorg);
24
26
27 entity t = toast(actor, e,r,d);
28 delete(e);
29
30 if (t == NULL) return;
31
33
34 actor.attack_finished_single[0] = time + actor.shot_refire;
35 for (int i = 0; i < 10; ++i) {
36 d *= 0.75;
37 r *= 0.85;
38 t = toast(actor, t, r, d);
39 if (t == NULL) break;
40
41 }
42
43 IL_EACH(g_railgunhit, it.railgunhit,
44 {
45 it.railgunhit = false;
46 });
48 }
49}
50
51entity toast(entity actor, entity from, float range, float damage)
52{
53 float dd = range + 1;
54 entity etarget = NULL;
55 FOREACH_ENTITY_RADIUS(from.origin, range, it != from && !it.railgunhit,
56 {
57 float r = turret_validate_target(actor, it, actor.target_validate_flags);
58 if(r > 0)
59 {
60 traceline(from.origin, 0.5 * (it.absmin + it.absmax), MOVE_WORLDONLY, from);
61 if(trace_fraction == 1.0)
62 {
63 float d = vlen(it.origin - from.origin);
64 if(d < dd)
65 {
66 dd = d;
67 etarget = it;
68 }
69 }
70 }
71 });
72
73 if (etarget)
74 {
75 te_csqc_lightningarc(from.origin, etarget.origin);
76 if (etarget != actor.realowner)
77 Damage(etarget, actor, actor, damage, DEATH_TURRET_TESLA.m_id, DMG_NOWEP, etarget.origin, '0 0 0');
78 etarget.railgunhit = true;
79 IL_PUSH(g_railgunhit, etarget);
80 }
81
82 return etarget;
83}
84
85#endif
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define IS_PLAYER(s)
Definition player.qh:243
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:503
#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:225
#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:85
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
Definition turret.qh:87
const int TFL_TARGETSELECT_PLAYERS
Definition turret.qh:82
const int TFL_TARGETSELECT_RANGELIMITS
Definition turret.qh:86
const int TFL_TARGETSELECT_MISSILES
Definition turret.qh:83
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)