5 /* spawnflags */ TUR_FLAG_SPLASH | TUR_FLAG_MEDPROJ | TUR_FLAG_PLAYER | TUR_FLAG_RECIEVETARGETS,
6 /* mins,maxs */ '-32 -32 0', '32 32 64',
7 /* model */ "base.md3",
8 /* head_model */ "hk.md3",
10 /* fullname */ _("Hunter-Killer Turret")
14 float autocvar_g_turrets_unit_hk_shot_speed;
15 float autocvar_g_turrets_unit_hk_shot_speed_accel;
16 float autocvar_g_turrets_unit_hk_shot_speed_accel2;
17 float autocvar_g_turrets_unit_hk_shot_speed_decel;
18 float autocvar_g_turrets_unit_hk_shot_speed_max;
19 float autocvar_g_turrets_unit_hk_shot_speed_turnrate;
21 //#define TURRET_DEBUG_HK
23 #ifdef TURRET_DEBUG_HK
27 float hk_is_valid_target(entity e_target)
29 if (e_target == world)
32 // If only this was used more..
33 if (e_target.flags & FL_NOTARGET)
37 if ((e_target.takedamage == DAMAGE_NO) || (e_target.health < 0))
41 if (IS_CLIENT(e_target))
43 if (self.owner.target_select_playerbias < 0)
46 if (e_target.deadflag != DEAD_NO)
51 if ((e_target.flags & FL_PROJECTILE) && (self.owner.target_select_missilebias < 0))
55 if ((e_target.team == self.owner.team) || (self.owner.team == e_target.owner.team))
61 void turret_hk_missile_think()
63 vector vu, vd, vf, vl, vr, ve; // Vector (direction)
64 float fu, fd, ff, fl, fr, fe; // Fraction to solid
65 vector olddir,wishdir,newdir; // Final direction
66 float lt_for; // Length of Trace FORwrad
67 float lt_seek; // Length of Trace SEEK (left, right, up down)
68 float pt_seek; // Pitch of Trace SEEK (How mutch to angele left, right up, down trace towards v_forward)
74 self.nextthink = time + self.ticrate;
76 //if (self.cnt < time)
77 // turret_hk_missile_explode();
79 if (self.enemy.deadflag != DEAD_NO)
82 // Pick the closest valid target.
85 e = findradius(self.origin, 5000);
88 if (hk_is_valid_target(e))
93 if (vlen(self.origin - e.origin) < vlen(self.origin - self.enemy.origin))
100 self.angles = vectoangles(self.velocity);
101 self.angles_x = self.angles_x * -1;
102 makevectors(self.angles);
103 self.angles_x = self.angles_x * -1;
107 edist = vlen(self.origin - self.enemy.origin);
108 // Close enougth to do decent damage?
109 if ( edist <= (self.owner.shot_radius * 0.25) )
111 turret_projectile_explode();
115 // Get data on enemy position
116 pre_pos = self.enemy.origin +
117 self.enemy.velocity *
118 min((vlen(self.enemy.origin - self.origin) / vlen(self.velocity)),0.5);
120 traceline(self.origin, pre_pos,true,self.enemy);
121 ve = normalize(pre_pos - self.origin);
132 if ((fe != 1) || (self.enemy == world) || (edist > 1000))
134 myspeed = vlen(self.velocity);
136 lt_for = myspeed * 3;
137 lt_seek = myspeed * 2.95;
140 traceline(self.origin, self.origin + v_forward * lt_for,false,self);
144 // Find angular offset
145 ad = vlen(vectoangles(normalize(self.enemy.origin - self.origin)) - self.angles);
147 // To close to something, Slow down!
148 if ( ((ff < 0.7) || (ad > 4)) && (myspeed > (autocvar_g_turrets_unit_hk_shot_speed)) )
149 myspeed = max(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_decel), (autocvar_g_turrets_unit_hk_shot_speed));
151 // Failry clear, accelerate.
152 if ( (ff > 0.7) && (myspeed < (autocvar_g_turrets_unit_hk_shot_speed_max)) )
153 myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel), (autocvar_g_turrets_unit_hk_shot_speed_max));
157 pt_seek = bound(0.15,pt_seek,0.8);
158 if (ff < 0.5) pt_seek = 1;
161 traceline(self.origin, self.origin + (-1 * (v_right * pt_seek) + (v_forward * ff)) * lt_seek,false,self);
166 traceline(self.origin, self.origin + ((v_right * pt_seek) + (v_forward * ff)) * lt_seek ,false,self);
171 traceline(self.origin, self.origin + ((v_up * pt_seek) + (v_forward * ff)) * lt_seek ,false,self);
176 traceline(self.origin, self.origin + (-1 * (v_up * pt_seek) + (v_forward * ff)) * lt_seek ,false,self);
180 vl = normalize(vl - self.origin);
181 vr = normalize(vr - self.origin);
182 vu = normalize(vu - self.origin);
183 vd = normalize(vd - self.origin);
185 // Panic tresh passed, find a single direction and turn as hard as we can
189 if (fl > fr) wishdir = -1 * v_right;
190 if (fu > fl) wishdir = v_up;
191 if (fd > fu) wishdir = -1 * v_up;
195 // Normalize our trace vectors to make a smooth path
196 wishdir = normalize( (vl * fl) + (vr * fr) + (vu * fu) + (vd * fd) );
201 if (fe < 0.1) fe = 0.1; // Make sure we always try to move sligtly towards our target
202 wishdir = (wishdir * (1 - fe)) + (ve * fe);
207 // Got a clear path to target, speed up fast (if not at full speed) and go straight for it.
208 myspeed = vlen(self.velocity);
209 if (myspeed < (autocvar_g_turrets_unit_hk_shot_speed_max))
210 myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel2),(autocvar_g_turrets_unit_hk_shot_speed_max));
215 if ((myspeed > (autocvar_g_turrets_unit_hk_shot_speed)) && (self.cnt > time))
216 myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel2),(autocvar_g_turrets_unit_hk_shot_speed_max));
221 self.cnt = time + 0.25;
223 self.movetype = MOVETYPE_BOUNCE;
227 // Calculate new heading
228 olddir = normalize(self.velocity);
229 newdir = normalize(olddir + wishdir * (autocvar_g_turrets_unit_hk_shot_speed_turnrate));
231 // Set heading & speed
232 self.velocity = newdir * myspeed;
234 // Align model with new heading
235 self.angles = vectoangles(self.velocity);
238 #ifdef TURRET_DEBUG_HK
239 //if(self.atime < time) {
240 if ((fe <= 0.99)||(edist > 1000))
242 te_lightning2(world,self.origin, self.origin + vr * lt_seek);
243 te_lightning2(world,self.origin, self.origin + vl * lt_seek);
244 te_lightning2(world,self.origin, self.origin + vu * lt_seek);
245 te_lightning2(world,self.origin, self.origin + vd * lt_seek);
246 te_lightning2(world,self.origin, vf);
250 te_lightning2(world,self.origin, self.enemy.origin);
252 bprint("Speed: ", ftos(rint(myspeed)), "\n");
253 bprint("Trace to solid: ", ftos(rint(ff * 100)), "%\n");
254 bprint("Trace to target:", ftos(rint(fe * 100)), "%\n");
255 self.atime = time + 0.2;
259 UpdateCSQCProjectile(self);
262 float turret_hk_addtarget(entity e_target,entity e_sender)
266 if (turret_validate_target(self,e_target,self.target_validate_flags) > 0)
268 self.enemy = e_target;
276 void spawnfunc_turret_hk() { SELFPARAM(); if(!turret_initialize(TUR_HK)) remove(self); }
278 float t_hk(float req)
286 missile = turret_projectile(W_Sound("rocket_fire"), 6, 10, DEATH_TURRET_HK, PROJECTILE_ROCKET, FALSE, FALSE);
287 te_explosion (missile.origin);
289 missile.think = turret_hk_missile_think;
290 missile.nextthink = time + 0.25;
291 missile.movetype = MOVETYPE_BOUNCEMISSILE;
292 missile.velocity = self.tur_shotdir_updated * (self.shot_speed * 0.75);
293 missile.angles = vectoangles(missile.velocity);
294 missile.cnt = time + 30;
295 missile.ticrate = max(autocvar_sys_ticrate, 0.05);
296 missile.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_AI;
298 if (self.tur_head.frame == 0)
299 self.tur_head.frame = self.tur_head.frame + 1;
305 if (self.tur_head.frame != 0)
306 self.tur_head.frame = self.tur_head.frame + 1;
308 if (self.tur_head.frame > 5)
309 self.tur_head.frame = 0;
319 self.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE;
320 self.aim_flags = TFL_AIM_SIMPLE;
321 self.target_select_flags = TFL_TARGETSELECT_LOS | TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TRIGGERTARGET | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK;
322 self.firecheck_flags = TFL_FIRECHECK_DEAD | TFL_FIRECHECK_TEAMCHECK | TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_AFF;
323 self.shoot_flags = TFL_SHOOT_CLEARTARGET;
324 self.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TEAMCHECK;
326 self.turret_addtarget = turret_hk_addtarget;
341 float t_hk(float req)
359 #endif // REGISTER_TURRET