Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
hk_weapon.qc File Reference
#include "hk_weapon.qh"
Include dependency graph for hk_weapon.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool hk_is_valid_target (entity this, entity proj, entity targ)
 SOUND (HunterKillerAttack_FIRE, W_Sound("rocket_fire"))
void turret_hk_missile_think (entity this)

Variables

float autocvar_g_turrets_unit_hk_shot_speed
float autocvar_g_turrets_unit_hk_shot_speed_accel
float autocvar_g_turrets_unit_hk_shot_speed_accel2
float autocvar_g_turrets_unit_hk_shot_speed_decel
float autocvar_g_turrets_unit_hk_shot_speed_max
float autocvar_g_turrets_unit_hk_shot_speed_turnrate

Function Documentation

◆ hk_is_valid_target()

bool hk_is_valid_target ( entity this,
entity proj,
entity targ )

Definition at line 241 of file hk_weapon.qc.

242{
243 if (!targ)
244 return false;
245 if (is_pure(targ)) // we know for sure pure entities are bad targets
246 return false;
247 if (targ.flags & FL_NOTARGET) // If only this was used more..
248 return false;
249
250 if (targ.takedamage == DAMAGE_NO || GetResource(targ, RES_HEALTH) < 0) // Cant touch this
251 return false;
252
253 if (IS_PLAYER(targ)) // player
254 {
255 if (this.target_select_playerbias < 0)
256 return false;
257
258 if (IS_DEAD(targ))
259 return false;
260 }
261
262 if ((targ.flags & FL_PROJECTILE) && this.target_select_missilebias < 0) // Missile
263 return false;
264
265 if (SAME_TEAM(targ, this) || SAME_TEAM(this, targ.owner)) // Team check
266 return false;
267
268 return true;
269}
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
#define IS_DEAD(s)
Definition player.qh:244
#define IS_PLAYER(s)
Definition player.qh:242
const int FL_PROJECTILE
Definition constants.qh:85
const int FL_NOTARGET
Definition constants.qh:76
#define is_pure(e)
Definition oo.qh:16
const int DAMAGE_NO
Definition subs.qh:79
#define SAME_TEAM(a, b)
Definition teams.qh:241

References DAMAGE_NO, entity(), FL_NOTARGET, FL_PROJECTILE, GetResource(), IS_DEAD, IS_PLAYER, is_pure, and SAME_TEAM.

Referenced by turret_hk_missile_think().

◆ SOUND()

SOUND ( HunterKillerAttack_FIRE ,
W_Sound("rocket_fire")  )

◆ turret_hk_missile_think()

void turret_hk_missile_think ( entity this)

Definition at line 47 of file hk_weapon.qc.

