6 /* spawnflags */ TUR_FLAG_SPLASH | TUR_FLAG_MEDPROJ | TUR_FLAG_PLAYER | TUR_FLAG_RECIEVETARGETS,
7 /* mins,maxs */ '-32 -32 0', '32 32 64',
8 /* model */ "base.md3",
9 /* head_model */ "hk.md3",
11 /* fullname */ _("Hunter-Killer Turret")
17 float autocvar_g_turrets_unit_hk_shot_speed;
18 float autocvar_g_turrets_unit_hk_shot_speed_accel;
19 float autocvar_g_turrets_unit_hk_shot_speed_accel2;
20 float autocvar_g_turrets_unit_hk_shot_speed_decel;
21 float autocvar_g_turrets_unit_hk_shot_speed_max;
22 float autocvar_g_turrets_unit_hk_shot_speed_turnrate;
24 //#define TURRET_DEBUG_HK
26 #ifdef TURRET_DEBUG_HK
30 float hk_is_valid_target(entity e_target)
32 if (e_target == world)
35 // If only this was used more..
36 if (e_target.flags & FL_NOTARGET)
40 if ((e_target.takedamage == DAMAGE_NO) || (e_target.health < 0))
44 if (IS_CLIENT(e_target))
46 if (self.owner.target_select_playerbias < 0)
49 if (e_target.deadflag != DEAD_NO)
54 if ((e_target.flags & FL_PROJECTILE) && (self.owner.target_select_missilebias < 0))
58 if ((e_target.team == self.owner.team) || (self.owner.team == e_target.owner.team))
64 void turret_hk_missile_think()
66 vector vu, vd, vf, vl, vr, ve; // Vector (direction)
67 float fu, fd, ff, fl, fr, fe; // Fraction to solid
68 vector olddir,wishdir,newdir; // Final direction
69 float lt_for; // Length of Trace FORwrad
70 float lt_seek; // Length of Trace SEEK (left, right, up down)
71 float pt_seek; // Pitch of Trace SEEK (How mutch to angele left, right up, down trace towards v_forward)
77 self.nextthink = time + self.ticrate;
79 //if (self.cnt < time)
80 // turret_hk_missile_explode();
82 if (self.enemy.deadflag != DEAD_NO)
85 // Pick the closest valid target.
88 e = findradius(self.origin, 5000);
91 if (hk_is_valid_target(e))
96 if (vlen(self.origin - e.origin) < vlen(self.origin - self.enemy.origin))
103 self.angles = vectoangles(self.velocity);
104 self.angles_x = self.angles_x * -1;
105 makevectors(self.angles);
106 self.angles_x = self.angles_x * -1;
110 edist = vlen(self.origin - self.enemy.origin);
111 // Close enougth to do decent damage?
112 if ( edist <= (self.owner.shot_radius * 0.25) )
114 turret_projectile_explode();
118 // Get data on enemy position
119 pre_pos = self.enemy.origin +
120 self.enemy.velocity *
121 min((vlen(self.enemy.origin - self.origin) / vlen(self.velocity)),0.5);
123 traceline(self.origin, pre_pos,true,self.enemy);
124 ve = normalize(pre_pos - self.origin);
135 if ((fe != 1) || (self.enemy == world) || (edist > 1000))
137 myspeed = vlen(self.velocity);
139 lt_for = myspeed * 3;
140 lt_seek = myspeed * 2.95;
143 traceline(self.origin, self.origin + v_forward * lt_for,false,self);
147 // Find angular offset
148 ad = vlen(vectoangles(normalize(self.enemy.origin - self.origin)) - self.angles);
150 // To close to something, Slow down!
151 if ( ((ff < 0.7) || (ad > 4)) && (myspeed > (autocvar_g_turrets_unit_hk_shot_speed)) )
152 myspeed = max(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_decel), (autocvar_g_turrets_unit_hk_shot_speed));
154 // Failry clear, accelerate.
155 if ( (ff > 0.7) && (myspeed < (autocvar_g_turrets_unit_hk_shot_speed_max)) )
156 myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel), (autocvar_g_turrets_unit_hk_shot_speed_max));
160 pt_seek = bound(0.15,pt_seek,0.8);
161 if (ff < 0.5) pt_seek = 1;
164 traceline(self.origin, self.origin + (-1 * (v_right * pt_seek) + (v_forward * ff)) * lt_seek,false,self);
169 traceline(self.origin, self.origin + ((v_right * pt_seek) + (v_forward * ff)) * lt_seek ,false,self);
174 traceline(self.origin, self.origin + ((v_up * pt_seek) + (v_forward * ff)) * lt_seek ,false,self);
179 traceline(self.origin, self.origin + (-1 * (v_up * pt_seek) + (v_forward * ff)) * lt_seek ,false,self);
183 vl = normalize(vl - self.origin);
184 vr = normalize(vr - self.origin);
185 vu = normalize(vu - self.origin);
186 vd = normalize(vd - self.origin);
188 // Panic tresh passed, find a single direction and turn as hard as we can
192 if (fl > fr) wishdir = -1 * v_right;
193 if (fu > fl) wishdir = v_up;
194 if (fd > fu) wishdir = -1 * v_up;
198 // Normalize our trace vectors to make a smooth path
199 wishdir = normalize( (vl * fl) + (vr * fr) + (vu * fu) + (vd * fd) );
204 if (fe < 0.1) fe = 0.1; // Make sure we always try to move sligtly towards our target
205 wishdir = (wishdir * (1 - fe)) + (ve * fe);
210 // Got a clear path to target, speed up fast (if not at full speed) and go straight for it.
211 myspeed = vlen(self.velocity);
212 if (myspeed < (autocvar_g_turrets_unit_hk_shot_speed_max))
213 myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel2),(autocvar_g_turrets_unit_hk_shot_speed_max));
218 if ((myspeed > (autocvar_g_turrets_unit_hk_shot_speed)) && (self.cnt > time))
219 myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel2),(autocvar_g_turrets_unit_hk_shot_speed_max));
224 self.cnt = time + 0.25;
226 self.movetype = MOVETYPE_BOUNCE;
230 // Calculate new heading
231 olddir = normalize(self.velocity);
232 newdir = normalize(olddir + wishdir * (autocvar_g_turrets_unit_hk_shot_speed_turnrate));
234 // Set heading & speed
235 self.velocity = newdir * myspeed;
237 // Align model with new heading
238 self.angles = vectoangles(self.velocity);
241 #ifdef TURRET_DEBUG_HK
242 //if(self.atime < time) {
243 if ((fe <= 0.99)||(edist > 1000))
245 te_lightning2(world,self.origin, self.origin + vr * lt_seek);
246 te_lightning2(world,self.origin, self.origin + vl * lt_seek);
247 te_lightning2(world,self.origin, self.origin + vu * lt_seek);
248 te_lightning2(world,self.origin, self.origin + vd * lt_seek);
249 te_lightning2(world,self.origin, vf);
253 te_lightning2(world,self.origin, self.enemy.origin);
255 bprint("Speed: ", ftos(rint(myspeed)), "\n");
256 bprint("Trace to solid: ", ftos(rint(ff * 100)), "%\n");
257 bprint("Trace to target:", ftos(rint(fe * 100)), "%\n");
258 self.atime = time + 0.2;
262 UpdateCSQCProjectile(self);
265 float turret_hk_addtarget(entity e_target,entity e_sender)
269 if (turret_validate_target(self,e_target,self.target_validate_flags) > 0)
271 self.enemy = e_target;
279 void spawnfunc_turret_hk() { SELFPARAM(); if(!turret_initialize(TUR_HK.m_id)) remove(self); }
281 float t_hk(Turret thistur, float req)
289 missile = turret_projectile(SND(ROCKET_FIRE), 6, 10, DEATH_TURRET_HK, PROJECTILE_ROCKET, FALSE, FALSE);
290 te_explosion (missile.origin);
292 missile.think = turret_hk_missile_think;
293 missile.nextthink = time + 0.25;
294 missile.movetype = MOVETYPE_BOUNCEMISSILE;
295 missile.velocity = self.tur_shotdir_updated * (self.shot_speed * 0.75);
296 missile.angles = vectoangles(missile.velocity);
297 missile.cnt = time + 30;
298 missile.ticrate = max(autocvar_sys_ticrate, 0.05);
299 missile.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_AI;
301 if (self.tur_head.frame == 0)
302 self.tur_head.frame = self.tur_head.frame + 1;
308 if (self.tur_head.frame != 0)
309 self.tur_head.frame = self.tur_head.frame + 1;
311 if (self.tur_head.frame > 5)
312 self.tur_head.frame = 0;
322 self.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE;
323 self.aim_flags = TFL_AIM_SIMPLE;
324 self.target_select_flags = TFL_TARGETSELECT_LOS | TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TRIGGERTARGET | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK;
325 self.firecheck_flags = TFL_FIRECHECK_DEAD | TFL_FIRECHECK_TEAMCHECK | TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_AFF;
326 self.shoot_flags = TFL_SHOOT_CLEARTARGET;
327 self.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TEAMCHECK;
329 self.turret_addtarget = turret_hk_addtarget;
344 float t_hk(Turret thistur, float req)
362 #endif // REGISTER_TURRET