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