48{
49 vector vu, vd, vf, vl, vr, ve; // Vector (direction)
50 float fu, fd, ff, fl, fr, fe; // Fraction to solid
51 vector olddir, wishdir, newdir; // Final direction
52 float lt_for; // Length of Trace FORwrad
53 float lt_seek; // Length of Trace SEEK (left, right, up down)
54 float pt_seek; // Pitch of Trace SEEK (How mutch to angele left, right up, down trace towards v_forward)
55 float myspeed;
56
57 this.nextthink = time;
58
59 //if (this.cnt < time)
60 // turret_hk_missile_explode();
61
62 if (IS_DEAD(this.enemy) || IS_SPEC(this.enemy) || IS_OBSERVER(this.enemy))
63 this.enemy = NULL;
64
65 // Pick the closest valid target.
66 if (!this.enemy)
67 {
68 // in this case, the lighter check is to validate it first, and check distance if it is valid
70 {
71 if (vdist(it.origin, >, 5000))
72 continue;
73
74 if (!this.enemy)
75 this.enemy = it;
76 else if (vlen2(this.origin - it.origin) < vlen2(this.origin - this.enemy.origin))
77 this.enemy = it;
78 });
79 }
80
81 this.angles = vectoangles(this.velocity);
82 this.angles.x = -this.angles.x;
83 makevectors(this.angles);
84 this.angles.x = -this.angles.x;
85
86 if (this.enemy)
87 {
88 // Close enougth to do decent damage?
89 if (vdist(this.origin - this.enemy.origin, <=, (this.owner.shot_radius * 0.25)))
90 {
92 return;
93 }
94
95 // Get data on enemy position
96 vector pre_pos = this.enemy.origin
97 + this.enemy.velocity * min(vlen(this.enemy.origin - this.origin) / vlen(this.velocity), 0.5);
98
99 traceline(this.origin, pre_pos, true, this.enemy);
100 ve = normalize(pre_pos - this.origin);
101 fe = trace_fraction;
102 }
103 else
104 {
105 ve = '0 0 0';
106 fe = 0;
107 }
108
109 if (fe != 1 || this.enemy == NULL || vdist(this.origin - this.enemy.origin, >, 1000))
110 {
111 myspeed = vlen(this.velocity);
112
113 lt_for = myspeed * 3;
114 lt_seek = myspeed * 2.95;
115
116 // Trace forward
117 traceline(this.origin, this.origin + v_forward * lt_for, false, this);
118 vf = trace_endpos;
119 ff = trace_fraction;
120
121 // Find angular offset
122 float ad = vlen(vectoangles(normalize(this.enemy.origin - this.origin)) - this.angles);
123
124 // To close to something, Slow down!
125 if ((ff < 0.7 || ad > 4)
128
129 // Failry clear, accelerate.
130 if (ff > 0.7
133
134 // Setup trace pitch
135 pt_seek = bound(0.15, 1 - ff, 0.8);
136 if (ff < 0.5)
137 pt_seek = 1;
138
139 // Trace left
140 traceline(this.origin, this.origin + (-(v_right * pt_seek) + (v_forward * ff)) * lt_seek, false, this);
141 vl = trace_endpos;
142 fl = trace_fraction;
143
144 // Trace right
145 traceline(this.origin, this.origin + ((v_right * pt_seek) + (v_forward * ff)) * lt_seek, false, this);
146 vr = trace_endpos;
147 fr = trace_fraction;
148
149 // Trace up
150 traceline(this.origin, this.origin + ((v_up * pt_seek) + (v_forward * ff)) * lt_seek, false, this);
151 vu = trace_endpos;
152 fu = trace_fraction;
153
154 // Trace down
155 traceline(this.origin, this.origin + (-(v_up * pt_seek) + (v_forward * ff)) * lt_seek, false, this);
156 vd = trace_endpos;
157 fd = trace_fraction;
158
159 vl = normalize(vl - this.origin);
160 vr = normalize(vr - this.origin);
161 vu = normalize(vu - this.origin);
162 vd = normalize(vd - this.origin);
163
164 // Panic tresh passed, find a single direction and turn as hard as we can
165 if (pt_seek == 1)
166 {
167 wishdir = v_right;
168 if (fl > fr) wishdir = -v_right;
169 if (fu > fl) wishdir = v_up;
170 if (fd > fu) wishdir = -v_up;
171 }
172 else
173 {
174 // Normalize our trace vectors to make a smooth path
175 wishdir = normalize((vl * fl) + (vr * fr) + (vu * fu) + (vd * fd));
176 }
177
178 if (this.enemy)
179 {
180 if (fe < 0.1)
181 fe = 0.1; // Make sure we always try to move sligtly towards our target
182 wishdir = wishdir * (1 - fe) + (ve * fe);
183 }
184 }
185 else
186 {
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);
191
192 wishdir = ve;
193 }
194
195 if (myspeed > autocvar_g_turrets_unit_hk_shot_speed && this.cnt > time)
197
198 // Ranoutagazfish?
199 if (this.cnt < time)
200 {
201 this.cnt = time + 0.25;
202 this.nextthink = 0;
204 return;
205 }
206
207 // Calculate new heading
208 olddir = normalize(this.velocity);
210
211 // Set heading & speed
212 this.velocity = newdir * myspeed;
213
214 // Align model with new heading
215 this.angles = vectoangles(this.velocity);
216
217
218#ifdef TURRET_DEBUG_HK
219 //if (this.atime < time) {
220 if (fe <= 0.99 || vdist(this.origin - this.enemy.origin, >, 1000))
221 {
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);
227 }
228 else
229 te_lightning2(NULL, this.origin, this.enemy.origin);
230
231 bprint("Speed: ", ftos(rint(myspeed)), "\n");
232 bprint("Trace to solid: ", ftos(rint(ff * 100)), "%\n");
233 bprint("Trace to target:", ftos(rint(fe * 100)), "%\n");
234 this.atime = time + 0.2;
235 //}
236#endif
237
239}
float cnt
Definition powerups.qc:24
entity owner
Definition main.qh:87
vector v_up
vector velocity
float time
vector v_right
vector trace_endpos
float nextthink
vector v_forward
vector origin
float trace_fraction
void UpdateCSQCProjectile(entity e)
IntrusiveList g_damagedbycontents
Definition damage.qh:143
ent angles
Definition ent_cs.qc:121
float autocvar_g_turrets_unit_hk_shot_speed_decel
Definition hk_weapon.qc:8
float autocvar_g_turrets_unit_hk_shot_speed_accel2
Definition hk_weapon.qc:7
float autocvar_g_turrets_unit_hk_shot_speed_turnrate
Definition hk_weapon.qc:10
float autocvar_g_turrets_unit_hk_shot_speed_accel
Definition hk_weapon.qc:6
float autocvar_g_turrets_unit_hk_shot_speed_max
Definition hk_weapon.qc:9
float autocvar_g_turrets_unit_hk_shot_speed
Definition hk_weapon.qc:5
bool hk_is_valid_target(entity this, entity proj, entity targ)
Definition hk_weapon.qc:241
#define IL_EACH(this, cond, body)
float bound(float min, float value, float max)
void bprint(string text,...)
float vlen(vector v)
vector vectoangles(vector v)
float min(float f,...)
float rint(float f)
vector normalize(vector v)
string ftos(float f)
float max(float f,...)
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
const int MOVETYPE_BOUNCE
Definition movetypes.qh:139
#define NULL
Definition post.qh:14
#define makevectors
Definition post.qh:21
vector
Definition self.qh:92
entity enemy
Definition sv_ctf.qh:153
void turret_projectile_explode(entity this)
#define IS_OBSERVER(v)
Definition utils.qh:11
#define IS_SPEC(v)
Definition utils.qh:10
#define vlen2(v)
Definition vector.qh:4
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition vector.qh:8

