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 turret_tesla_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 = turret_tesla_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) // chain the lightning between max 10 more targets
40 {
41 d *= 0.75;
42 r *= 0.85;
43 t = turret_tesla_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
56{
57 return (e != turret_tesla_toast_cond_from && !e.railgunhit
59}
60entity turret_tesla_toast(entity actor, entity from, float range, float damage)
61{
62 entity closest = NULL;
63 float head_dist2, closest_dist2 = 0;
66 for (entity head = WarpZone_SearchInRadius(from.origin, range, MOVE_NOMONSTERS, turret_tesla_toast_cond); head; head = head.chain)
67 {
68 head_dist2 = vlen2(head.WarpZone_findradius_dist);
69 if (!closest || head_dist2 < closest_dist2) // new closest
70 {
71 closest_dist2 = head_dist2;
72 closest = head;
73 }
74 }
75
76 if (closest)
77 {
79 WarpZone_TraceLine_ThroughZone(from.origin, WarpZone_UnTransformOrigin(closest, closest.WarpZone_findradius_nearest),
81 if (closest != actor.realowner)
82 Damage(closest, actor, actor,
83 damage,
84 DEATH_TURRET_TESLA.m_id,
86 closest.WarpZone_findradius_nearest,
87 '0 0 0'
88 );
89 closest.railgunhit = true;
90 IL_PUSH(g_railgunhit, closest);
91 }
92 return closest;
93}
94
95#endif // SVQC
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define IS_PLAYER(s)
Definition player.qh:242
const float MOVE_NOMONSTERS
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:484
#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.
entity WarpZone_SearchInRadius(vector org, float rad, float nomonsters, WarpZone_FindRadius_cond_callback_t cb)
Modified findradius aware of warpzones, that only includes entities that meet the "cb" criteria.
Definition common.qc:680
vector WarpZone_UnTransformOrigin(entity wz, vector org)
Transforms origin org backwards through warpzone wz, as the inverse of WarpZone_TransformOrigin.
Definition common.qc:526
#define WarpZone_TraceLine_ThroughZone(org, end, nomonsters, forent, zone, cb)
Definition common.qh:47
WarpZone_trace_callback_t te_csqc_trace_callback
Definition common.qh:38
#define MOVE_NOTHING
Definition common.qh:35
var void te_csqc_trace_callback_func(vector start, vector hit)
void te_csqc_lightningarc(vector from, vector to)
#define METHOD(cname, name, prototype)
Definition oo.qh:274
#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
float turret_validate_target(entity e_turret, entity e_target, float validate_flags)
Evaluate a entity for target valitity based on validate_flags NOTE: the caller must check takedamage ...
void turret_initparams(entity tur)
entity turret_tesla_toast_cond_from
bool turret_tesla_toast_cond(entity e)
entity turret_tesla_toast_cond_actor
entity turret_tesla_toast(entity actor, entity from, float range, float damage)
IntrusiveList g_railgunhit
Definition tracing.qh:91
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:91
const int TFL_TARGETSELECT_PLAYERS
target players
Definition turret.qh:86
const int TFL_TARGETSELECT_RANGELIMITS
limit target selection range
Definition turret.qh:90
const int TFL_TARGETSELECT_MISSILES
target projectiles
Definition turret.qh:87
#define vlen2(v)
Definition vector.qh:4
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)