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

Go to the source code of this file.

Macros

#define steerlib_pull(ent, point)
 Uniform pull towards a point.
#define steerlib_push(ent, point)
 Uniform push from a point.

Functions

float beamsweep (entity this, vector from, vector dir, float length, float step, float step_up, float step_down)
vector steerlib_arrive (entity this, vector point, float maximal_distance)
 Pull toward a point, The further away, the stronger the pull.
vector steerlib_attract (entity this, vector point, float maximal_distance)
 Pull toward a point increasing the pull the closer we get.
vector steerlib_attract2 (entity this, vector point, float min_influense, float max_distance, float max_influense)
vector steerlib_beamsteer (entity this, vector dir, float length, float step, float step_up, float step_down)
vector steerlib_dodge (entity this, vector point, vector dodge_dir, float min_distance)
 Dodge a point NOTE: doesn't work well.
vector steerlib_flock (entity this, float _radius, float standoff, float separation_force, float flock_force)
vector steerlib_flock2d (entity this, float _radius, float standoff, float separation_force, float flock_force)
 flocking by .flock_id Group will move towards the unified direction while keeping close to eachother.
vector steerlib_repel (entity this, vector point, float maximal_distance)
 Move away from a point.
vector steerlib_standoff (entity this, vector point, float ideal_distance)
 Try to keep at ideal_distance away from point.
vector steerlib_swarm (entity this, float _radius, float standoff, float separation_force, float swarm_force)
 All members want to be in the center, and keep away from eachother.
vector steerlib_traceavoid (entity this, float pitch, float length)
 Steer towards the direction least obstructed.
vector steerlib_traceavoid_flat (entity this, float pitch, float length, vector vofs)
 Steer towards the direction least obstructed.
vector steerlib_wander (entity this, float range, float threshold, vector oldpoint)
 A random heading in a forward semicircle.

Variables

float flock_id
 flocking by .flock_id Group will move towards the unified direction while keeping close to eachother.

Macro Definition Documentation

◆ steerlib_pull

#define steerlib_pull ( ent,
point )
Value:
normalize(point - (ent).origin)
vector origin
vector normalize(vector v)

Uniform pull towards a point.

Definition at line 8 of file steerlib.qc.

Referenced by walker_rocket_loop2(), walker_rocket_loop3(), and walker_rocket_think().

◆ steerlib_push

#define steerlib_push ( ent,
point )
Value:
normalize((ent).origin - point)

Uniform push from a point.

Definition at line 17 of file steerlib.qc.

Function Documentation

◆ beamsweep()

float beamsweep ( entity this,
vector from,
vector dir,
float length,
float step,
float step_up,
float step_down )

Definition at line 310 of file steerlib.qc.

311{
312 vector u = '0 0 1' * step_up;
313 vector d = '0 0 1' * step_down;
314
315 traceline(from + u, from - d,MOVE_NORMAL,this);
316 if(trace_fraction == 1.0)
317 return 0;
318
319 if(!location_isok(trace_endpos, false, false))
320 return 0;
321
323 for(int i = 0; i < length; i += step)
324 {
325
326 vector b = a + dir * step;
327 tracebox(a + u,'-4 -4 -4','4 4 4', b + u,MOVE_NORMAL,this);
328 if(trace_fraction != 1.0)
329 return i / length;
330
331 traceline(b + u, b - d,MOVE_NORMAL,this);
332 if(trace_fraction == 1.0)
333 return i / length;
334
335 if(!location_isok(trace_endpos, false, false))
336 return i / length;
337#ifdef BEAMSTEER_VISUAL
338 te_lightning1(NULL,a+u,b+u);
339 te_lightning1(NULL,b+u,b-d);
340#endif
341 a = trace_endpos;
342 }
343
344 return 1;
345}
const float MOVE_NORMAL
vector trace_endpos
float trace_fraction
#define NULL
Definition post.qh:14
vector
Definition self.qh:92
int dir
Definition impulse.qc:89
bool location_isok(vector point, bool waterok, bool air_isok)
Definition utility.qc:7

References dir, entity(), location_isok(), MOVE_NORMAL, NULL, trace_endpos, trace_fraction, and vector.

Referenced by steerlib_beamsteer().

◆ steerlib_arrive()

vector steerlib_arrive ( entity this,
vector point,
float maximal_distance )

Pull toward a point, The further away, the stronger the pull.

Definition at line 27 of file steerlib.qc.

28{
29 float distance = bound(0.001, vlen(this.origin - point), maximal_distance);
30 vector direction = normalize(point - this.origin);
31 return direction * (distance / maximal_distance);
32}
float bound(float min, float value, float max)
float vlen(vector v)

References bound(), entity(), normalize(), origin, vector, and vlen().

