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) { if (!turret_initialize(this, TUR_TESLA)) delete(this); }
6
7METHOD(TeslaCoil, tr_think, void(TeslaCoil thistur, entity it))
8{
9 if(!it.active)
10 {
11 it.tur_head.avelocity = '0 0 0';
12 return;
13 }
14
15 if(it.ammo < it.shot_dmg)
16 {
17 it.tur_head.avelocity = '0 45 0' * (it.ammo / it.shot_dmg);
18 }
19 else
20 {
21 it.tur_head.avelocity = '0 180 0' * (it.ammo / it.shot_dmg);
22
23 if(it.attack_finished_single[0] > time)
24 return;
25
26 float f;
27 f = (it.ammo / it.ammo_max);
28 f = f * f;
29 if(f > random())
30 if(random() < 0.1)
31 te_csqc_lightningarc(it.tur_shotorg,it.tur_shotorg + (randomvec() * 350));
32 }
33}
34
36METHOD(TeslaCoil, tr_setup, void(TeslaCoil this, entity it))
37{
38 it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES |
40
41 it.turret_firecheckfunc = turret_tesla_firecheck;
42 it.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES |
44
45 it.firecheck_flags = TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_AMMO_OWN;
46 it.shoot_flags = TFL_SHOOT_CUSTOM;
48 it.aim_flags = TFL_AIM_NO;
49 it.track_flags = TFL_TRACK_NO;
50}
51
53{
54 // g_turrets_targetscan_maxdelay forces a target re-scan at least this often
55 float do_target_scan = 0;
56
58 do_target_scan = 1;
59
60 // Old target (if any) invalid?
61 if(this.target_validate_time < time)
62 if (turret_validate_target(this, this.enemy, this.target_validate_flags) <= 0)
63 {
64 this.enemy = NULL;
65 this.target_validate_time = time + 0.5;
66 do_target_scan = 1;
67 }
68
69 // But never more often then g_turrets_targetscan_mindelay!
71 do_target_scan = 0;
72
73 if(do_target_scan)
74 {
75 this.enemy = turret_select_target(this);
77 }
78
79 if(!turret_firecheck(this))
80 return false;
81
82 if(this.enemy)
83 return true;
84
85 return false;
86}
87
88#endif // SVQC
89#ifdef MENUQC
90
91METHOD(TeslaCoil, describe, string(TeslaCoil this))
92{
93 TC(TeslaCoil, this);
95 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));
96 PAR(_("Since the arcs of lightning can jump between nearby targets, it is best to just stay away from the %s."), COLORED_NAME(this));
97 return PAGE_TEXT;
98}
99
100#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:643
#define PAR(...)
Adds an individually translatable paragraph to PAGE_TEXT without having to deal with strcat and sprin...
Definition string.qh:649
#define PAGE_TEXT_INIT()
Definition string.qh:642
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:52
const int TFL_TRACK_NO
Definition turret.qh:106
const int TFL_TARGETSELECT_TEAMCHECK
Definition turret.qh:87
const int TFL_FIRECHECK_AMMO_OWN
Definition turret.qh:120
int target_validate_flags
Definition turret.qh:79
const int TFL_TARGETSELECT_PLAYERS
Definition turret.qh:82
const int TFL_TARGETSELECT_RANGELIMITS
Definition turret.qh:86
const int TFL_FIRECHECK_REFIRE
Definition turret.qh:122
const int TFL_AMMO_ENERGY
Definition turret.qh:157
const int TFL_AIM_NO
Definition turret.qh:97
const int TFL_AMMO_RECHARGE
Definition turret.qh:160
const int TFL_AMMO_RECIEVE
Definition turret.qh:161
const int TFL_TARGETSELECT_MISSILES
Definition turret.qh:83
const int TFL_SHOOT_CUSTOM
Definition turret.qh:132