]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/turrets/turret/phaser.qc
Turrets: make plasma turrets use weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / turret / phaser.qc
1 #ifndef TUR_PHASER_H
2 #define TUR_PHASER_H
3
4 CLASS(PhaserTurret, Turret)
5 /* spawnflags */ ATTRIB(PhaserTurret, spawnflags, int, TUR_FLAG_SNIPER | TUR_FLAG_HITSCAN | TUR_FLAG_PLAYER);
6 /* mins       */ ATTRIB(PhaserTurret, mins, vector, '-32 -32 0');
7 /* maxs       */ ATTRIB(PhaserTurret, maxs, vector, '32 32 64');
8 /* modelname  */ ATTRIB(PhaserTurret, mdl, string, "base.md3");
9 /* model      */ ATTRIB(PhaserTurret, model, string, strzone(strcat("models/turrets/", this.mdl)));
10 /* head_model */ ATTRIB(PhaserTurret, head_model, string, strzone(strcat("models/turrets/", "phaser.md3")));
11 /* netname    */ ATTRIB(PhaserTurret, netname, string, "phaser");
12 /* fullname   */ ATTRIB(PhaserTurret, turret_name, string, _("Phaser Cannon"));
13 ENDCLASS(PhaserTurret)
14
15 REGISTER_TURRET(PHASER, NEW(PhaserTurret));
16
17 #endif
18
19 #ifdef IMPLEMENTATION
20 #ifdef SVQC
21 .float fireflag;
22
23 float turret_phaser_firecheck()
24 {SELFPARAM();
25     if (self.fireflag != 0) return 0;
26     return turret_firecheck();
27 }
28
29 void beam_think()
30 {SELFPARAM();
31     if ((time > self.cnt) || (self.owner.deadflag != DEAD_NO))
32     {
33         self.owner.attack_finished_single = time + self.owner.shot_refire;
34         self.owner.fireflag = 2;
35         self.owner.tur_head.frame = 10;
36         sound (self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
37         remove(self);
38         return;
39     }
40
41     turret_do_updates(self.owner);
42
43     if (time - self.shot_spread > 0)
44     {
45         self.shot_spread = time + 2;
46         sound (self, CH_SHOTS_SINGLE, SND_TUR_PHASER, VOL_BASE, ATTEN_NORM);
47     }
48
49
50     self.nextthink = time + self.ticrate;
51
52     self.owner.attack_finished_single = time + frametime;
53     setself(self.owner);
54     FireImoBeam (   self.tur_shotorg,
55                     self.tur_shotorg + self.tur_shotdir_updated * self.target_range,
56                     '-1 -1 -1' * self.shot_radius,
57                     '1 1 1' * self.shot_radius,
58                     self.shot_force,
59                     this.shot_dmg,
60                     0.75,
61                     DEATH_TURRET_PHASER);
62     setself(this);
63     self.scale = vlen(self.owner.tur_shotorg - trace_endpos) / 256;
64
65 }
66
67 void spawnfunc_turret_phaser() { SELFPARAM(); if(!turret_initialize(TUR_PHASER.m_id)) remove(self); }
68
69         METHOD(PhaserTurret, tr_attack, void(PhaserTurret thistur))
70         {
71             entity beam;
72
73             beam = spawn();
74             beam.ticrate = 0.1; //autocvar_sys_ticrate;
75             setmodel(beam, MDL_TUR_PHASER_BEAM);
76             beam.effects = EF_LOWPRECISION;
77             beam.solid = SOLID_NOT;
78             beam.think = beam_think;
79             beam.cnt = time + self.shot_speed;
80             beam.shot_spread = time + 2;
81             beam.nextthink = time;
82             beam.owner = self;
83             beam.shot_dmg = self.shot_dmg / (self.shot_speed / beam.ticrate);
84             beam.scale = self.target_range / 256;
85             beam.movetype = MOVETYPE_NONE;
86             beam.enemy = self.enemy;
87             beam.bot_dodge = true;
88             beam.bot_dodgerating = beam.shot_dmg;
89             sound (beam, CH_SHOTS_SINGLE, SND_TUR_PHASER, VOL_BASE, ATTEN_NORM);
90             self.fireflag = 1;
91
92             beam.attack_finished_single = self.attack_finished_single;
93             self.attack_finished_single = time; // + autocvar_sys_ticrate;
94
95             setattachment(beam,self.tur_head,"tag_fire");
96
97             soundat (self, trace_endpos, CH_SHOTS, SND(NEXIMPACT), VOL_BASE, ATTEN_NORM);
98
99             if (self.tur_head.frame == 0)
100                 self.tur_head.frame = 1;
101         }
102         METHOD(PhaserTurret, tr_think, bool(PhaserTurret thistur))
103         {
104             if (self.tur_head.frame != 0)
105             {
106                 if (self.fireflag == 1)
107                 {
108                     if (self.tur_head.frame == 10)
109                         self.tur_head.frame = 1;
110                     else
111                         self.tur_head.frame = self.tur_head.frame +1;
112                 }
113                 else if (self.fireflag == 2 )
114                 {
115                     self.tur_head.frame = self.tur_head.frame +1;
116                     if (self.tur_head.frame == 15)
117                     {
118                         self.tur_head.frame = 0;
119                         self.fireflag = 0;
120                     }
121                 }
122             }
123
124             return true;
125         }
126         METHOD(PhaserTurret, tr_death, bool(PhaserTurret thistur))
127         {
128             return true;
129         }
130         METHOD(PhaserTurret, tr_setup, bool(PhaserTurret thistur))
131         {
132             self.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE;
133             self.aim_flags = TFL_AIM_LEAD;
134
135             self.turret_firecheckfunc = turret_phaser_firecheck;
136
137             return true;
138         }
139         METHOD(PhaserTurret, tr_precache, bool(PhaserTurret thistur))
140         {
141             return true;
142         }
143
144 #endif // SVQC
145 #ifdef CSQC
146         METHOD(PhaserTurret, tr_setup, bool(PhaserTurret thistur))
147         {
148             return true;
149         }
150         METHOD(PhaserTurret, tr_precache, bool(PhaserTurret thistur))
151         {
152             return true;
153         }
154
155 #endif // CSQC
156 #endif // REGISTER_TURRET