]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/turrets/turret/phaser.qc
Turrets: upgrade phaser
[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, bool(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             return true;
103         }
104         METHOD(PhaserTurret, tr_think, bool(PhaserTurret thistur))
105         {
106             if (self.tur_head.frame != 0)
107             {
108                 if (self.fireflag == 1)
109                 {
110                     if (self.tur_head.frame == 10)
111                         self.tur_head.frame = 1;
112                     else
113                         self.tur_head.frame = self.tur_head.frame +1;
114                 }
115                 else if (self.fireflag == 2 )
116                 {
117                     self.tur_head.frame = self.tur_head.frame +1;
118                     if (self.tur_head.frame == 15)
119                     {
120                         self.tur_head.frame = 0;
121                         self.fireflag = 0;
122                     }
123                 }
124             }
125
126             return true;
127         }
128         METHOD(PhaserTurret, tr_death, bool(PhaserTurret thistur))
129         {
130             return true;
131         }
132         METHOD(PhaserTurret, tr_setup, bool(PhaserTurret thistur))
133         {
134             self.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE;
135             self.aim_flags = TFL_AIM_LEAD;
136
137             self.turret_firecheckfunc = turret_phaser_firecheck;
138
139             return true;
140         }
141         METHOD(PhaserTurret, tr_precache, bool(PhaserTurret thistur))
142         {
143             return true;
144         }
145
146 #endif // SVQC
147 #ifdef CSQC
148         METHOD(PhaserTurret, tr_setup, bool(PhaserTurret thistur))
149         {
150             return true;
151         }
152         METHOD(PhaserTurret, tr_precache, bool(PhaserTurret thistur))
153         {
154             return true;
155         }
156
157 #endif // CSQC
158 #endif // REGISTER_TURRET