]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/turrets/turret/tesla.qc
Merge branch 'master' into terencehill/infomessages_panel_update
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / turret / tesla.qc
1 #ifndef TURRET_TESLA_H
2 #define TURRET_TESLA_H
3
4 #include "tesla_weapon.qh"
5
6 CLASS(TeslaCoil, Turret)
7 /* spawnflags */ ATTRIB(TeslaCoil, spawnflags, int, TUR_FLAG_HITSCAN | TUR_FLAG_PLAYER | TUR_FLAG_MISSILE);
8 /* mins       */ ATTRIB(TeslaCoil, mins, vector, '-60 -60 0');
9 /* maxs       */ ATTRIB(TeslaCoil, maxs, vector, '60 60 128');
10 /* modelname  */ ATTRIB(TeslaCoil, mdl, string, "tesla_base.md3");
11 /* model      */ ATTRIB_STRZONE(TeslaCoil, model, string, strcat("models/turrets/", this.mdl));
12 /* head_model */ ATTRIB_STRZONE(TeslaCoil, head_model, string, strcat("models/turrets/", "tesla_head.md3"));
13 /* netname    */ ATTRIB(TeslaCoil, netname, string, "tesla");
14 /* fullname   */ ATTRIB(TeslaCoil, turret_name, string, _("Tesla Coil"));
15     ATTRIB(TeslaCoil, m_weapon, Weapon, WEP_TESLA);
16 ENDCLASS(TeslaCoil)
17 REGISTER_TURRET(TESLA, NEW(TeslaCoil));
18
19 #endif
20
21 #ifdef IMPLEMENTATION
22
23 #ifdef SVQC
24
25 spawnfunc(turret_tesla) { if (!turret_initialize(this, TUR_TESLA)) remove(this); }
26
27 METHOD(TeslaCoil, tr_think, void(TeslaCoil thistur, entity it))
28 {
29     if(!it.active)
30     {
31         it.tur_head.avelocity = '0 0 0';
32         return;
33     }
34
35     if(it.ammo < it.shot_dmg)
36     {
37         it.tur_head.avelocity = '0 45 0' * (it.ammo / it.shot_dmg);
38     }
39     else
40     {
41         it.tur_head.avelocity = '0 180 0' * (it.ammo / it.shot_dmg);
42
43         if(it.attack_finished_single[0] > time)
44             return;
45
46         float f;
47         f = (it.ammo / it.ammo_max);
48         f = f * f;
49         if(f > random())
50             if(random() < 0.1)
51                 te_csqc_lightningarc(it.tur_shotorg,it.tur_shotorg + (randomvec() * 350));
52     }
53 }
54
55 bool turret_tesla_firecheck(entity this);
56 METHOD(TeslaCoil, tr_setup, void(TeslaCoil this, entity it))
57 {
58     it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES |
59                          TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK;
60
61     it.turret_firecheckfunc = turret_tesla_firecheck;
62     it.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES |
63                        TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK;
64
65     it.firecheck_flags  = TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_AMMO_OWN;
66     it.shoot_flags              = TFL_SHOOT_CUSTOM;
67     it.ammo_flags                       = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE;
68     it.aim_flags                        = TFL_AIM_NO;
69     it.track_flags              = TFL_TRACK_NO;
70 }
71
72 bool turret_tesla_firecheck(entity this)
73 {
74     // g_turrets_targetscan_maxdelay forces a target re-scan at least this often
75     float do_target_scan = 0;
76
77     if((this.target_select_time + autocvar_g_turrets_targetscan_maxdelay) < time)
78         do_target_scan = 1;
79
80     // Old target (if any) invalid?
81     if(this.target_validate_time < time)
82     if (turret_validate_target(this, this.enemy, this.target_validate_flags) <= 0)
83     {
84         this.enemy = NULL;
85         this.target_validate_time = time + 0.5;
86         do_target_scan = 1;
87     }
88
89     // But never more often then g_turrets_targetscan_mindelay!
90     if (this.target_select_time + autocvar_g_turrets_targetscan_mindelay > time)
91         do_target_scan = 0;
92
93     if(do_target_scan)
94     {
95         this.enemy = turret_select_target(this);
96         this.target_select_time = time;
97     }
98
99     if(!turret_firecheck(this))
100         return false;
101
102     if(this.enemy)
103         return true;
104
105     return false;
106 }
107
108 #endif
109 #endif