4 CLASS(HunterKillerAttack, PortoLaunch)
5 /* flags */ ATTRIB(HunterKillerAttack, spawnflags, int, WEP_TYPE_OTHER);
6 /* impulse */ ATTRIB(HunterKillerAttack, impulse, int, 9);
7 /* refname */ ATTRIB(HunterKillerAttack, netname, string, "turret_hk");
8 /* wepname */ ATTRIB(HunterKillerAttack, message, string, _("Hunter-Killer"));
9 ENDCLASS(HunterKillerAttack)
10 REGISTER_WEAPON(HK, NEW(HunterKillerAttack));
12 CLASS(HunterKiller, Turret)
13 /* spawnflags */ ATTRIB(HunterKiller, spawnflags, int, TUR_FLAG_SPLASH | TUR_FLAG_MEDPROJ | TUR_FLAG_PLAYER | TUR_FLAG_RECIEVETARGETS);
14 /* mins */ ATTRIB(HunterKiller, mins, vector, '-32 -32 0');
15 /* maxs */ ATTRIB(HunterKiller, maxs, vector, '32 32 64');
16 /* modelname */ ATTRIB(HunterKiller, mdl, string, "base.md3");
17 /* model */ ATTRIB(HunterKiller, model, string, strzone(strcat("models/turrets/", this.mdl)));
18 /* head_model */ ATTRIB(HunterKiller, head_model, string, strzone(strcat("models/turrets/", "hk.md3")));
19 /* netname */ ATTRIB(HunterKiller, netname, string, "hk");
20 /* fullname */ ATTRIB(HunterKiller, turret_name, string, _("Hunter-Killer Turret"));
21 ATTRIB(HunterKiller, m_weapon, Weapon, WEP_HK);
22 ENDCLASS(HunterKiller)
23 REGISTER_TURRET(HK, NEW(HunterKiller));
29 void turret_hk_missile_think();
30 METHOD(HunterKillerAttack, wr_think, bool(entity thiswep, bool fire1, bool fire2)) {
32 bool isPlayer = IS_PLAYER(self);
34 if (!isPlayer || weapon_prepareattack(false, WEP_CVAR_PRI(electro, refire))) {
36 turret_initparams(self);
37 W_SetupShot_Dir(self, v_forward, false, 0, W_Sound("electro_fire"), CH_WEAPON_B, 0);
38 self.tur_shotdir_updated = w_shotdir;
39 self.tur_shotorg = w_shotorg;
41 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
43 entity missile = turret_projectile(SND(ROCKET_FIRE), 6, 10, DEATH_TURRET_HK, PROJECTILE_ROCKET, FALSE, FALSE);
44 te_explosion (missile.origin);
46 missile.think = turret_hk_missile_think;
47 missile.nextthink = time + 0.25;
48 missile.movetype = MOVETYPE_BOUNCEMISSILE;
49 missile.velocity = self.tur_shotdir_updated * (self.shot_speed * 0.75);
50 missile.angles = vectoangles(missile.velocity);
51 missile.cnt = time + 30;
52 missile.ticrate = max(autocvar_sys_ticrate, 0.05);
53 missile.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_AI;
56 if (self.tur_head.frame == 0)
57 self.tur_head.frame = self.tur_head.frame + 1;
62 float autocvar_g_turrets_unit_hk_shot_speed;
63 float autocvar_g_turrets_unit_hk_shot_speed_accel;
64 float autocvar_g_turrets_unit_hk_shot_speed_accel2;
65 float autocvar_g_turrets_unit_hk_shot_speed_decel;
66 float autocvar_g_turrets_unit_hk_shot_speed_max;
67 float autocvar_g_turrets_unit_hk_shot_speed_turnrate;
69 //#define TURRET_DEBUG_HK
71 #ifdef TURRET_DEBUG_HK
75 float hk_is_valid_target(entity e_target)
77 if (e_target == world)
80 // If only this was used more..
81 if (e_target.flags & FL_NOTARGET)
85 if ((e_target.takedamage == DAMAGE_NO) || (e_target.health < 0))
89 if (IS_CLIENT(e_target))
91 if (self.owner.target_select_playerbias < 0)
94 if (e_target.deadflag != DEAD_NO)
99 if ((e_target.flags & FL_PROJECTILE) && (self.owner.target_select_missilebias < 0))
103 if ((e_target.team == self.owner.team) || (self.owner.team == e_target.owner.team))
109 void turret_hk_missile_think()
111 vector vu, vd, vf, vl, vr, ve; // Vector (direction)
112 float fu, fd, ff, fl, fr, fe; // Fraction to solid
113 vector olddir,wishdir,newdir; // Final direction
114 float lt_for; // Length of Trace FORwrad
115 float lt_seek; // Length of Trace SEEK (left, right, up down)
116 float pt_seek; // Pitch of Trace SEEK (How mutch to angele left, right up, down trace towards v_forward)
122 self.nextthink = time + self.ticrate;
124 //if (self.cnt < time)
125 // turret_hk_missile_explode();
127 if (self.enemy.deadflag != DEAD_NO)
130 // Pick the closest valid target.
133 e = findradius(self.origin, 5000);
136 if (hk_is_valid_target(e))
141 if (vlen(self.origin - e.origin) < vlen(self.origin - self.enemy.origin))
148 self.angles = vectoangles(self.velocity);
149 self.angles_x = self.angles_x * -1;
150 makevectors(self.angles);
151 self.angles_x = self.angles_x * -1;
155 edist = vlen(self.origin - self.enemy.origin);
156 // Close enougth to do decent damage?
157 if ( edist <= (self.owner.shot_radius * 0.25) )
159 turret_projectile_explode();
163 // Get data on enemy position
164 pre_pos = self.enemy.origin +
165 self.enemy.velocity *
166 min((vlen(self.enemy.origin - self.origin) / vlen(self.velocity)),0.5);
168 traceline(self.origin, pre_pos,true,self.enemy);
169 ve = normalize(pre_pos - self.origin);
180 if ((fe != 1) || (self.enemy == world) || (edist > 1000))
182 myspeed = vlen(self.velocity);
184 lt_for = myspeed * 3;
185 lt_seek = myspeed * 2.95;
188 traceline(self.origin, self.origin + v_forward * lt_for,false,self);
192 // Find angular offset
193 ad = vlen(vectoangles(normalize(self.enemy.origin - self.origin)) - self.angles);
195 // To close to something, Slow down!
196 if ( ((ff < 0.7) || (ad > 4)) && (myspeed > (autocvar_g_turrets_unit_hk_shot_speed)) )
197 myspeed = max(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_decel), (autocvar_g_turrets_unit_hk_shot_speed));
199 // Failry clear, accelerate.
200 if ( (ff > 0.7) && (myspeed < (autocvar_g_turrets_unit_hk_shot_speed_max)) )
201 myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel), (autocvar_g_turrets_unit_hk_shot_speed_max));
205 pt_seek = bound(0.15,pt_seek,0.8);
206 if (ff < 0.5) pt_seek = 1;
209 traceline(self.origin, self.origin + (-1 * (v_right * pt_seek) + (v_forward * ff)) * lt_seek,false,self);
214 traceline(self.origin, self.origin + ((v_right * pt_seek) + (v_forward * ff)) * lt_seek ,false,self);
219 traceline(self.origin, self.origin + ((v_up * pt_seek) + (v_forward * ff)) * lt_seek ,false,self);
224 traceline(self.origin, self.origin + (-1 * (v_up * pt_seek) + (v_forward * ff)) * lt_seek ,false,self);
228 vl = normalize(vl - self.origin);
229 vr = normalize(vr - self.origin);
230 vu = normalize(vu - self.origin);
231 vd = normalize(vd - self.origin);
233 // Panic tresh passed, find a single direction and turn as hard as we can
237 if (fl > fr) wishdir = -1 * v_right;
238 if (fu > fl) wishdir = v_up;
239 if (fd > fu) wishdir = -1 * v_up;
243 // Normalize our trace vectors to make a smooth path
244 wishdir = normalize( (vl * fl) + (vr * fr) + (vu * fu) + (vd * fd) );
249 if (fe < 0.1) fe = 0.1; // Make sure we always try to move sligtly towards our target
250 wishdir = (wishdir * (1 - fe)) + (ve * fe);
255 // Got a clear path to target, speed up fast (if not at full speed) and go straight for it.
256 myspeed = vlen(self.velocity);
257 if (myspeed < (autocvar_g_turrets_unit_hk_shot_speed_max))
258 myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel2),(autocvar_g_turrets_unit_hk_shot_speed_max));
263 if ((myspeed > (autocvar_g_turrets_unit_hk_shot_speed)) && (self.cnt > time))
264 myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel2),(autocvar_g_turrets_unit_hk_shot_speed_max));
269 self.cnt = time + 0.25;
271 self.movetype = MOVETYPE_BOUNCE;
275 // Calculate new heading
276 olddir = normalize(self.velocity);
277 newdir = normalize(olddir + wishdir * (autocvar_g_turrets_unit_hk_shot_speed_turnrate));
279 // Set heading & speed
280 self.velocity = newdir * myspeed;
282 // Align model with new heading
283 self.angles = vectoangles(self.velocity);
286 #ifdef TURRET_DEBUG_HK
287 //if(self.atime < time) {
288 if ((fe <= 0.99)||(edist > 1000))
290 te_lightning2(world,self.origin, self.origin + vr * lt_seek);
291 te_lightning2(world,self.origin, self.origin + vl * lt_seek);
292 te_lightning2(world,self.origin, self.origin + vu * lt_seek);
293 te_lightning2(world,self.origin, self.origin + vd * lt_seek);
294 te_lightning2(world,self.origin, vf);
298 te_lightning2(world,self.origin, self.enemy.origin);
300 bprint("Speed: ", ftos(rint(myspeed)), "\n");
301 bprint("Trace to solid: ", ftos(rint(ff * 100)), "%\n");
302 bprint("Trace to target:", ftos(rint(fe * 100)), "%\n");
303 self.atime = time + 0.2;
307 UpdateCSQCProjectile(self);
310 float turret_hk_addtarget(entity e_target,entity e_sender)
314 if (turret_validate_target(self,e_target,self.target_validate_flags) > 0)
316 self.enemy = e_target;
324 void spawnfunc_turret_hk() { SELFPARAM(); if(!turret_initialize(TUR_HK)) remove(self); }
326 METHOD(HunterKiller, tr_think, void(HunterKiller thistur))
328 if (self.tur_head.frame != 0)
329 self.tur_head.frame = self.tur_head.frame + 1;
331 if (self.tur_head.frame > 5)
332 self.tur_head.frame = 0;
334 METHOD(HunterKiller, tr_setup, void(HunterKiller this, entity it))
336 it.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE;
337 it.aim_flags = TFL_AIM_SIMPLE;
338 it.target_select_flags = TFL_TARGETSELECT_LOS | TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TRIGGERTARGET | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK;
339 it.firecheck_flags = TFL_FIRECHECK_DEAD | TFL_FIRECHECK_TEAMCHECK | TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_AFF;
340 it.shoot_flags = TFL_SHOOT_CLEARTARGET;
341 it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TEAMCHECK;
343 it.turret_addtarget = turret_hk_addtarget;