Xonotic
tesla_weapon.qc
Go to the documentation of this file.
1 #include "tesla_weapon.qh"
2 
3 #ifdef SVQC
4 
5 entity toast(entity actor, entity from, float range, float damage);
6 SOUND(TeslaCoilTurretAttack_FIRE, W_Sound("electro_fire"));
7 METHOD(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, WEP_CVAR_PRI(electro, refire))) {
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, WEP_CVAR_PRI(electro, animtime), 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 
51 entity 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  Damage(etarget, actor, actor, damage, DEATH_TURRET_TESLA.m_id, DMG_NOWEP, etarget.origin, '0 0 0');
77  etarget.railgunhit = true;
78  IL_PUSH(g_railgunhit, etarget);
79  }
80 
81  return etarget;
82 }
83 
84 #endif
#define WEP_CVAR_PRI(wepname, name)
Definition: all.qh:300
#define IL_EACH(this, cond, body)
#define IL_CLEAR(this)
Remove all elements.
vector w_shotorg
Definition: tracing.qh:18
IntrusiveList g_railgunhit
Definition: tracing.qh:84
entity() spawn
void w_ready(Weapon thiswep, entity actor,.entity weaponentity, int fire)
vector w_shotdir
Definition: tracing.qh:19
string W_Sound(string w_snd)
Definition: all.qc:281
#define METHOD(cname, name, prototype)
Definition: oo.qh:257
#define DMG_NOWEP
Definition: damage.qh:126
const int TFL_TARGETSELECT_PLAYERS
Definition: turret.qh:65
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
bool weapon_prepareattack(Weapon thiswep, entity actor,.entity weaponentity, bool secondary, float attacktime)
#define NULL
Definition: post.qh:17
void Damage(entity targ, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector force)
Definition: damage.qc:583
#define W_SetupShot_Dir(ent, wepent, s_forward, antilag, recoil, snd, chan, maxdamage, deathtype)
Definition: tracing.qh:31
const int TFL_TARGETSELECT_TEAMCHECK
Definition: turret.qh:70
void weapon_thinkf(entity actor,.entity weaponentity, WFRAME fr, float t, void(Weapon thiswep, entity actor,.entity weaponentity, int fire) func)
const int TFL_TARGETSELECT_MISSILES
Definition: turret.qh:66
setorigin(ent, v)
#define SOUND(name, path)
Definition: all.qh:30
float time
Definition: csprogsdefs.qc:16
const int CH_WEAPON_B
Definition: sound.qh:8
#define IS_PLAYER(v)
Definition: utils.qh:9
const int TFL_TARGETSELECT_RANGELIMITS
Definition: turret.qh:69
vector v_forward
Definition: csprogsdefs.qc:31