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, 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 missile.movetype = 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 e_target);
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)
61 this.nextthink = time + this.ticrate;
63 //if (this.cnt < time)
64 // turret_hk_missile_explode();
66 if (IS_DEAD(this.enemy))
69 // Pick the closest valid target.
72 e = findradius(this.origin, 5000);
75 if (hk_is_valid_target(this, e))
80 if (vlen2(this.origin - e.origin) < vlen2(this.origin - this.enemy.origin))
87 this.angles = vectoangles(this.velocity);
88 this.angles_x = this.angles_x * -1;
89 makevectors(this.angles);
90 this.angles_x = this.angles_x * -1;
94 edist = vlen(this.origin - this.enemy.origin);
95 // Close enougth to do decent damage?
96 if ( edist <= (this.owner.shot_radius * 0.25) )
98 turret_projectile_explode(this);
102 // Get data on enemy position
103 pre_pos = this.enemy.origin +
104 this.enemy.velocity *
105 min((vlen(this.enemy.origin - this.origin) / vlen(this.velocity)),0.5);
107 traceline(this.origin, pre_pos,true,this.enemy);
108 ve = normalize(pre_pos - this.origin);
119 if ((fe != 1) || (this.enemy == world) || (edist > 1000))
121 myspeed = vlen(this.velocity);
123 lt_for = myspeed * 3;
124 lt_seek = myspeed * 2.95;
127 traceline(this.origin, this.origin + v_forward * lt_for,false,this);
131 // Find angular offset
132 ad = vlen(vectoangles(normalize(this.enemy.origin - this.origin)) - this.angles);
134 // To close to something, Slow down!
135 if ( ((ff < 0.7) || (ad > 4)) && (myspeed > (autocvar_g_turrets_unit_hk_shot_speed)) )
136 myspeed = max(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_decel), (autocvar_g_turrets_unit_hk_shot_speed));
138 // Failry clear, accelerate.
139 if ( (ff > 0.7) && (myspeed < (autocvar_g_turrets_unit_hk_shot_speed_max)) )
140 myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel), (autocvar_g_turrets_unit_hk_shot_speed_max));
144 pt_seek = bound(0.15,pt_seek,0.8);
145 if (ff < 0.5) pt_seek = 1;
148 traceline(this.origin, this.origin + (-1 * (v_right * pt_seek) + (v_forward * ff)) * lt_seek,false,this);
153 traceline(this.origin, this.origin + ((v_right * pt_seek) + (v_forward * ff)) * lt_seek ,false,this);
158 traceline(this.origin, this.origin + ((v_up * pt_seek) + (v_forward * ff)) * lt_seek ,false,this);
163 traceline(this.origin, this.origin + (-1 * (v_up * pt_seek) + (v_forward * ff)) * lt_seek ,false,this);
167 vl = normalize(vl - this.origin);
168 vr = normalize(vr - this.origin);
169 vu = normalize(vu - this.origin);
170 vd = normalize(vd - this.origin);
172 // Panic tresh passed, find a single direction and turn as hard as we can
176 if (fl > fr) wishdir = -1 * v_right;
177 if (fu > fl) wishdir = v_up;
178 if (fd > fu) wishdir = -1 * v_up;
182 // Normalize our trace vectors to make a smooth path
183 wishdir = normalize( (vl * fl) + (vr * fr) + (vu * fu) + (vd * fd) );
188 if (fe < 0.1) fe = 0.1; // Make sure we always try to move sligtly towards our target
189 wishdir = (wishdir * (1 - fe)) + (ve * fe);
194 // Got a clear path to target, speed up fast (if not at full speed) and go straight for it.
195 myspeed = vlen(this.velocity);
196 if (myspeed < (autocvar_g_turrets_unit_hk_shot_speed_max))
197 myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel2),(autocvar_g_turrets_unit_hk_shot_speed_max));
202 if ((myspeed > (autocvar_g_turrets_unit_hk_shot_speed)) && (this.cnt > time))
203 myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel2),(autocvar_g_turrets_unit_hk_shot_speed_max));
208 this.cnt = time + 0.25;
210 this.movetype = MOVETYPE_BOUNCE;
214 // Calculate new heading
215 olddir = normalize(this.velocity);
216 newdir = normalize(olddir + wishdir * (autocvar_g_turrets_unit_hk_shot_speed_turnrate));
218 // Set heading & speed
219 this.velocity = newdir * myspeed;
221 // Align model with new heading
222 this.angles = vectoangles(this.velocity);
225 #ifdef TURRET_DEBUG_HK
226 //if(this.atime < time) {
227 if ((fe <= 0.99)||(edist > 1000))
229 te_lightning2(world,this.origin, this.origin + vr * lt_seek);
230 te_lightning2(world,this.origin, this.origin + vl * lt_seek);
231 te_lightning2(world,this.origin, this.origin + vu * lt_seek);
232 te_lightning2(world,this.origin, this.origin + vd * lt_seek);
233 te_lightning2(world,this.origin, vf);
237 te_lightning2(world,this.origin, this.enemy.origin);
239 bprint("Speed: ", ftos(rint(myspeed)), "\n");
240 bprint("Trace to solid: ", ftos(rint(ff * 100)), "%\n");
241 bprint("Trace to target:", ftos(rint(fe * 100)), "%\n");
242 this.atime = time + 0.2;
246 UpdateCSQCProjectile(this);
249 bool hk_is_valid_target(entity this, entity e_target)
251 if (e_target == world)
254 // If only this was used more..
255 if (e_target.flags & FL_NOTARGET)
259 if ((e_target.takedamage == DAMAGE_NO) || (e_target.health < 0))
263 if (IS_CLIENT(e_target))
265 if (this.owner.target_select_playerbias < 0)
268 if (IS_DEAD(e_target))
273 if ((e_target.flags & FL_PROJECTILE) && (this.owner.target_select_missilebias < 0))
277 if ((e_target.team == this.owner.team) || (this.owner.team == e_target.owner.team))