Xonotic
tesla.qc
Go to the documentation of this file.
1 #include "tesla.qh"
2 
3 #ifdef SVQC
4 
5 spawnfunc(turret_tesla) { if (!turret_initialize(this, TUR_TESLA)) delete(this); }
6 
7 METHOD(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 
35 bool turret_tesla_firecheck(entity this);
36 METHOD(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 
52 bool turret_tesla_firecheck(entity this)
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);
76  this.target_select_time = time;
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
entity turret_select_target(entity this)
float turret_validate_target(entity e_turret, entity e_target, float validate_flags)
entity() spawn
int target_validate_flags
Definition: turret.qh:62
float target_validate_time
Definition: sv_turrets.qh:41
const int TFL_FIRECHECK_AMMO_OWN
Definition: turret.qh:103
bool turret_initialize(entity this, Turret tur)
spawnfunc(info_player_attacker)
Definition: sv_assault.qc:283
#define METHOD(cname, name, prototype)
Definition: oo.qh:257
float autocvar_g_turrets_targetscan_maxdelay
Definition: sv_turrets.qh:9
const int TFL_AMMO_RECHARGE
Definition: turret.qh:143
const int TFL_TARGETSELECT_PLAYERS
Definition: turret.qh:65
entity enemy
Definition: sv_ctf.qh:143
float autocvar_g_turrets_targetscan_mindelay
Definition: sv_turrets.qh:10
const int TFL_FIRECHECK_REFIRE
Definition: turret.qh:105
bool turret_firecheck(entity this)
const int TFL_SHOOT_CUSTOM
Definition: turret.qh:115
#define NULL
Definition: post.qh:17
const int TFL_AMMO_RECIEVE
Definition: turret.qh:144
const int TFL_AIM_NO
Definition: turret.qh:80
const int TFL_TARGETSELECT_TEAMCHECK
Definition: turret.qh:70
const int TFL_AMMO_ENERGY
Definition: turret.qh:140
const int TFL_TRACK_NO
Definition: turret.qh:89
const int TFL_TARGETSELECT_MISSILES
Definition: turret.qh:66
float time
Definition: csprogsdefs.qc:16
float target_select_time
Definition: sv_turrets.qh:40
const int TFL_TARGETSELECT_RANGELIMITS
Definition: turret.qh:69