]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/turrets/turret/hellion.qc
Turrets: cleanup
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / turret / hellion.qc
1 #ifndef TUR_HELLION_H
2 #define TUR_HELLION_H
3 REGISTER_TURRET(
4 /* TUR_##id   */ HELLION,
5 /* function   */ t_hellion,
6 /* spawnflags */ TUR_FLAG_SPLASH | TUR_FLAG_FASTPROJ | TUR_FLAG_PLAYER | TUR_FLAG_MISSILE,
7 /* mins,maxs  */ '-32 -32 0', '32 32 64',
8 /* model          */ "base.md3",
9 /* head_model */ "hellion.md3",
10 /* netname        */ "hellion",
11 /* fullname   */ _("Hellion Missile Turret")
12 );
13 #endif
14
15 #ifdef IMPLEMENTATION
16 #ifdef SVQC
17 float autocvar_g_turrets_unit_hellion_shot_speed_gain;
18 float autocvar_g_turrets_unit_hellion_shot_speed_max;
19
20 void turret_hellion_missile_think()
21 {SELFPARAM();
22     vector olddir,newdir;
23     vector pre_pos;
24     float itime;
25
26     self.nextthink = time + 0.05;
27
28     olddir = normalize(self.velocity);
29
30     if(self.max_health < time)
31         turret_projectile_explode();
32
33     // Enemy dead? just keep on the current heading then.
34     if ((self.enemy == world) || (self.enemy.deadflag != DEAD_NO))
35     {
36
37         // Make sure we dont return to tracking a respawned player
38         self.enemy = world;
39
40         // Turn model
41         self.angles = vectoangles(self.velocity);
42
43         if ( (vlen(self.origin - self.owner.origin)) > (self.owner.shot_radius * 5) )
44             turret_projectile_explode();
45
46         // Accelerate
47         self.velocity = olddir * min(vlen(self.velocity) * (autocvar_g_turrets_unit_hellion_shot_speed_gain), (autocvar_g_turrets_unit_hellion_shot_speed_max));
48
49         UpdateCSQCProjectile(self);
50
51         return;
52     }
53
54     // Enemy in range?
55     if (vlen(self.origin - self.enemy.origin) < self.owner.shot_radius * 0.2)
56         turret_projectile_explode();
57
58     // Predict enemy position
59     itime = vlen(self.enemy.origin - self.origin) / vlen(self.velocity);
60     pre_pos = self.enemy.origin + self.enemy.velocity * itime;
61
62     pre_pos = (pre_pos + self.enemy.origin) * 0.5;
63
64     // Find out the direction to that place
65     newdir = normalize(pre_pos - self.origin);
66
67     // Turn
68     newdir = normalize(olddir + newdir * 0.35);
69
70     // Turn model
71     self.angles = vectoangles(self.velocity);
72
73     // Accelerate
74     self.velocity = newdir * min(vlen(self.velocity) * (autocvar_g_turrets_unit_hellion_shot_speed_gain), (autocvar_g_turrets_unit_hellion_shot_speed_max));
75
76     if (itime < 0.05)
77         self.think = turret_projectile_explode;
78
79     UpdateCSQCProjectile(self);
80 }
81
82 void spawnfunc_turret_hellion() { SELFPARAM(); if(!turret_initialize(TUR_HELLION.m_id)) remove(self); }
83
84 float t_hellion(float req)
85 {SELFPARAM();
86     switch(req)
87     {
88         case TR_ATTACK:
89         {
90             entity missile;
91
92             if(self.tur_head.frame != 0)
93                 self.tur_shotorg = gettaginfo(self.tur_head, gettagindex(self.tur_head, "tag_fire"));
94             else
95                 self.tur_shotorg = gettaginfo(self.tur_head, gettagindex(self.tur_head, "tag_fire2"));
96
97             missile = turret_projectile(SND(ROCKET_FIRE), 6, 10, DEATH_TURRET_HELLION, PROJECTILE_ROCKET, FALSE, FALSE);
98             te_explosion (missile.origin);
99             missile.think               = turret_hellion_missile_think;
100             missile.nextthink   = time;
101             missile.flags               = FL_PROJECTILE;
102             missile.max_health   = time + 9;
103             missile.tur_aimpos   = randomvec() * 128;
104             missile.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_HEAT;
105             self.tur_head.frame += 1;
106
107             return true;
108         }
109         case TR_THINK:
110         {
111             if (self.tur_head.frame != 0)
112                 self.tur_head.frame += 1;
113
114             if (self.tur_head.frame >= 7)
115                 self.tur_head.frame = 0;
116
117             return true;
118         }
119         case TR_DEATH:
120         {
121             return true;
122         }
123         case TR_SETUP:
124         {
125             self.aim_flags = TFL_AIM_SIMPLE;
126             self.target_select_flags = TFL_TARGETSELECT_LOS | TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK ;
127             self.firecheck_flags = TFL_FIRECHECK_DEAD | TFL_FIRECHECK_DISTANCES | TFL_FIRECHECK_TEAMCHECK | TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_AFF | TFL_FIRECHECK_AMMO_OWN;
128             self.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE;
129
130             return true;
131         }
132         case TR_PRECACHE:
133         {
134             return true;
135         }
136     }
137
138     return true;
139 }
140
141 #endif // SVQC
142 #ifdef CSQC
143 float t_hellion(float req)
144 {
145     switch(req)
146     {
147         case TR_SETUP:
148         {
149             return true;
150         }
151         case TR_PRECACHE:
152         {
153             return true;
154         }
155     }
156
157     return true;
158 }
159
160 #endif // CSQC
161 #endif // REGISTER_TURRET