Referenced by ewheel_move_enemy(), steerlib_flock(), steerlib_flock2d(), and steerlib_swarm().

◆ steerlib_attract()

vector steerlib_attract ( entity this,
vector point,
float maximal_distance )

Pull toward a point increasing the pull the closer we get.

Definition at line 37 of file steerlib.qc.

38{
39 float distance = bound(0.001, vlen(this.origin - point), maximal_distance);
40 vector direction = normalize(point - this.origin);
41
42 return direction * (1 - (distance / maximal_distance));
43}

References bound(), entity(), normalize(), origin, vector, and vlen().

◆ steerlib_attract2()

vector steerlib_attract2 ( entity this,
vector point,
float min_influense,
float max_distance,
float max_influense )

Definition at line 45 of file steerlib.qc.

46{
47 float distance = bound(0.00001, vlen(this.origin - point), max_distance);
48 vector direction = normalize(point - this.origin);
49
50 float influense = 1 - (distance / max_distance);
51 influense = min_influense + (influense * (max_influense - min_influense));
52
53 return direction * influense;
54}

References bound(), entity(), normalize(), origin, vector, and vlen().

Referenced by ewheel_move_path(), Monster_Move(), walker_move_path(), and walker_move_to().

◆ steerlib_beamsteer()

vector steerlib_beamsteer ( entity this,
vector dir,
float length,
float step,
float step_up,
float step_down )

Definition at line 347 of file steerlib.qc.

348{
349 dir.z *= 0.15;
350 vector vr = vectoangles(dir);
351 //vr.x *= -1;
352
353 tracebox(this.origin + '0 0 1' * step_up, this.mins, this.maxs, ('0 0 1' * step_up) + this.origin + (dir * length), MOVE_NOMONSTERS, this);
354 if(trace_fraction == 1.0)
355 {
356 //te_lightning1(this,this.origin,this.origin + (dir * length));
357 return dir;
358 }
359
360 makevectors(vr);
361 float bm_forward = beamsweep(this, this.origin, v_forward, length, step, step_up, step_down);
362
363 vr = normalize(v_forward + v_right * 0.125);
364 vector vl = normalize(v_forward - v_right * 0.125);
365
366 float bm_right = beamsweep(this, this.origin, vr, length, step, step_up, step_down);
367 float bm_left = beamsweep(this, this.origin, vl, length, step, step_up, step_down);
368
369 float p = bm_left + bm_right;
370 if(p == 2)
371 {
372 //te_lightning1(this,this.origin + '0 0 32',this.origin + '0 0 32' + vr * length);
373 //te_lightning1(this.tur_head,this.origin + '0 0 32',this.origin + '0 0 32' + vl * length);
374
375 return v_forward;
376 }
377
378 p = 2 - p;
379
380 vr = normalize(v_forward + v_right * p);
381 vl = normalize(v_forward - v_right * p);
382 bm_right = beamsweep(this, this.origin, vr, length, step, step_up, step_down);
383 bm_left = beamsweep(this, this.origin, vl, length, step, step_up, step_down);
384
385
386 if(bm_left + bm_right < 0.15)
387 {
388 vr = normalize((v_forward*-1) + v_right * 0.90);
389 vl = normalize((v_forward*-1) - v_right * 0.90);
390
391 bm_right = beamsweep(this, this.origin, vr, length, step, step_up, step_down);
392 bm_left = beamsweep(this, this.origin, vl, length, step, step_up, step_down);
393 }
394
395 //te_lightning1(this,this.origin + '0 0 32',this.origin + '0 0 32' + vr * length);
396 //te_lightning1(this.tur_head,this.origin + '0 0 32',this.origin + '0 0 32' + vl * length);
397
398 bm_forward *= bm_forward;
399 bm_right *= bm_right;
400 bm_left *= bm_left;
401
402 vr = vr * bm_right;
403 vl = vl * bm_left;
404
405 return normalize(vr + vl);
406}
const float MOVE_NOMONSTERS
vector mins
vector v_right
vector maxs
vector v_forward
vector vectoangles(vector v)
#define makevectors
Definition post.qh:21
float beamsweep(entity this, vector from, vector dir, float length, float step, float step_up, float step_down)
Definition steerlib.qc:310

References beamsweep(), dir, entity(), makevectors, maxs, mins, MOVE_NOMONSTERS, normalize(), origin, trace_fraction, v_forward, v_right, vectoangles(), and vector.

◆ steerlib_dodge()

vector steerlib_dodge ( entity this,
vector point,
vector dodge_dir,
float min_distance )

Dodge a point NOTE: doesn't work well.

Definition at line 143 of file steerlib.qc.

