Xonotic
jumppads.qh File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 STATIC_INIT (g_jumppads)
 
vector trigger_push_calculatevelocity (vector org, entity tgt, float ht, entity pushed_entity)
 
void trigger_push_findtarget (entity this)
 
bool trigger_push_test (entity this, entity item)
 if (item != NULL) returns true if the item can be reached by using this jumppad, false otherwise if (item == NULL) tests jumppad's trajectory and eventually spawns waypoints for it (return value doesn't matter) More...
 
void trigger_push_touch (entity this, entity toucher)
 

Variables

vector dest
 
IntrusiveList g_jumppads
 
float height
 
bool istypefrag
 
float jumppadcount
 
entity jumppadsused [NUM_JUMPPADSUSED]
 
const int NUM_JUMPPADSUSED = 3
 
const int PUSH_ONCE = BIT(0)
 
const int PUSH_SILENT = BIT(1)
 
float pushltime
 

Function Documentation

◆ STATIC_INIT()

STATIC_INIT ( g_jumppads  )

Definition at line 8 of file jumppads.qh.

References IL_NEW.

8 { g_jumppads = IL_NEW(); }
#define IL_NEW()
IntrusiveList g_jumppads
Definition: jumppads.qh:7

◆ trigger_push_calculatevelocity()

vector trigger_push_calculatevelocity ( vector  org,
entity  tgt,
float  ht,
entity  pushed_entity 
)

Definition at line 31 of file jumppads.qc.

References fabs(), normalize(), NULL, solve_quadratic(), sqrt(), vector(), and vlen().

Referenced by jumppad_push(), trigger_push_test(), and trigger_push_touch().

32 {
33  float grav, sdist, zdist, vs, vz, jumpheight;
34  vector sdir, torg;
35 
36  torg = tgt.origin + (tgt.mins + tgt.maxs) * 0.5;
37 
38  grav = PHYS_GRAVITY(NULL);
39  if(pushed_entity && pushed_entity.gravity)
40  grav *= pushed_entity.gravity;
41 
42  zdist = torg.z - org.z;
43  sdist = vlen(torg - org - zdist * '0 0 1');
44  sdir = normalize(torg - org - zdist * '0 0 1');
45 
46  // how high do we need to push the player?
47  jumpheight = fabs(ht);
48  if(zdist > 0)
49  jumpheight = jumpheight + zdist;
50 
51  /*
52  STOP.
53 
54  You will not understand the following equations anyway...
55  But here is what I did to get them.
56 
57  I used the functions
58 
59  s(t) = t * vs
60  z(t) = t * vz - 1/2 grav t^2
61 
62  and solved for:
63 
64  s(ti) = sdist
65  z(ti) = zdist
66  max(z, ti) = jumpheight
67 
68  From these three equations, you will find the three parameters vs, vz
69  and ti.
70  */
71 
72  // push him so high...
73  vz = sqrt(fabs(2 * grav * jumpheight)); // NOTE: sqrt(positive)!
74 
75  // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump!
76  if(ht < 0)
77  if(zdist < 0)
78  vz = -vz;
79 
80  vector solution;
81  solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
82  // ALWAYS solvable because jumpheight >= zdist
83  if(!solution.z)
84  solution_y = solution.x; // just in case it is not solvable due to roundoff errors, assume two equal solutions at their center (this is mainly for the usual case with ht == 0)
85  if(zdist == 0)
86  solution_x = solution.y; // solution_x is 0 in this case, so don't use it, but rather use solution_y (which will be sqrt(0.5 * jumpheight / grav), actually)
87 
88  float flighttime;
89  if(zdist < 0)
90  {
91  // down-jump
92  if(ht < 0)
93  {
94  // almost straight line type
95  // jump apex is before the jump
96  // we must take the larger one
97  flighttime = solution.y;
98  }
99  else
100  {
101  // regular jump
102  // jump apex is during the jump
103  // we must take the larger one too
104  flighttime = solution.y;
105  }
106  }
107  else
108  {
109  // up-jump
110  if(ht < 0)
111  {
112  // almost straight line type
113  // jump apex is after the jump
114  // we must take the smaller one
115  flighttime = solution.x;
116  }
117  else
118  {
119  // regular jump
120  // jump apex is during the jump
121  // we must take the larger one
122  flighttime = solution.y;
123  }
124  }
125  vs = sdist / flighttime;
126 
127  // finally calculate the velocity
128  return sdir * vs + '0 0 1' * vz;
129 }
ERASEABLE vector solve_quadratic(float a, float b, float c)
ax^2 + bx + c = 0
Definition: math.qh:307
#define NULL
Definition: post.qh:17
vector(float skel, float bonenum) _skel_get_boneabs_hidden
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ trigger_push_findtarget()

