1 //#define TURRET_DEBUG_HK
7 void spawnfunc_turret_hk();
8 void turret_hk_dinit();
9 void turret_hk_attack();
10 void turret_hk_missile_explode();
11 void turret_hk_missile_think();
12 void turret_hk_missile_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force);
13 float turret_hk_addtarget(entity e_target,entity e_sender);
14 //void turret_hk_missile_touch();
22 float turret_hk_addtarget(entity e_target,entity e_sender)
26 if (turret_validate_target(self,e_target,self.target_validate_flags) > 0)
28 self.enemy = e_target;
36 float hk_is_valid_target(entity e_target)
38 if (e_target == world)
41 // If only this was used more..
42 if (e_target.flags & FL_NOTARGET)
46 if ((e_target.takedamage == DAMAGE_NO) || (e_target.health < 0))
50 if (e_target.flags & FL_CLIENT)
52 if (self.owner.target_select_playerbias < 0)
55 if (e_target.deadflag != DEAD_NO)
60 if ((e_target.flags & FL_PROJECTILE) && (self.owner.target_select_missilebias < 0))
64 if ((e_target.team == self.owner.team) || (self.owner.team == e_target.owner.team))
70 void turret_hk_missile_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
72 if (attacker.team == self.team)
75 self.velocity += force;
77 self.health -= damage;
80 turret_hk_missile_explode();
83 void turret_hk_attack()
86 //local entity flash2;
88 sound (self, CH_WEAPON_A, "weapons/rocket_fire.wav", VOL_BASE, ATTN_NORM);
91 missile.solid = SOLID_BBOX;
92 setsize (missile, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot
93 setorigin(missile, self.tur_shotorg);
96 missile.classname = "hk_missile";
98 missile.bot_dodge = TRUE;
99 missile.bot_dodgerating = self.shot_dmg;
100 missile.takedamage = DAMAGE_YES;
101 missile.damageforcescale = 4;
103 missile.think = turret_hk_missile_think;
104 missile.event_damage = turret_hk_missile_damage;
105 missile.nextthink = time + 0.25;
106 missile.movetype = MOVETYPE_BOUNCEMISSILE;
107 missile.velocity = self.tur_shotdir_updated * (self.shot_speed * 0.75);
108 missile.angles = vectoangles(missile.velocity);
109 missile.touch = turret_hk_missile_explode; //turret_hk_missile_touch;
110 missile.flags = FL_PROJECTILE;
111 missile.enemy = self.enemy;
112 missile.team = self.team;
113 missile.cnt = time + 30;
114 missile.ticrate = max(autocvar_sys_ticrate,0.05);
116 CSQCProjectile(missile, FALSE, PROJECTILE_ROCKET, FALSE); // no culling, fly sound
118 te_explosion (missile.origin);
120 if (self.tur_head.frame == 0)
121 self.tur_head.frame = self.tur_head.frame + 1;
125 void turret_hk_missile_think()
127 vector vu, vd, vf, vl, vr, ve; // Vector (direction)
128 float fu, fd, ff, fl, fr, fe; // Fraction to solid
129 vector olddir,wishdir,newdir; // Final direction
130 float lt_for; // Length of Trace FORwrad
131 float lt_seek; // Length of Trace SEEK (left, right, up down)
132 float pt_seek; // Pitch of Trace SEEK (How mutch to angele left, right up, down trace towards v_forward)
138 self.nextthink = time + self.ticrate;
140 //if (self.cnt < time)
141 // turret_hk_missile_explode();
143 if (self.enemy.deadflag != DEAD_NO)
146 // Pick the closest valid target.
149 e = findradius(self.origin, 5000);
152 if (hk_is_valid_target(e))
157 if (vlen(self.origin - e.origin) < vlen(self.origin - self.enemy.origin))
164 self.angles = vectoangles(self.velocity);
165 self.angles_x = self.angles_x * -1;
166 makevectors(self.angles);
167 self.angles_x = self.angles_x * -1;
171 edist = vlen(self.origin - self.enemy.origin);
172 // Close enougth to do decent damage?
173 if ( edist <= (self.owner.shot_radius * 0.25) )
175 turret_hk_missile_explode();
179 // Get data on enemy position
180 pre_pos = self.enemy.origin +
181 self.enemy.velocity *
182 min((vlen(self.enemy.origin - self.origin) / vlen(self.velocity)),0.5);
184 traceline(self.origin, pre_pos,TRUE,self.enemy);
185 ve = normalize(pre_pos - self.origin);
194 if ((fe != 1) || (self.enemy == world) || (edist > 1000))
196 myspeed = vlen(self.velocity);
198 lt_for = myspeed * 3;
199 lt_seek = myspeed * 2.95;
202 traceline(self.origin, self.origin + v_forward * lt_for,FALSE,self);
206 // Find angular offset
207 ad = vlen(vectoangles(normalize(self.enemy.origin - self.origin)) - self.angles);
209 // To close to something, Slow down!
210 if ( ((ff < 0.7) || (ad > 4)) && (myspeed > hk_minspeed) )
211 myspeed = max(myspeed * hk_decel,hk_minspeed);
213 // Failry clear, accelerate.
214 if ( (ff > 0.7) && (myspeed < hk_maxspeed) )
215 myspeed = min(myspeed * hk_accel,hk_maxspeed);
219 pt_seek = bound(0.15,pt_seek,0.8);
220 if (ff < 0.5) pt_seek = 1;
223 traceline(self.origin, self.origin + (-1 * (v_right * pt_seek) + (v_forward * ff)) * lt_seek,FALSE,self);
228 traceline(self.origin, self.origin + ((v_right * pt_seek) + (v_forward * ff)) * lt_seek ,FALSE,self);
233 traceline(self.origin, self.origin + ((v_up * pt_seek) + (v_forward * ff)) * lt_seek ,FALSE,self);
238 traceline(self.origin, self.origin + (-1 * (v_up * pt_seek) + (v_forward * ff)) * lt_seek ,FALSE,self);
242 vl = normalize(vl - self.origin);
243 vr = normalize(vr - self.origin);
244 vu = normalize(vu - self.origin);
245 vd = normalize(vd - self.origin);
247 // Panic tresh passed, find a single direction and turn as hard as we can
251 if (fl > fr) wishdir = -1 * v_right;
252 if (fu > fl) wishdir = v_up;
253 if (fd > fu) wishdir = -1 * v_up;
257 // Normalize our trace vectors to make a smooth path
258 wishdir = normalize( (vl * fl) + (vr * fr) + (vu * fu) + (vd * fd) );
263 if (fe < 0.1) fe = 0.1; // Make sure we always try to move sligtly towards our target
264 wishdir = (wishdir * (1 - fe)) + (ve * fe);
269 // Got a clear path to target, speed up fast (if not at full speed) and go straight for it.
270 myspeed = vlen(self.velocity);
271 if (myspeed < hk_maxspeed)
272 myspeed = min(myspeed * hk_accel2,hk_maxspeed);
277 if ((myspeed > hk_minspeed) && (self.cnt > time))
278 myspeed = min(myspeed * hk_accel2,hk_maxspeed);
283 self.cnt = time + 0.25;
285 self.movetype = MOVETYPE_BOUNCE;
289 // Calculate new heading
290 olddir = normalize(self.velocity);
291 newdir = normalize(olddir + wishdir * autocvar_g_turrets_unit_hk_std_shot_speed_turnrate);
293 // Set heading & speed
294 self.velocity = newdir * myspeed;
296 // Align model with new heading
297 self.angles = vectoangles(self.velocity);
300 #ifdef TURRET_DEBUG_HK
301 //if(self.atime < time) {
302 if ((fe <= 0.99)||(edist > 1000))
304 te_lightning2(world,self.origin, self.origin + vr * lt_seek);
305 te_lightning2(world,self.origin, self.origin + vl * lt_seek);
306 te_lightning2(world,self.origin, self.origin + vu * lt_seek);
307 te_lightning2(world,self.origin, self.origin + vd * lt_seek);
308 te_lightning2(world,self.origin, vf);
312 te_lightning2(world,self.origin, self.enemy.origin);
314 bprint("Speed: ", ftos(rint(myspeed)), "\n");
315 bprint("Trace to solid: ", ftos(rint(ff * 100)), "%\n");
316 bprint("Trace to target:", ftos(rint(fe * 100)), "%\n");
317 self.atime = time + 0.2;
321 UpdateCSQCProjectile(self);
324 void turret_hk_missile_explode()
328 if(self.event_damage != SUB_Null)
330 self.event_damage = SUB_Null;
331 self.think = turret_hk_missile_explode;
332 self.nextthink = time;
336 if ((other == self.owner)||(other == self.owner.tur_head))
339 self.event_damage = SUB_Null;
340 d = RadiusDamage (self, self.owner, self.owner.shot_dmg, 0, self.owner.shot_radius, world, self.owner.shot_force, DEATH_TURRET_HK, world);
343 self.owner.tur_dbg_dmg_t_h = self.owner.tur_dbg_dmg_t_h + d; //self.owner.shot_dmg;
344 self.owner.tur_dbg_dmg_t_f = self.owner.tur_dbg_dmg_t_f + self.owner.shot_dmg;
347 // Target dead, get another is still targeting the same.
348 if ((self.enemy.deadflag != DEAD_NO) && (self.enemy == self.owner.enemy))
349 self.owner.enemy = world;
354 void turret_hk_postthink()
356 if (autocvar_g_turrets_reloadcvars)
358 hk_maxspeed = autocvar_g_turrets_unit_hk_std_shot_speed_max;
359 hk_minspeed = autocvar_g_turrets_unit_hk_std_shot_speed;
360 hk_accel = autocvar_g_turrets_unit_hk_std_shot_speed_accel;
361 hk_accel2 = autocvar_g_turrets_unit_hk_std_shot_speed_accel2;
362 hk_decel = autocvar_g_turrets_unit_hk_std_shot_speed_decel;
365 if (self.tur_head.frame != 0)
366 self.tur_head.frame = self.tur_head.frame + 1;
368 if (self.tur_head.frame > 5)
369 self.tur_head.frame = 0;
373 void turret_hk_dinit()
375 if (self.netname == "") self.netname = "Hunter-killer turret";
377 hk_maxspeed = autocvar_g_turrets_unit_hk_std_shot_speed_max;
378 hk_minspeed = autocvar_g_turrets_unit_hk_std_shot_speed;
379 hk_accel = autocvar_g_turrets_unit_hk_std_shot_speed_accel;
380 hk_accel2 = autocvar_g_turrets_unit_hk_std_shot_speed_accel2;
381 hk_decel = autocvar_g_turrets_unit_hk_std_shot_speed_decel;
383 self.turrcaps_flags = TFL_TURRCAPS_RADIUSDMG | TFL_TURRCAPS_MEDPROJ | TFL_TURRCAPS_PLAYERKILL | TFL_TURRCAPS_RECIVETARGETS;
385 self.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE;
387 self.aim_flags = TFL_AIM_SIMPLE;
389 self.target_select_flags = TFL_TARGETSELECT_LOS | TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TRIGGERTARGET | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK;
391 self.firecheck_flags = TFL_FIRECHECK_WORLD | TFL_FIRECHECK_DEAD | TFL_FIRECHECK_TEAMCECK | TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_AFF;
393 self.target_select_flags = TFL_TARGETSELECT_LOS | TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TRIGGERTARGET | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK;
395 self.shoot_flags = TFL_SHOOT_CLEARTARGET;
397 if (turret_stdproc_init("hk_std", "models/turrets/base.md3", "models/turrets/hk.md3", TID_HK) == 0)
403 self.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TEAMCHECK;
406 self.turret_firefunc = turret_hk_attack;
408 // re-color badge & handle recoil effect
409 self.turret_postthink = turret_hk_postthink;
411 // What to do when reciveing foreign target data
412 self.turret_addtarget = turret_hk_addtarget;
416 /*QUAKED turret_hk (0 .5 .8) ?
417 * Turret that fires Hunter-killer missiles.
418 * Missiles seek their target and try to avoid obstacles. If target dies early, they
419 * pick a new one on their own.
422 void spawnfunc_turret_hk()
424 precache_model ("models/turrets/base.md3");
425 precache_model ("models/turrets/hk.md3");
427 self.think = turret_hk_dinit;
428 self.nextthink = time + 0.5;