1 #include "hk_weapon.qh"
7 float autocvar_g_turrets_unit_hk_shot_speed;
8 float autocvar_g_turrets_unit_hk_shot_speed_accel;
9 float autocvar_g_turrets_unit_hk_shot_speed_accel2;
10 float autocvar_g_turrets_unit_hk_shot_speed_decel;
11 float autocvar_g_turrets_unit_hk_shot_speed_max;
12 float autocvar_g_turrets_unit_hk_shot_speed_turnrate;
14 void turret_hk_missile_think(entity this);
15 SOUND(HunterKillerAttack_FIRE, W_Sound("electro_fire"));
16 METHOD(HunterKillerAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
18 bool isPlayer = IS_PLAYER(actor);
20 if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) {
22 turret_initparams(actor);
23 W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_HunterKillerAttack_FIRE, CH_WEAPON_B, 0);
24 actor.tur_shotdir_updated = w_shotdir;
25 actor.tur_shotorg = w_shotorg;
26 actor.tur_head = actor;
27 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
29 entity missile = turret_projectile(actor, SND_ROCKET_FIRE, 6, 10, DEATH_TURRET_HK.m_id, PROJECTILE_ROCKET, false, false);
30 te_explosion (missile.origin);
32 setthink(missile, turret_hk_missile_think);
33 missile.nextthink = time + 0.25;
34 set_movetype(missile, MOVETYPE_BOUNCEMISSILE);
35 missile.velocity = actor.tur_shotdir_updated * (actor.shot_speed * 0.75);
36 missile.angles = vectoangles(missile.velocity);
37 missile.cnt = time + 30;
38 missile.ticrate = max(autocvar_sys_ticrate, 0.05);
39 missile.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_AI;
42 if (actor.tur_head.frame == 0)
43 actor.tur_head.frame = actor.tur_head.frame + 1;
47 bool hk_is_valid_target(entity this, entity proj, entity targ);
48 void turret_hk_missile_think(entity this)
50 vector vu, vd, vf, vl, vr, ve; // Vector (direction)
51 float fu, fd, ff, fl, fr, fe; // Fraction to solid
52 vector olddir,wishdir,newdir; // Final direction
53 float lt_for; // Length of Trace FORwrad
54 float lt_seek; // Length of Trace SEEK (left, right, up down)
55 float pt_seek; // Pitch of Trace SEEK (How mutch to angele left, right up, down trace towards v_forward)
58 this.nextthink = time + this.ticrate;
60 //if (this.cnt < time)
61 // turret_hk_missile_explode();
63 if (IS_DEAD(this.enemy))
66 // Pick the closest valid target.
69 // in this case, the lighter check is to validate it first, and check distance if it is valid
70 IL_EACH(g_damagedbycontents, hk_is_valid_target(this.owner, this, it),
72 if(vdist(it.origin, >, 5000))
77 else if(vlen2(this.origin - it.origin) < vlen2(this.origin - this.enemy.origin))
82 this.angles = vectoangles(this.velocity);
83 this.angles_x = this.angles_x * -1;
84 makevectors(this.angles);
85 this.angles_x = this.angles_x * -1;
89 // Close enougth to do decent damage?
90 if(vdist(this.origin - this.enemy.origin, <=, (this.owner.shot_radius * 0.25)))
92 turret_projectile_explode(this);
96 // Get data on enemy position
97 vector pre_pos = this.enemy.origin +
99 min((vlen(this.enemy.origin - this.origin) / vlen(this.velocity)),0.5);
101 traceline(this.origin, pre_pos,true,this.enemy);
102 ve = normalize(pre_pos - this.origin);
112 if ((fe != 1) || (this.enemy == NULL) || vdist(this.origin - this.enemy.origin, >, 1000))
114 myspeed = vlen(this.velocity);
116 lt_for = myspeed * 3;
117 lt_seek = myspeed * 2.95;
120 traceline(this.origin, this.origin + v_forward * lt_for,false,this);
124 // Find angular offset
125 float ad = vlen(vectoangles(normalize(this.enemy.origin - this.origin)) - this.angles);
127 // To close to something, Slow down!
128 if ( ((ff < 0.7) || (ad > 4)) && (myspeed > (autocvar_g_turrets_unit_hk_shot_speed)) )
129 myspeed = max(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_decel), (autocvar_g_turrets_unit_hk_shot_speed));
131 // Failry clear, accelerate.
132 if ( (ff > 0.7) && (myspeed < (autocvar_g_turrets_unit_hk_shot_speed_max)) )
133 myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel), (autocvar_g_turrets_unit_hk_shot_speed_max));
137 pt_seek = bound(0.15,pt_seek,0.8);
138 if (ff < 0.5) pt_seek = 1;
141 traceline(this.origin, this.origin + (-1 * (v_right * pt_seek) + (v_forward * ff)) * lt_seek,false,this);
146 traceline(this.origin, this.origin + ((v_right * pt_seek) + (v_forward * ff)) * lt_seek ,false,this);
151 traceline(this.origin, this.origin + ((v_up * pt_seek) + (v_forward * ff)) * lt_seek ,false,this);
156 traceline(this.origin, this.origin + (-1 * (v_up * pt_seek) + (v_forward * ff)) * lt_seek ,false,this);
160 vl = normalize(vl - this.origin);
161 vr = normalize(vr - this.origin);
162 vu = normalize(vu - this.origin);
163 vd = normalize(vd - this.origin);
165 // Panic tresh passed, find a single direction and turn as hard as we can
169 if (fl > fr) wishdir = -1 * v_right;
170 if (fu > fl) wishdir = v_up;
171 if (fd > fu) wishdir = -1 * v_up;
175 // Normalize our trace vectors to make a smooth path
176 wishdir = normalize( (vl * fl) + (vr * fr) + (vu * fu) + (vd * fd) );
181 if (fe < 0.1) fe = 0.1; // Make sure we always try to move sligtly towards our target
182 wishdir = (wishdir * (1 - fe)) + (ve * fe);
187 // Got a clear path to target, speed up fast (if not at full speed) and go straight for it.
188 myspeed = vlen(this.velocity);
189 if (myspeed < (autocvar_g_turrets_unit_hk_shot_speed_max))
190 myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel2),(autocvar_g_turrets_unit_hk_shot_speed_max));
195 if ((myspeed > (autocvar_g_turrets_unit_hk_shot_speed)) && (this.cnt > time))
196 myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel2),(autocvar_g_turrets_unit_hk_shot_speed_max));
201 this.cnt = time + 0.25;
203 set_movetype(this, MOVETYPE_BOUNCE);
207 // Calculate new heading
208 olddir = normalize(this.velocity);
209 newdir = normalize(olddir + wishdir * (autocvar_g_turrets_unit_hk_shot_speed_turnrate));
211 // Set heading & speed
212 this.velocity = newdir * myspeed;
214 // Align model with new heading
215 this.angles = vectoangles(this.velocity);
218 #ifdef TURRET_DEBUG_HK
219 //if(this.atime < time) {
220 if ((fe <= 0.99)||vdist(this.origin - this.enemy.origin, >, 1000))
222 te_lightning2(NULL,this.origin, this.origin + vr * lt_seek);
223 te_lightning2(NULL,this.origin, this.origin + vl * lt_seek);
224 te_lightning2(NULL,this.origin, this.origin + vu * lt_seek);
225 te_lightning2(NULL,this.origin, this.origin + vd * lt_seek);
226 te_lightning2(NULL,this.origin, vf);
230 te_lightning2(NULL,this.origin, this.enemy.origin);
232 bprint("Speed: ", ftos(rint(myspeed)), "\n");
233 bprint("Trace to solid: ", ftos(rint(ff * 100)), "%\n");
234 bprint("Trace to target:", ftos(rint(fe * 100)), "%\n");
235 this.atime = time + 0.2;
239 UpdateCSQCProjectile(this);
242 bool hk_is_valid_target(entity this, entity proj, entity targ)
247 // we know for sure pure entities are bad targets
251 // If only this was used more..
252 if (targ.flags & FL_NOTARGET)
256 if ((targ.takedamage == DAMAGE_NO) || (targ.health < 0))
262 if (this.target_select_playerbias < 0)
270 if ((targ.flags & FL_PROJECTILE) && (this.target_select_missilebias < 0))
274 if ((targ.team == this.team) || (this.team == targ.owner.team))