void trigger_push_findtarget ( entity  this)

Definition at line 558 of file jumppads.qc.

References active, ACTIVE_ACTIVE, angles, BITSET_ASSIGN, cnt, drawmask, EF_NODEPTHTEST, effects, entity(), g_jumppads, height, IL_PUSH(), InitializeEntity(), jumppad_push(), mangle, MASK_NORMAL, move_time, movedir, NET_HANDLE, noise, NULL, origin, precache_sound(), ReadString, setorigin(), SF_TRIGGER_INIT, solid, SOLID_TRIGGER, spawnflags, spawnfunc(), speed, strfree, strzone(), target, targetname, team, time, to, trigger_push_findtarget(), trigger_push_test(), trigger_push_touch(), use, WriteByte(), WriteCoord(), and WriteString().

Referenced by trigger_push_findtarget().

559 {
560  trigger_push_test(this, NULL);
561 }
#define NULL
Definition: post.qh:17
bool trigger_push_test(entity this, entity item)
if (item != NULL) returns true if the item can be reached by using this jumppad, false otherwise if (...
Definition: jumppads.qc:387
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ trigger_push_test()

bool trigger_push_test ( entity  this,
entity  item 
)

if (item != NULL) returns true if the item can be reached by using this jumppad, false otherwise if (item == NULL) tests jumppad's trajectory and eventually spawns waypoints for it (return value doesn't matter)

Definition at line 387 of file jumppads.qc.

References absmax, absmin, boxesoverlap(), DPCONTENTS_BODY, DPCONTENTS_BOTCLIP, DPCONTENTS_PLAYERCLIP, DPCONTENTS_SOLID, enemy, entity(), eZ, fabs(), find(), height, if(), LABEL, min(), movedir, MOVETYPE_NONE, normalize(), NULL, objerror(), setorigin(), spawn(), target, targetname, team, trace_endpos, trace_ent, trigger_push_calculatevelocity(), vdist, vec2, vector(), vlen(), and waypoint_spawnforteleporter().

Referenced by navigation_findnearestwaypoint_withdist_except(), and trigger_push_findtarget().

