4 CLASS(HunterKiller, Turret)
5 /* spawnflags */ ATTRIB(HunterKiller, spawnflags, int, TUR_FLAG_SPLASH | TUR_FLAG_MEDPROJ | TUR_FLAG_PLAYER | TUR_FLAG_RECIEVETARGETS);
6 /* mins */ ATTRIB(HunterKiller, mins, vector, '-32 -32 0');
7 /* maxs */ ATTRIB(HunterKiller, maxs, vector, '32 32 64');
8 /* modelname */ ATTRIB(HunterKiller, mdl, string, "base.md3");
9 /* model */ ATTRIB(HunterKiller, model, string, strzone(strcat("models/turrets/", this.mdl)));
10 /* head_model */ ATTRIB(HunterKiller, head_model, string, strzone(strcat("models/turrets/", "hk.md3")));
11 /* netname */ ATTRIB(HunterKiller, netname, string, "hk");
12 /* fullname */ ATTRIB(HunterKiller, turret_name, string, _("Hunter-Killer Turret"));
13 ENDCLASS(HunterKiller)
15 REGISTER_TURRET(HK, NEW(HunterKiller));
17 CLASS(HunterKillerAttack, PortoLaunch)
18 /* flags */ ATTRIB(HunterKillerAttack, spawnflags, int, WEP_TYPE_OTHER);
19 /* impulse */ ATTRIB(HunterKillerAttack, impulse, int, 9);
20 /* refname */ ATTRIB(HunterKillerAttack, netname, string, "turret_hk");
21 /* wepname */ ATTRIB(HunterKillerAttack, message, string, _("Hunter-Killer"));
22 ENDCLASS(HunterKillerAttack)
23 REGISTER_WEAPON(HK, NEW(HunterKillerAttack));
29 void turret_initparams(entity);
30 void turret_hk_missile_think();
31 METHOD(HunterKillerAttack, wr_think, bool(entity thiswep, bool fire1, bool fire2)) {
33 bool isPlayer = IS_PLAYER(self);
35 if (!isPlayer || weapon_prepareattack(false, WEP_CVAR_PRI(electro, refire))) {
37 turret_initparams(self);
38 W_SetupShot_Dir(self, v_forward, false, 0, W_Sound("electro_fire"), CH_WEAPON_B, 0);
39 self.tur_shotdir_updated = w_shotdir;
40 self.tur_shotorg = w_shotorg;
42 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
44 entity missile = turret_projectile(SND(ROCKET_FIRE), 6, 10, DEATH_TURRET_HK, PROJECTILE_ROCKET, FALSE, FALSE);
45 te_explosion (missile.origin);
47 missile.think = turret_hk_missile_think;
48 missile.nextthink = time + 0.25;
49 missile.movetype = MOVETYPE_BOUNCEMISSILE;
50 missile.velocity = self.tur_shotdir_updated * (self.shot_speed * 0.75);
51 missile.angles = vectoangles(missile.velocity);
52 missile.cnt = time + 30;
53 missile.ticrate = max(autocvar_sys_ticrate, 0.05);
54 missile.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_AI;
57 if (self.tur_head.frame == 0)
58 self.tur_head.frame = self.tur_head.frame + 1;
63 float autocvar_g_turrets_unit_hk_shot_speed;
64 float autocvar_g_turrets_unit_hk_shot_speed_accel;
65 float autocvar_g_turrets_unit_hk_shot_speed_accel2;
66 float autocvar_g_turrets_unit_hk_shot_speed_decel;
67 float autocvar_g_turrets_unit_hk_shot_speed_max;
68 float autocvar_g_turrets_unit_hk_shot_speed_turnrate;
70 //#define TURRET_DEBUG_HK
72 #ifdef TURRET_DEBUG_HK
76 float hk_is_valid_target(entity e_target)
78 if (e_target == world)
81 // If only this was used more..
82 if (e_target.flags & FL_NOTARGET)
86 if ((e_target.takedamage == DAMAGE_NO) || (e_target.health < 0))
90 if (IS_CLIENT(e_target))
92 if (self.owner.target_select_playerbias < 0)
95 if (e_target.deadflag != DEAD_NO)
100 if ((e_target.flags & FL_PROJECTILE) && (self.owner.target_select_missilebias < 0))
104 if ((e_target.team == self.owner.team) || (self.owner.team == e_target.owner.team))
110 void turret_hk_missile_think()
112 vector vu, vd, vf, vl, vr, ve; // Vector (direction)
113 float fu, fd, ff, fl, fr, fe; // Fraction to solid
114 vector olddir,wishdir,newdir; // Final direction
115 float lt_for; // Length of Trace FORwrad
116 float lt_seek; // Length of Trace SEEK (left, right, up down)
117 float pt_seek; // Pitch of Trace SEEK (How mutch to angele left, right up, down trace towards v_forward)
123 self.nextthink = time + self.ticrate;
125 //if (self.cnt < time)
126 // turret_hk_missile_explode();
128 if (self.enemy.deadflag != DEAD_NO)
131 // Pick the closest valid target.
134 e = findradius(self.origin, 5000);
137 if (hk_is_valid_target(e))
142 if (vlen(self.origin - e.origin) < vlen(self.origin - self.enemy.origin))
149 self.angles = vectoangles(self.velocity);
150 self.angles_x = self.angles_x * -1;
151 makevectors(self.angles);
152 self.angles_x = self.angles_x * -1;
156 edist = vlen(self.origin - self.enemy.origin);
157 // Close enougth to do decent damage?
158 if ( edist <= (self.owner.shot_radius * 0.25) )
160 turret_projectile_explode();
164 // Get data on enemy position
165 pre_pos = self.enemy.origin +
166 self.enemy.velocity *
167 min((vlen(self.enemy.origin - self.origin) / vlen(self.velocity)),0.5);
169 traceline(self.origin, pre_pos,true,self.enemy);
170 ve = normalize(pre_pos - self.origin);
181 if ((fe != 1) || (self.enemy == world) || (edist > 1000))
183 myspeed = vlen(self.velocity);
185 lt_for = myspeed * 3;
186 lt_seek = myspeed * 2.95;
189 traceline(self.origin, self.origin + v_forward * lt_for,false,self);
193 // Find angular offset
194 ad = vlen(vectoangles(normalize(self.enemy.origin - self.origin)) - self.angles);
196 // To close to something, Slow down!
197 if ( ((ff < 0.7) || (ad > 4)) && (myspeed > (autocvar_g_turrets_unit_hk_shot_speed)) )
198 myspeed = max(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_decel), (autocvar_g_turrets_unit_hk_shot_speed));
200 // Failry clear, accelerate.
201 if ( (ff > 0.7) && (myspeed < (autocvar_g_turrets_unit_hk_shot_speed_max)) )
202 myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel), (autocvar_g_turrets_unit_hk_shot_speed_max));
206 pt_seek = bound(0.15,pt_seek,0.8);
207 if (ff < 0.5) pt_seek = 1;
210 traceline(self.origin, self.origin + (-1 * (v_right * pt_seek) + (v_forward * ff)) * lt_seek,false,self);
215 traceline(self.origin, self.origin + ((v_right * pt_seek) + (v_forward * ff)) * lt_seek ,false,self);
220 traceline(self.origin, self.origin + ((v_up * pt_seek) + (v_forward * ff)) * lt_seek ,false,self);
225 traceline(self.origin, self.origin + (-1 * (v_up * pt_seek) + (v_forward * ff)) * lt_seek ,false,self);
229 vl = normalize(vl - self.origin);
230 vr = normalize(vr - self.origin);
231 vu = normalize(vu - self.origin);
232 vd = normalize(vd - self.origin);
234 // Panic tresh passed, find a single direction and turn as hard as we can
238 if (fl > fr) wishdir = -1 * v_right;
239 if (fu > fl) wishdir = v_up;
240 if (fd > fu) wishdir = -1 * v_up;
244 // Normalize our trace vectors to make a smooth path
245 wishdir = normalize( (vl * fl) + (vr * fr) + (vu * fu) + (vd * fd) );
250 if (fe < 0.1) fe = 0.1; // Make sure we always try to move sligtly towards our target
251 wishdir = (wishdir * (1 - fe)) + (ve * fe);
256 // Got a clear path to target, speed up fast (if not at full speed) and go straight for it.
257 myspeed = vlen(self.velocity);
258 if (myspeed < (autocvar_g_turrets_unit_hk_shot_speed_max))
259 myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel2),(autocvar_g_turrets_unit_hk_shot_speed_max));
264 if ((myspeed > (autocvar_g_turrets_unit_hk_shot_speed)) && (self.cnt > time))
265 myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel2),(autocvar_g_turrets_unit_hk_shot_speed_max));
270 self.cnt = time + 0.25;
272 self.movetype = MOVETYPE_BOUNCE;
276 // Calculate new heading
277 olddir = normalize(self.velocity);
278 newdir = normalize(olddir + wishdir * (autocvar_g_turrets_unit_hk_shot_speed_turnrate));
280 // Set heading & speed
281 self.velocity = newdir * myspeed;
283 // Align model with new heading
284 self.angles = vectoangles(self.velocity);
287 #ifdef TURRET_DEBUG_HK
288 //if(self.atime < time) {
289 if ((fe <= 0.99)||(edist > 1000))
291 te_lightning2(world,self.origin, self.origin + vr * lt_seek);
292 te_lightning2(world,self.origin, self.origin + vl * lt_seek);
293 te_lightning2(world,self.origin, self.origin + vu * lt_seek);
294 te_lightning2(world,self.origin, self.origin + vd * lt_seek);
295 te_lightning2(world,self.origin, vf);
299 te_lightning2(world,self.origin, self.enemy.origin);
301 bprint("Speed: ", ftos(rint(myspeed)), "\n");
302 bprint("Trace to solid: ", ftos(rint(ff * 100)), "%\n");
303 bprint("Trace to target:", ftos(rint(fe * 100)), "%\n");
304 self.atime = time + 0.2;
308 UpdateCSQCProjectile(self);
311 float turret_hk_addtarget(entity e_target,entity e_sender)
315 if (turret_validate_target(self,e_target,self.target_validate_flags) > 0)
317 self.enemy = e_target;
325 void spawnfunc_turret_hk() { SELFPARAM(); if(!turret_initialize(TUR_HK.m_id)) remove(self); }
327 METHOD(HunterKiller, tr_attack, void(HunterKiller thistur))
330 wep.wr_think(wep, true, false);
332 METHOD(HunterKiller, tr_think, bool(HunterKiller thistur))
334 if (self.tur_head.frame != 0)
335 self.tur_head.frame = self.tur_head.frame + 1;
337 if (self.tur_head.frame > 5)
338 self.tur_head.frame = 0;
342 METHOD(HunterKiller, tr_death, bool(HunterKiller thistur))
346 METHOD(HunterKiller, tr_setup, bool(HunterKiller thistur))
348 self.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE;
349 self.aim_flags = TFL_AIM_SIMPLE;
350 self.target_select_flags = TFL_TARGETSELECT_LOS | TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TRIGGERTARGET | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK;
351 self.firecheck_flags = TFL_FIRECHECK_DEAD | TFL_FIRECHECK_TEAMCHECK | TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_AFF;
352 self.shoot_flags = TFL_SHOOT_CLEARTARGET;
353 self.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TEAMCHECK;
355 self.turret_addtarget = turret_hk_addtarget;
359 METHOD(HunterKiller, tr_precache, bool(HunterKiller thistur))
366 METHOD(HunterKiller, tr_setup, bool(HunterKiller thistur))
370 METHOD(HunterKiller, tr_precache, bool(HunterKiller thistur))
376 #endif // REGISTER_TURRET