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 239 of file hk_weapon.qc.

240{
241 if (!targ)
242 return false;
243
244 // we know for sure pure entities are bad targets
245 if(is_pure(targ))
246 return false;
247
248 // If only this was used more..
249 if (targ.flags & FL_NOTARGET)
250 return false;
251
252 // Cant touch this
253 if ((targ.takedamage == DAMAGE_NO) || (GetResource(targ, RES_HEALTH) < 0))
254 return false;
255
256 // player
257 if (IS_PLAYER(targ))
258 {
259 if (this.target_select_playerbias < 0)
260 return false;
261
262 if (IS_DEAD(targ))
263 return false;
264 }
265
266 // Missile
267 if ((targ.flags & FL_PROJECTILE) && (this.target_select_missilebias < 0))
268 return false;
269
270 // Team check
271 if ((targ.team == this.team) || (this.team == targ.owner.team))
272 return false;
273
274 return true;
275}
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
#define IS_DEAD(s)
Definition player.qh:245
#define IS_PLAYER(s)
Definition player.qh:243
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

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

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 45 of file hk_weapon.qc.

46{
47 vector vu, vd, vf, vl, vr, ve; // Vector (direction)
48 float fu, fd, ff, fl, fr, fe; // Fraction to solid
49 vector olddir,wishdir,newdir; // Final direction
50 float lt_for; // Length of Trace FORwrad
51 float lt_seek; // Length of Trace SEEK (left, right, up down)
52 float pt_seek; // Pitch of Trace SEEK (How mutch to angele left, right up, down trace towards v_forward)
53 float myspeed;
54
55 this.nextthink = time;
56
57 //if (this.cnt < time)
58 // turret_hk_missile_explode();
59
60 if (IS_DEAD(this.enemy) || IS_SPEC(this.enemy) || IS_OBSERVER(this.enemy))
61 this.enemy = NULL;
62
63 // Pick the closest valid target.
64 if (!this.enemy)
65 {
66 // in this case, the lighter check is to validate it first, and check distance if it is valid
68 {
69 if(vdist(it.origin, >, 5000))
70 continue;
71
72 if(!this.enemy)
73 this.enemy = it;
74 else if(vlen2(this.origin - it.origin) < vlen2(this.origin - this.enemy.origin))
75 this.enemy = it;
76 });
77 }
78
79 this.angles = vectoangles(this.velocity);
80 this.angles_x = this.angles_x * -1;
81 makevectors(this.angles);
82 this.angles_x = this.angles_x * -1;
83
84 if (this.enemy)
85 {
86 // Close enougth to do decent damage?
87 if(vdist(this.origin - this.enemy.origin, <=, (this.owner.shot_radius * 0.25)))
88 {
90 return;
91 }
92
93 // Get data on enemy position
94 vector pre_pos = this.enemy.origin +
95 this.enemy.velocity *
96 min((vlen(this.enemy.origin - this.origin) / vlen(this.velocity)),0.5);
97
98 traceline(this.origin, pre_pos,true,this.enemy);
99 ve = normalize(pre_pos - this.origin);
100 fe = trace_fraction;
101
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)) && (myspeed > (autocvar_g_turrets_unit_hk_shot_speed)) )
127
128 // Failry clear, accelerate.
129 if ( (ff > 0.7) && (myspeed < (autocvar_g_turrets_unit_hk_shot_speed_max)) )
131
132 // Setup trace pitch
133 pt_seek = 1 - ff;
134 pt_seek = bound(0.15,pt_seek,0.8);
135 if (ff < 0.5) pt_seek = 1;
136
137 // Trace left
138 traceline(this.origin, this.origin + (-1 * (v_right * pt_seek) + (v_forward * ff)) * lt_seek,false,this);
139 vl = trace_endpos;
140 fl = trace_fraction;
141
142 // Trace right
143 traceline(this.origin, this.origin + ((v_right * pt_seek) + (v_forward * ff)) * lt_seek ,false,this);
144 vr = trace_endpos;
145 fr = trace_fraction;
146
147 // Trace up
148 traceline(this.origin, this.origin + ((v_up * pt_seek) + (v_forward * ff)) * lt_seek ,false,this);
149 vu = trace_endpos;
150 fu = trace_fraction;
151
152 // Trace down
153 traceline(this.origin, this.origin + (-1 * (v_up * pt_seek) + (v_forward * ff)) * lt_seek ,false,this);
154 vd = trace_endpos;
155 fd = trace_fraction;
156
157 vl = normalize(vl - this.origin);
158 vr = normalize(vr - this.origin);
159 vu = normalize(vu - this.origin);
160 vd = normalize(vd - this.origin);
161
162 // Panic tresh passed, find a single direction and turn as hard as we can
163 if (pt_seek == 1)
164 {
165 wishdir = v_right;
166 if (fl > fr) wishdir = -1 * v_right;
167 if (fu > fl) wishdir = v_up;
168 if (fd > fu) wishdir = -1 * v_up;
169 }
170 else
171 {
172 // Normalize our trace vectors to make a smooth path
173 wishdir = normalize( (vl * fl) + (vr * fr) + (vu * fu) + (vd * fd) );
174 }
175
176 if (this.enemy)
177 {
178 if (fe < 0.1) fe = 0.1; // Make sure we always try to move sligtly towards our target
179 wishdir = (wishdir * (1 - fe)) + (ve * fe);
180 }
181 }
182 else
183 {
184 // Got a clear path to target, speed up fast (if not at full speed) and go straight for it.
185 myspeed = vlen(this.velocity);
188
189 wishdir = ve;
190 }
191
192 if ((myspeed > (autocvar_g_turrets_unit_hk_shot_speed)) && (this.cnt > time))
194
195 // Ranoutagazfish?
196 if (this.cnt < time)
197 {
198 this.cnt = time + 0.25;
199 this.nextthink = 0;
201 return;
202 }
203
204 // Calculate new heading
205 olddir = normalize(this.velocity);
206 newdir = normalize(olddir + wishdir * (autocvar_g_turrets_unit_hk_shot_speed_turnrate));
207
208 // Set heading & speed
209 this.velocity = newdir * myspeed;
210
211 // Align model with new heading
212 this.angles = vectoangles(this.velocity);
213
214
215#ifdef TURRET_DEBUG_HK
216 //if(this.atime < time) {
217 if ((fe <= 0.99)||vdist(this.origin - this.enemy.origin, >, 1000))
218 {
219 te_lightning2(NULL,this.origin, this.origin + vr * lt_seek);
220 te_lightning2(NULL,this.origin, this.origin + vl * lt_seek);
221 te_lightning2(NULL,this.origin, this.origin + vu * lt_seek);
222 te_lightning2(NULL,this.origin, this.origin + vd * lt_seek);
223 te_lightning2(NULL,this.origin, vf);
224 }
225 else
226 {
227 te_lightning2(NULL,this.origin, this.enemy.origin);
228 }
229 bprint("Speed: ", ftos(rint(myspeed)), "\n");
230 bprint("Trace to solid: ", ftos(rint(ff * 100)), "%\n");
231 bprint("Trace to target:", ftos(rint(fe * 100)), "%\n");
232 this.atime = time + 0.2;
233 //}
234#endif
235
237}
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:135
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:239
#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().