388 {
389 #ifdef SVQC
390  vector org = trigger_push_get_start_point(this);
391 #endif
392 
393  if (this.target)
394  {
395  int n = 0;
396 #ifdef SVQC
397  vector vel = '0 0 0';
398 #endif
399  for(entity t = NULL; (t = find(t, targetname, this.target)); )
400  {
401  ++n;
402 #ifdef SVQC
403  if(t.move_movetype != MOVETYPE_NONE)
404  continue;
405 
406  // bots can't tell teamed jumppads from normal ones
407  if (this.team)
408  continue;
409 
410  entity e = spawn();
411  setsize(e, PL_MIN_CONST, PL_MAX_CONST);
413  e.velocity = trigger_push_calculatevelocity(org, t, this.height, e);
414 
415  vel = e.velocity;
416  vector best_target = '0 0 0';
417  vector best_org = '0 0 0';
418  vector best_vel = '0 0 0';
419  bool valid_best_target = false;
420  if (item)
421  {
422  if (!trigger_push_testorigin_for_item(e, item, org))
423  {
424  delete(e);
425  return false;
426  }
427  }
428  else
429  {
430  if (trigger_push_testorigin(e, t, this, org))
431  {
432  best_target = trace_endpos;
433  best_org = org;
434  best_vel = e.velocity;
435  valid_best_target = true;
436  }
437  }
438 
439  vector new_org;
440  vector dist = t.origin - org;
441  if (dist.x || dist.y) // if not perfectly vertical
442  {
443  // test trajectory with different starting points, sometimes the trajectory
444  // starting from the jumppad origin can't reach the real destination
445  // and destination waypoint ends up near the jumppad itself
446  vector flatdir = normalize(dist - eZ * dist.z);
447  vector ofs = flatdir * 0.5 * min(fabs(this.absmax.x - this.absmin.x), fabs(this.absmax.y - this.absmin.y));
448  new_org = org + ofs;
449 
450  LABEL(new_test)
451  e.velocity = trigger_push_calculatevelocity(new_org, t, this.height, e);
452  if (item)
453  {
454  if (!trigger_push_testorigin_for_item(e, item, new_org))
455  {
456  delete(e);
457  return false;
458  }
459  }
460  else
461  {
462  vel = e.velocity;
463  if (vdist(vec2(e.velocity), <, autocvar_sv_maxspeed))
464  e.velocity = autocvar_sv_maxspeed * flatdir;
465  if (trigger_push_testorigin(e, t, this, new_org) && (!valid_best_target || trace_endpos.z > best_target.z + 50))
466  {
467  best_target = trace_endpos;
468  best_org = new_org;
469  best_vel = vel;
470  valid_best_target = true;
471  }
472  }
473  if (ofs && new_org != org - ofs)
474  {
475  new_org = org - ofs;
476  goto new_test;
477  }
478  }
479 
480  if (item)
481  {
482  delete(e);
483  return true;
484  }
485 
486  if (valid_best_target)
487  {
488  if (!(boxesoverlap(this.absmin, this.absmax + eZ * 50, best_target + PL_MIN_CONST, best_target + PL_MAX_CONST)))
489  {
490  float velxy = vlen(vec2(best_vel));
491  float cost = vlen(vec2(t.origin - best_org)) / velxy;
492  if(velxy < autocvar_sv_maxspeed)
493  velxy = autocvar_sv_maxspeed;
494  cost += vlen(vec2(best_target - t.origin)) / velxy;
495  waypoint_spawnforteleporter(this, best_target, cost, e);
496  }
497  }
498  delete(e);
499 #endif
500  }
501 
502  if(item)
503  return false;
504 
505  if(!n)
506  {
507  // no dest!
508 #ifdef SVQC
509  objerror (this, "Jumppad with nonexistant target");
510 #endif
511  return false;
512  }
513  else if(n == 1)
514  {
515  // exactly one dest - bots love that
516  if (!this.team)
517  this.enemy = find(NULL, targetname, this.target);
518  else // bots can't tell teamed jumppads from normal ones
519  this.enemy = NULL;
520  }
521  else
522  {
523  // have to use random selection every single time
524  this.enemy = NULL;
525  }
526 
527  }
528 #ifdef SVQC
529  else
530  {
531  if (!this.team)
532  {
533  entity e = spawn();
534  setsize(e, PL_MIN_CONST, PL_MAX_CONST);
536  setorigin(e, org);
537  e.velocity = this.movedir;
538  tracetoss(e, e);
539  if (item)
540  {
541  bool r = (trace_ent == item);
542  delete(e);
543  return r;
544  }
545  if (!(boxesoverlap(this.absmin, this.absmax + eZ * 50, trace_endpos + PL_MIN_CONST, trace_endpos + PL_MAX_CONST)))
546  waypoint_spawnforteleporter(this, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity), e);
547  delete(e);
548  }
549  else if (item)
550  return false;
551  }
552 
553  defer(this, 0.1, trigger_push_updatelink);
554 #endif
555  return true;
556 }
float MOVETYPE_NONE
Definition: progsdefs.qc:246
int team
Definition: main.qh:157
entity() spawn
float DPCONTENTS_BOTCLIP
float DPCONTENTS_PLAYERCLIP
vector trigger_push_calculatevelocity(vector org, entity tgt, float ht, entity pushed_entity)
Definition: jumppads.qc:31
entity trace_ent
Definition: csprogsdefs.qc:40
vector absmax
Definition: csprogsdefs.qc:92
vector movedir
Definition: progsdefs.qc:203
entity enemy
Definition: sv_ctf.qh:143
ERASEABLE float boxesoverlap(vector m1, vector m2, vector m3, vector m4)
requires that m2>m1 in all coordinates, and that m4>m3
Definition: vector.qh:73
float height
Definition: jumppads.qh:12
#define NULL
Definition: post.qh:17
float DPCONTENTS_SOLID
vector trace_endpos
Definition: csprogsdefs.qc:37
void waypoint_spawnforteleporter(entity e, vector destination, float timetaken, entity tracetest_ent)
Definition: waypoints.qc:2069
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float DPCONTENTS_BODY
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition: vector.qh:8
const vector eZ
Definition: vector.qh:46
string targetname
Definition: progsdefs.qc:194
#define vec2(...)
Definition: vector.qh:90
#define LABEL(id)
Definition: compiler.qh:36
setorigin(ent, v)
string target
Definition: progsdefs.qc:193
vector absmin
Definition: csprogsdefs.qc:92
if(IS_DEAD(this))
Definition: impulse.qc:92
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ trigger_push_touch()