144{
145 float distance = max(vlen(this.origin - point), min_distance);
146 if (min_distance < distance)
147 return '0 0 0';
148
149 return dodge_dir * (min_distance / distance);
150}
float max(float f,...)

References entity(), max(), origin, vector, and vlen().

◆ steerlib_flock()

vector steerlib_flock ( entity this,
float _radius,
float standoff,
float separation_force,
float flock_force )

Definition at line 157 of file steerlib.qc.

158{
159 vector push = '0 0 0', pull = '0 0 0';
160 int ccount = 0;
161
162 entity flock_member = findradius(this.origin, _radius);
163 while(flock_member)
164 {
165 if(flock_member != this)
166 if(flock_member.flock_id == this.flock_id)
167 {
168 ++ccount;
169 push = push + (steerlib_repel(this, flock_member.origin,standoff) * separation_force);
170 pull = pull + (steerlib_arrive(this, flock_member.origin + flock_member.velocity, _radius) * flock_force);
171 }
172 flock_member = flock_member.chain;
173 }
174 return push + (pull* (1 / ccount));
175}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
vector steerlib_arrive(entity this, vector point, float maximal_distance)
Pull toward a point, The further away, the stronger the pull.
Definition steerlib.qc:27
vector steerlib_repel(entity this, vector point, float maximal_distance)
Move away from a point.
Definition steerlib.qc:89

References entity(), origin, steerlib_arrive(), steerlib_repel(), and vector.

◆ steerlib_flock2d()

vector steerlib_flock2d ( entity this,
float _radius,
float standoff,
float separation_force,
float flock_force )

flocking by .flock_id Group will move towards the unified direction while keeping close to eachother.

xy only version (for ground movers).

Definition at line 182 of file steerlib.qc.

183{
184 vector push = '0 0 0', pull = '0 0 0';
185 int ccount = 0;
186
187 entity flock_member = findradius(this.origin,_radius);
188 while(flock_member)
189 {
190 if(flock_member != this)
191 if(flock_member.flock_id == this.flock_id)
192 {
193 ++ccount;
194 push = push + (steerlib_repel(this, flock_member.origin, standoff) * separation_force);
195 pull = pull + (steerlib_arrive(this, flock_member.origin + flock_member.velocity, _radius) * flock_force);
196 }
197 flock_member = flock_member.chain;
198 }
199
200 push.z = 0;
201 pull.z = 0;
202
203 return push + (pull * (1 / ccount));
204}

References entity(), origin, steerlib_arrive(), steerlib_repel(), and vector.

◆ steerlib_repel()

vector steerlib_repel ( entity this,
vector point,
float maximal_distance )

Move away from a point.

Definition at line 89 of file steerlib.qc.

90{
91 float distance = bound(0.001, vlen(this.origin - point), maximal_distance);
92 vector direction = normalize(this.origin - point);
93
94 return direction * (1 - (distance / maximal_distance));
95}

References bound(), entity(), normalize(), origin, vector, and vlen().

Referenced by steerlib_flock(), steerlib_flock2d(), and steerlib_swarm().

◆ steerlib_standoff()

vector steerlib_standoff ( entity this,
vector point,
float ideal_distance )

Try to keep at ideal_distance away from point.

Definition at line 100 of file steerlib.qc.

101{
102 vector direction;
103 float distance = vlen(this.origin - point);
104
105 if(distance < ideal_distance)
106 {
107 direction = normalize(this.origin - point);
108 return direction * (distance / ideal_distance);
109 }
110
111 direction = normalize(point - this.origin);
112 return direction * (ideal_distance / distance);
113
114}

References entity(), normalize(), origin, vector, and vlen().

◆ steerlib_swarm()

vector steerlib_swarm ( entity this,
float _radius,
float standoff,
float separation_force,
float swarm_force )

All members want to be in the center, and keep away from eachother.

The further from the center the more they want to be there.

This results in a aligned movement (?!) much like flocking.

Definition at line 212 of file steerlib.qc.

213{
214 vector force = '0 0 0', center = '0 0 0';
215 int ccount = 0;
216
217 entity swarm_member = findradius(this.origin,_radius);
218 while(swarm_member)
219 {
220 if(swarm_member.flock_id == this.flock_id)
221 {
222 ++ccount;
223 center = center + swarm_member.origin;
224 force = force + (steerlib_repel(this, swarm_member.origin,standoff) * separation_force);
225 }
226 swarm_member = swarm_member.chain;
227 }
228
229 center = center * (1 / ccount);
230 force = force + (steerlib_arrive(this, center,_radius) * swarm_force);
231
232 return force;
233}

References entity(), origin, steerlib_arrive(), steerlib_repel(), and vector.

◆ steerlib_traceavoid()

vector steerlib_traceavoid ( entity this,
float pitch,
float length )

Steer towards the direction least obstructed.

