1 //#define TURRET_DEBUG_HK
7 void spawnfunc_turret_hk();
8 void turret_hk_dinit();
9 void turret_hk_attack();
12 float hk_is_valid_target(entity e_target)
14 if (e_target == world)
17 // If only this was used more..
18 if (e_target.flags & FL_NOTARGET)
22 if ((e_target.takedamage == DAMAGE_NO) || (e_target.health < 0))
26 if (e_target.flags & FL_CLIENT)
28 if (self.owner.target_select_playerbias < 0)
31 if (e_target.deadflag != DEAD_NO)
36 if ((e_target.flags & FL_PROJECTILE) && (self.owner.target_select_missilebias < 0))
40 if ((e_target.team == self.owner.team) || (self.owner.team == e_target.owner.team))
45 void turret_hk_missile_think()
47 vector vu, vd, vf, vl, vr, ve; // Vector (direction)
48 float fu, fd, ff, fl, fr, fe; // Fraction to solid
49 vector olddir,wishdir,newdir; // Final direction
50 float lt_for; // Length of Trace FORwrad
51 float lt_seek; // Length of Trace SEEK (left, right, up down)
52 float pt_seek; // Pitch of Trace SEEK (How mutch to angele left, right up, down trace towards v_forward)
58 self.nextthink = time + self.ticrate;
60 //if (self.cnt < time)
61 // turret_hk_missile_explode();
63 if (self.enemy.deadflag != DEAD_NO)
66 // Pick the closest valid target.
69 e = findradius(self.origin, 5000);
72 if (hk_is_valid_target(e))
77 if (vlen(self.origin - e.origin) < vlen(self.origin - self.enemy.origin))
84 self.angles = vectoangles(self.velocity);
85 self.angles_x = self.angles_x * -1;
86 makevectors(self.angles);
87 self.angles_x = self.angles_x * -1;
91 edist = vlen(self.origin - self.enemy.origin);
92 // Close enougth to do decent damage?
93 if ( edist <= (self.owner.shot_radius * 0.25) )
95 turret_projectile_explode();
99 // Get data on enemy position
100 pre_pos = self.enemy.origin +
101 self.enemy.velocity *
102 min((vlen(self.enemy.origin - self.origin) / vlen(self.velocity)),0.5);
104 traceline(self.origin, pre_pos,TRUE,self.enemy);
105 ve = normalize(pre_pos - self.origin);
116 if ((fe != 1) || (self.enemy == world) || (edist > 1000))
118 myspeed = vlen(self.velocity);
120 lt_for = myspeed * 3;
121 lt_seek = myspeed * 2.95;
124 traceline(self.origin, self.origin + v_forward * lt_for,FALSE,self);
128 // Find angular offset
129 ad = vlen(vectoangles(normalize(self.enemy.origin - self.origin)) - self.angles);
131 // To close to something, Slow down!
132 if ( ((ff < 0.7) || (ad > 4)) && (myspeed > autocvar_g_turrets_unit_hk_std_shot_speed) )
133 myspeed = max(myspeed * autocvar_g_turrets_unit_hk_std_shot_speed_decel, autocvar_g_turrets_unit_hk_std_shot_speed);
135 // Failry clear, accelerate.
136 if ( (ff > 0.7) && (myspeed < autocvar_g_turrets_unit_hk_std_shot_speed_max) )
137 myspeed = min(myspeed * autocvar_g_turrets_unit_hk_std_shot_speed_accel, autocvar_g_turrets_unit_hk_std_shot_speed_max);
141 pt_seek = bound(0.15,pt_seek,0.8);
142 if (ff < 0.5) pt_seek = 1;
145 traceline(self.origin, self.origin + (-1 * (v_right * pt_seek) + (v_forward * ff)) * lt_seek,FALSE,self);
150 traceline(self.origin, self.origin + ((v_right * pt_seek) + (v_forward * ff)) * lt_seek ,FALSE,self);
155 traceline(self.origin, self.origin + ((v_up * pt_seek) + (v_forward * ff)) * lt_seek ,FALSE,self);
160 traceline(self.origin, self.origin + (-1 * (v_up * pt_seek) + (v_forward * ff)) * lt_seek ,FALSE,self);
164 vl = normalize(vl - self.origin);
165 vr = normalize(vr - self.origin);
166 vu = normalize(vu - self.origin);
167 vd = normalize(vd - self.origin);
169 // Panic tresh passed, find a single direction and turn as hard as we can
173 if (fl > fr) wishdir = -1 * v_right;
174 if (fu > fl) wishdir = v_up;
175 if (fd > fu) wishdir = -1 * v_up;
179 // Normalize our trace vectors to make a smooth path
180 wishdir = normalize( (vl * fl) + (vr * fr) + (vu * fu) + (vd * fd) );
185 if (fe < 0.1) fe = 0.1; // Make sure we always try to move sligtly towards our target
186 wishdir = (wishdir * (1 - fe)) + (ve * fe);
191 // Got a clear path to target, speed up fast (if not at full speed) and go straight for it.
192 myspeed = vlen(self.velocity);
193 if (myspeed < autocvar_g_turrets_unit_hk_std_shot_speed_max)
194 myspeed = min(myspeed * autocvar_g_turrets_unit_hk_std_shot_speed_accel2,autocvar_g_turrets_unit_hk_std_shot_speed_max);
199 if ((myspeed > autocvar_g_turrets_unit_hk_std_shot_speed) && (self.cnt > time))
200 myspeed = min(myspeed * autocvar_g_turrets_unit_hk_std_shot_speed_accel2,autocvar_g_turrets_unit_hk_std_shot_speed_max);
205 self.cnt = time + 0.25;
207 self.movetype = MOVETYPE_BOUNCE;
211 // Calculate new heading
212 olddir = normalize(self.velocity);
213 newdir = normalize(olddir + wishdir * autocvar_g_turrets_unit_hk_std_shot_speed_turnrate);
215 // Set heading & speed
216 self.velocity = newdir * myspeed;
218 // Align model with new heading
219 self.angles = vectoangles(self.velocity);
222 #ifdef TURRET_DEBUG_HK
223 //if(self.atime < time) {
224 if ((fe <= 0.99)||(edist > 1000))
226 te_lightning2(world,self.origin, self.origin + vr * lt_seek);
227 te_lightning2(world,self.origin, self.origin + vl * lt_seek);
228 te_lightning2(world,self.origin, self.origin + vu * lt_seek);
229 te_lightning2(world,self.origin, self.origin + vd * lt_seek);
230 te_lightning2(world,self.origin, vf);
234 te_lightning2(world,self.origin, self.enemy.origin);
236 bprint("Speed: ", ftos(rint(myspeed)), "\n");
237 bprint("Trace to solid: ", ftos(rint(ff * 100)), "%\n");
238 bprint("Trace to target:", ftos(rint(fe * 100)), "%\n");
239 self.atime = time + 0.2;
243 UpdateCSQCProjectile(self);
246 void turret_hk_attack()
250 missile = turret_projectile("weapons/rocket_fire.wav", 6, 10, DEATH_TURRET_HK, PROJECTILE_ROCKET, FALSE, FALSE);
251 te_explosion (missile.origin);
253 missile.think = turret_hk_missile_think;
254 missile.nextthink = time + 0.25;
255 missile.movetype = MOVETYPE_BOUNCEMISSILE;
256 missile.velocity = self.tur_shotdir_updated * (self.shot_speed * 0.75);
257 missile.angles = vectoangles(missile.velocity);
258 missile.cnt = time + 30;
259 missile.ticrate = max(autocvar_sys_ticrate, 0.05);
260 missile.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_AI;
262 if (self.tur_head.frame == 0)
263 self.tur_head.frame = self.tur_head.frame + 1;
267 void turret_hk_postthink()
269 if (self.tur_head.frame != 0)
270 self.tur_head.frame = self.tur_head.frame + 1;
272 if (self.tur_head.frame > 5)
273 self.tur_head.frame = 0;
276 float turret_hk_addtarget(entity e_target,entity e_sender)
280 if (turret_validate_target(self,e_target,self.target_validate_flags) > 0)
282 self.enemy = e_target;
290 void turret_hk_dinit()
292 if (self.netname == "")
293 self.netname = "Hunter-killer turret";
295 self.turrcaps_flags = TFL_TURRCAPS_RADIUSDMG | TFL_TURRCAPS_MEDPROJ | TFL_TURRCAPS_PLAYERKILL | TFL_TURRCAPS_RECIVETARGETS;
296 self.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE;
297 self.aim_flags = TFL_AIM_SIMPLE;
298 self.target_select_flags = TFL_TARGETSELECT_LOS | TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TRIGGERTARGET | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK;
299 self.firecheck_flags = TFL_FIRECHECK_DEAD | TFL_FIRECHECK_TEAMCECK | TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_AFF;
300 self.shoot_flags = TFL_SHOOT_CLEARTARGET;
302 if (turret_stdproc_init("hk_std", "models/turrets/base.md3", "models/turrets/hk.md3", TID_HK) == 0)
308 self.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TEAMCHECK;
311 self.turret_firefunc = turret_hk_attack;
313 // re-color badge & handle recoil effect
314 self.turret_postthink = turret_hk_postthink;
316 // What to do when reciveing foreign target data
317 self.turret_addtarget = turret_hk_addtarget;
321 /*QUAKED turret_hk (0 .5 .8) ?
322 * Turret that fires Hunter-killer missiles.
323 * Missiles seek their target and try to avoid obstacles. If target dies early, they
324 * pick a new one on their own.
327 void spawnfunc_turret_hk()
329 precache_model ("models/turrets/base.md3");
330 precache_model ("models/turrets/hk.md3");
332 self.think = turret_hk_dinit;
333 self.nextthink = time + 0.5;