Merge branch 'master' into Mario/turrets
[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 {
18         if (self.fireflag != 0) return 0;
19         return turret_firecheck();
20 }
21
22 void beam_think()
23 {
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, "misc/null.wav", 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, "turrets/phaser.wav", VOL_BASE, ATTEN_NORM);
40         }
41
42
43         self.nextthink = time + self.ticrate;
44
45         self.owner.attack_finished_single = time + frametime;
46         entity oldself;
47         oldself = self;
48         self = self.owner;
49         FireImoBeam (   self.tur_shotorg,
50                                         self.tur_shotorg + self.tur_shotdir_updated * self.target_range,
51                                         '-1 -1 -1' * self.shot_radius,
52                                         '1 1 1' * self.shot_radius,
53                                         self.shot_force,
54                                         oldself.shot_dmg,
55                                         0.75,
56                                         DEATH_TURRET_PHASER);
57         self = oldself;
58         self.scale = vlen(self.owner.tur_shotorg - trace_endpos) / 256;
59
60 }
61
62 void spawnfunc_turret_phaser() { if(!turret_initialize(TUR_PHASER)) remove(self); }
63
64 float t_phaser(float req)
65 {
66         switch(req)
67         {
68                 case TR_ATTACK:
69                 {
70                         entity beam;
71
72                         beam = spawn();
73                         beam.ticrate = 0.1; //autocvar_sys_ticrate;
74                         setmodel(beam,"models/turrets/phaser_beam.md3");
75                         beam.effects = EF_LOWPRECISION;
76                         beam.solid = SOLID_NOT;
77                         beam.think = beam_think;
78                         beam.cnt = time + self.shot_speed;
79                         beam.shot_spread = time + 2;
80                         beam.nextthink = time;
81                         beam.owner = self;
82                         beam.shot_dmg = self.shot_dmg / (self.shot_speed / beam.ticrate);
83                         beam.scale = self.target_range / 256;
84                         beam.movetype = MOVETYPE_NONE;
85                         beam.enemy = self.enemy;
86                         beam.bot_dodge = true;
87                         beam.bot_dodgerating = beam.shot_dmg;
88                         sound (beam, CH_SHOTS_SINGLE, "turrets/phaser.wav", VOL_BASE, ATTEN_NORM);
89                         self.fireflag = 1;
90
91                         beam.attack_finished_single = self.attack_finished_single;
92                         self.attack_finished_single = time; // + autocvar_sys_ticrate;
93
94                         setattachment(beam,self.tur_head,"tag_fire");
95
96                         soundat (self, trace_endpos, CH_SHOTS, "weapons/neximpact.wav", VOL_BASE, ATTEN_NORM);
97
98                         if (self.tur_head.frame == 0)
99                                 self.tur_head.frame = 1;
100
101                         return true;
102                 }
103                 case TR_THINK:
104                 {
105                         if (self.tur_head.frame != 0)
106                         {
107                                 if (self.fireflag == 1)
108                                 {
109                                         if (self.tur_head.frame == 10)
110                                                 self.tur_head.frame = 1;
111                                         else
112                                                 self.tur_head.frame = self.tur_head.frame +1;
113                                 }
114                                 else if (self.fireflag == 2 )
115                                 {
116                                         self.tur_head.frame = self.tur_head.frame +1;
117                                         if (self.tur_head.frame == 15)
118                                         {
119                                                 self.tur_head.frame = 0;
120                                                 self.fireflag = 0;
121                                         }
122                                 }
123                         }
124
125                         return true;
126                 }
127                 case TR_DEATH:
128                 {
129                         return true;
130                 }
131                 case TR_SETUP:
132                 {
133                         self.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE;
134                         self.aim_flags = TFL_AIM_LEAD;
135
136                         self.turret_firecheckfunc = turret_phaser_firecheck;
137
138                         return true;
139                 }
140                 case TR_PRECACHE:
141                 {
142                         precache_model ("models/turrets/base.md3");
143                         precache_model ("models/turrets/phaser.md3");
144                         precache_model ("models/turrets/phaser_beam.md3");
145                         precache_sound ("turrets/phaser.wav");
146                         return true;
147                 }
148         }
149
150         return true;
151 }
152
153 #endif // SVQC
154 #ifdef CSQC
155 float t_phaser(float req)
156 {
157         switch(req)
158         {
159                 case TR_SETUP:
160                 {
161                         return true;
162                 }
163                 case TR_PRECACHE:
164                 {
165                         return true;
166                 }
167         }
168
169         return true;
170 }
171
172 #endif // CSQC
173 #endif // REGISTER_TURRET