References angles, autocvar_g_turrets_unit_hk_shot_speed, autocvar_g_turrets_unit_hk_shot_speed_accel, autocvar_g_turrets_unit_hk_shot_speed_accel2, autocvar_g_turrets_unit_hk_shot_speed_decel, autocvar_g_turrets_unit_hk_shot_speed_max, autocvar_g_turrets_unit_hk_shot_speed_turnrate, bound(), bprint(), cnt, enemy, entity(), ftos(), g_damagedbycontents, hk_is_valid_target(), IL_EACH, IS_DEAD, IS_OBSERVER, IS_SPEC, makevectors, max(), min(), MOVETYPE_BOUNCE, nextthink, normalize(), NULL, origin, owner, rint(), set_movetype(), time, trace_endpos, trace_fraction, turret_projectile_explode(), UpdateCSQCProjectile(), v_forward, v_right, v_up, vdist, vectoangles(), vector, velocity, vlen(), and vlen2.

Variable Documentation

◆ autocvar_g_turrets_unit_hk_shot_speed

float autocvar_g_turrets_unit_hk_shot_speed

Definition at line 5 of file hk_weapon.qc.

Referenced by turret_hk_missile_think().

◆ autocvar_g_turrets_unit_hk_shot_speed_accel

float autocvar_g_turrets_unit_hk_shot_speed_accel

Definition at line 6 of file hk_weapon.qc.

Referenced by turret_hk_missile_think().

◆ autocvar_g_turrets_unit_hk_shot_speed_accel2

float autocvar_g_turrets_unit_hk_shot_speed_accel2

Definition at line 7 of file hk_weapon.qc.

Referenced by turret_hk_missile_think().

◆ autocvar_g_turrets_unit_hk_shot_speed_decel

float autocvar_g_turrets_unit_hk_shot_speed_decel

Definition at line 8 of file hk_weapon.qc.

Referenced by turret_hk_missile_think().

◆ autocvar_g_turrets_unit_hk_shot_speed_max

float autocvar_g_turrets_unit_hk_shot_speed_max

Definition at line 9 of file hk_weapon.qc.

Referenced by turret_hk_missile_think().

◆ autocvar_g_turrets_unit_hk_shot_speed_turnrate

float autocvar_g_turrets_unit_hk_shot_speed_turnrate

Definition at line 10 of file hk_weapon.qc.

Referenced by turret_hk_missile_think().