void trigger_push_touch ( entity  this,
entity  toucher 
)

Definition at line 260 of file jumppads.qc.

References absmax, absmin, active, ACTIVE_NOT, DIFF_TEAM, DPCONTENTS_BODY, DPCONTENTS_BOTCLIP, DPCONTENTS_PLAYERCLIP, DPCONTENTS_SOLID, enemy, entity(), EXACTTRIGGER_TOUCH, eZ, func_null(), height, INVERT_TEAMS, jumppad_push(), movedir, nextthink, NULL, PUSH_ONCE, setorigin(), setthink, spawn(), spawnflags, sqrt(), stepheightvec, target, team, time, trace_endpos, trace_ent, trace_startsolid, trigger_push_calculatevelocity(), trigger_push_get_push_time(), v, vdist, vec2, and vector().

Referenced by trigger_push_findtarget().

261 {
262  if (this.active == ACTIVE_NOT)
263  return;
264 
265  if(this.team)
266  if(((this.spawnflags & INVERT_TEAMS) == 0) == (DIFF_TEAM(this, toucher)))
267  return;
268 
269  EXACTTRIGGER_TOUCH(this, toucher);
270 
271  noref bool success = jumppad_push(this, toucher);
272 
273 #ifdef SVQC
274  if (success && (this.spawnflags & PUSH_ONCE))
275  {
276  settouch(this, func_null);
277  setthink(this, SUB_Remove);
278  this.nextthink = time;
279  }
280 #endif
281 }
const int INVERT_TEAMS
Definition: defs.qh:10
bool jumppad_push(entity this, entity targ)
Definition: jumppads.qc:131
int team
Definition: main.qh:157
#define EXACTTRIGGER_TOUCH(e, t)
Definition: common.qh:116
const int PUSH_ONCE
Definition: jumppads.qh:4
#define DIFF_TEAM(a, b)
Definition: teams.qh:240
float spawnflags
Definition: progsdefs.qc:191
float nextthink
Definition: csprogsdefs.qc:121
int active
Definition: defs.qh:34
#define setthink(e, f)
const int ACTIVE_NOT
Definition: defs.qh:36
float time
Definition: csprogsdefs.qc:16
var void func_null()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ dest

◆ g_jumppads

◆ height

◆ istypefrag

bool istypefrag

Definition at line 11 of file jumppads.qh.

Referenced by PlayerDamage(), and PutObserverInServer().

◆ jumppadcount

◆ jumppadsused

entity jumppadsused[NUM_JUMPPADSUSED]

Definition at line 16 of file jumppads.qh.

◆ NUM_JUMPPADSUSED

const int NUM_JUMPPADSUSED = 3

Definition at line 14 of file jumppads.qh.

Referenced by jumppad_push().

◆ PUSH_ONCE

const int PUSH_ONCE = BIT(0)

Definition at line 4 of file jumppads.qh.

Referenced by trigger_push_touch().

◆ PUSH_SILENT

const int PUSH_SILENT = BIT(1)

Definition at line 5 of file jumppads.qh.

◆ pushltime