Run four tracelines in a forward funnel, bias each diretion negative if something is found there. You need to call makevectors() (or equivalent) before this function to set v_forward and v_right

Definition at line 240 of file steerlib.qc.

241{
242 vector v_left = v_right * -1;
243 vector v_down = v_up * -1;
244
245 vector vup_left = (v_forward + (v_left * pitch + v_up * pitch)) * length;
246 traceline(this.origin, this.origin + vup_left, MOVE_NOMONSTERS, this);
247 float fup_left = trace_fraction;
248
249 //te_lightning1(NULL,this.origin, trace_endpos);
250
251 vector vup_right = (v_forward + (v_right * pitch + v_up * pitch)) * length;
252 traceline(this.origin, this.origin + vup_right, MOVE_NOMONSTERS, this);
253 float fup_right = trace_fraction;
254
255 //te_lightning1(NULL,this.origin, trace_endpos);
256
257 vector vdown_left = (v_forward + (v_left * pitch + v_down * pitch)) * length;
258 traceline(this.origin, this.origin + vdown_left, MOVE_NOMONSTERS, this);
259 float fdown_left = trace_fraction;
260
261 //te_lightning1(NULL,this.origin, trace_endpos);
262
263 vector vdown_right = (v_forward + (v_right * pitch + v_down * pitch)) * length;
264 traceline(this.origin, this.origin + vdown_right, MOVE_NOMONSTERS, this);
265 float fdown_right = trace_fraction;
266
267 //te_lightning1(NULL,this.origin, trace_endpos);
268 vector upwish = v_up * (fup_left + fup_right);
269 vector downwish = v_down * (fdown_left + fdown_right);
270 vector leftwish = v_left * (fup_left + fdown_left);
271 vector rightwish = v_right * (fup_right + fdown_right);
272
273 return (upwish + leftwish + downwish + rightwish) * 0.25;
274
275}
vector v_up
float pitch
Definition halflife.qc:5

References entity(), MOVE_NOMONSTERS, origin, pitch, trace_fraction, v_forward, v_right, v_up, and vector.

◆ steerlib_traceavoid_flat()

vector steerlib_traceavoid_flat ( entity this,
float pitch,
float length,
vector vofs )

Steer towards the direction least obstructed.

Run tracelines in a forward trident, bias each direction negative if something is found there. You need to call makevectors() (or equivalent) before this function to set v_forward and v_right

Definition at line 282 of file steerlib.qc.

283{
284 vector v_left = v_right * -1;
285
286 vector vt_front = v_forward * length;
287 traceline(this.origin + vofs, this.origin + vofs + vt_front,MOVE_NOMONSTERS,this);
288 float f_front = trace_fraction;
289
290 vector vt_left = (v_forward + (v_left * pitch)) * length;
291 traceline(this.origin + vofs, this.origin + vofs + vt_left,MOVE_NOMONSTERS,this);
292 float f_left = trace_fraction;
293
294 //te_lightning1(NULL,this.origin, trace_endpos);
295
296 vector vt_right = (v_forward + (v_right * pitch)) * length;
297 traceline(this.origin + vofs, this.origin + vofs + vt_right ,MOVE_NOMONSTERS,this);
298 float f_right = trace_fraction;
299
300 //te_lightning1(NULL,this.origin, trace_endpos);
301
302 vector leftwish = v_left * f_left;
303 vector rightwish = v_right * f_right;
304 vector frontwish = v_forward * f_front;
305
306 return normalize(leftwish + rightwish + frontwish);
307}

References entity(), MOVE_NOMONSTERS, normalize(), origin, pitch, trace_fraction, v_forward, v_right, and vector.

◆ steerlib_wander()

vector steerlib_wander ( entity this,
float range,
float threshold,
vector oldpoint )

A random heading in a forward semicircle.

usage: this.target = steerlib_wander(256, 32, this.target)

where range is the circle radius and threshold is how close we need to be to pick a new heading. Assumes v_forward is set by makevectors

Definition at line 125 of file steerlib.qc.

126{
127 vector wander_point = v_forward - oldpoint;
128
129 if (vdist(wander_point, >, threshold))
130 return oldpoint;
131
132 range = bound(0, range, 1);
133
134 wander_point = this.origin + v_forward * 128;
135 wander_point = wander_point + randomvec() * (range * 128) - randomvec() * (range * 128);
136
137 return normalize(wander_point - this.origin);
138}
vector randomvec(void)
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition vector.qh:8

References bound(), entity(), normalize(), origin, randomvec(), v_forward, vdist, and vector.

Variable Documentation

◆ flock_id

float flock_id

flocking by .flock_id Group will move towards the unified direction while keeping close to eachother.

Definition at line 156 of file steerlib.qc.