]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/turrets/turret/tesla.qc
Monsters, turrets, vehicles: move definitions to headers
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / turret / tesla.qc
1 #include "tesla.qh"
2
3 #ifdef IMPLEMENTATION
4
5 #ifdef SVQC
6
7 spawnfunc(turret_tesla) { if (!turret_initialize(this, TUR_TESLA)) delete(this); }
8
9 METHOD(TeslaCoil, tr_think, void(TeslaCoil thistur, entity it))
10 {
11     if(!it.active)
12     {
13         it.tur_head.avelocity = '0 0 0';
14         return;
15     }
16
17     if(it.ammo < it.shot_dmg)
18     {
19         it.tur_head.avelocity = '0 45 0' * (it.ammo / it.shot_dmg);
20     }
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;
29         f = (it.ammo / it.ammo_max);
30         f = f * f;
31         if(f > random())
32             if(random() < 0.1)
33                 te_csqc_lightningarc(it.tur_shotorg,it.tur_shotorg + (randomvec() * 350));
34     }
35 }
36
37 bool turret_tesla_firecheck(entity this);
38 METHOD(TeslaCoil, tr_setup, void(TeslaCoil this, entity it))
39 {
40     it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES |
41                          TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK;
42
43     it.turret_firecheckfunc = turret_tesla_firecheck;
44     it.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES |
45                        TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK;
46
47     it.firecheck_flags  = TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_AMMO_OWN;
48     it.shoot_flags              = TFL_SHOOT_CUSTOM;
49     it.ammo_flags                       = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE;
50     it.aim_flags                        = TFL_AIM_NO;
51     it.track_flags              = TFL_TRACK_NO;
52 }
53
54 bool turret_tesla_firecheck(entity this)
55 {
56     // g_turrets_targetscan_maxdelay forces a target re-scan at least this often
57     float do_target_scan = 0;
58
59     if((this.target_select_time + autocvar_g_turrets_targetscan_maxdelay) < time)
60         do_target_scan = 1;
61
62     // Old target (if any) invalid?
63     if(this.target_validate_time < time)
64     if (turret_validate_target(this, this.enemy, this.target_validate_flags) <= 0)
65     {
66         this.enemy = NULL;
67         this.target_validate_time = time + 0.5;
68         do_target_scan = 1;
69     }
70
71     // But never more often then g_turrets_targetscan_mindelay!
72     if (this.target_select_time + autocvar_g_turrets_targetscan_mindelay > time)
73         do_target_scan = 0;
74
75     if(do_target_scan)
76     {
77         this.enemy = turret_select_target(this);
78         this.target_select_time = time;
79     }
80
81     if(!turret_firecheck(this))
82         return false;
83
84     if(this.enemy)
85         return true;
86
87     return false;
88 }
89
90 #endif
91 #endif