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