Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
tesla.qc
Go to the documentation of this file.
1#include "tesla.qh"
2
3#ifdef SVQC
4
5spawnfunc(turret_tesla)
6{
7 if (!turret_initialize(this, TUR_TESLA))
8 delete(this);
9}
10
11METHOD(TeslaCoil, tr_think, void(TeslaCoil thistur, entity it))
12{
13 if (!it.active)
14 {
15 it.tur_head.avelocity = '0 0 0';
16 return;
17 }
18
19 if (it.ammo < it.shot_dmg)
20 it.tur_head.avelocity = '0 45 0' * (it.ammo / it.shot_dmg);
21 else
22 {
23 it.tur_head.avelocity = '0 180 0' * (it.ammo / it.shot_dmg);
24
25 if (it.attack_finished_single[0] > time)
26 return;
27
28 float f = it.ammo / it.ammo_max;
29 if (f * f > random() && random() < 0.1)
30 te_csqc_lightningarc(it.tur_shotorg, it.tur_shotorg + (randomvec() * 350));
31 }
32}
33
35METHOD(TeslaCoil, tr_setup, void(TeslaCoil this, entity it))
36{
37 it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES
39
40 it.turret_firecheckfunc = turret_tesla_firecheck;
43
44 it.firecheck_flags = TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_AMMO_OWN;
45 it.shoot_flags = TFL_SHOOT_CUSTOM;
47 it.aim_flags = TFL_AIM_NO;
48 it.track_flags = TFL_TRACK_NO;
49}
50
52{
53 // g_turrets_targetscan_maxdelay forces a target re-scan at least this often
54 bool do_target_scan = false;
55
57 do_target_scan = true;
58
59 // Old target (if any) invalid?
60 if (this.target_validate_time < time
61 && turret_validate_target(this, this.enemy, this.target_validate_flags) <= 0)
62 {
63 this.enemy = NULL;
64 this.target_validate_time = time + 0.5;
65 do_target_scan = true;
66 }
67
68 // But never more often then g_turrets_targetscan_mindelay!
70 do_target_scan = false;
71
72 if (do_target_scan)
73 {
74 this.enemy = turret_select_target(this);
76 }
77
78 if (!turret_firecheck(this))
79 return false;
80
81 return this.enemy != NULL;
82}
83
84#endif // SVQC
85#ifdef MENUQC
86
87METHOD(TeslaCoil, describe, string(TeslaCoil this))
88{
89 TC(TeslaCoil, this);
91 PAR(_("The %s is a turret that electrocutes all who dare come near it, sending powerful high-voltage arcs of lightning to strike its targets."), COLORED_NAME(this));
92 PAR(_("Since the arcs of lightning can jump between nearby targets, it is best to just stay away from the %s."), COLORED_NAME(this));
93 return PAGE_TEXT;
94}
95
96#endif // MENUQC
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define COLORED_NAME(this)
Definition color.qh:195
float time
#define TC(T, sym)
Definition _all.inc:82
void te_csqc_lightningarc(vector from, vector to)
float random(void)
vector randomvec(void)
#define METHOD(cname, name, prototype)
Definition oo.qh:269
#define NULL
Definition post.qh:14
#define spawnfunc(id)
Definition spawnfunc.qh:96
#define PAGE_TEXT
Definition string.qh:642
#define PAR(...)
Adds an individually translatable paragraph to PAGE_TEXT without having to deal with strcat and sprin...
Definition string.qh:648
#define PAGE_TEXT_INIT()
Definition string.qh:641
entity enemy
Definition sv_ctf.qh:153
bool turret_firecheck(entity this)
Preforms pre-fire checks based on the uints firecheck_flags.
entity turret_select_target(entity this)
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 ...
bool turret_initialize(entity this, Turret tur)
float target_validate_time
Definition sv_turrets.qh:40
float autocvar_g_turrets_targetscan_maxdelay
Definition sv_turrets.qh:9
float autocvar_g_turrets_targetscan_mindelay
Definition sv_turrets.qh:10
float target_select_time
Definition sv_turrets.qh:39
bool turret_tesla_firecheck(entity this)
Definition tesla.qc:51
const int TFL_TRACK_NO
don't move head
Definition turret.qh:107
const int TFL_TARGETSELECT_TEAMCHECK
don't attack teammates
Definition turret.qh:88
const int TFL_FIRECHECK_AMMO_OWN
own ammo needs to be larger than damage dealt
Definition turret.qh:121
int target_validate_flags
Definition turret.qh:80
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_FIRECHECK_REFIRE
check single attack finished delays
Definition turret.qh:123
const int TFL_AMMO_ENERGY
uses power
Definition turret.qh:158
const int TFL_AIM_NO
no aiming
Definition turret.qh:98
const int TFL_AMMO_RECHARGE
regenerates ammo
Definition turret.qh:161
const int TFL_AMMO_RECIEVE
can recieve ammo from support units
Definition turret.qh:162
const int TFL_TARGETSELECT_MISSILES
target projectiles
Definition turret.qh:84
const int TFL_SHOOT_CUSTOM
custom attacking
Definition turret.qh:133