Xonotic
jumppads.qc File Reference
#include "jumppads.qh"
+ Include dependency graph for jumppads.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool jumppad_push (entity this, entity targ)
 
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)
 

Function Documentation

◆ jumppad_push()

bool jumppad_push ( entity  this,
entity  targ 
)

Definition at line 131 of file jumppads.qc.

References _sound, ANIMACTION_JUMP, animdecide_setaction(), ATTEN_NORM, centerprint(), CH_TRIGGER, enemy, entity(), find(), height, IS_BOT_CLIENT, IS_DEAD, IS_PLAYER, IS_REAL_CLIENT, isPushable(), message, movedir, MOVETYPE_BOUNCE, MOVETYPE_BOUNCEMISSILE, MOVETYPE_FLY, MOVETYPE_TOSS, noise, NULL, NUM_JUMPPADSUSED, pushltime, RandomSelection_AddEnt, RandomSelection_chosen_ent, RandomSelection_Init(), set_movetype(), SUB_UseTargets(), target, targetname, time, trigger_push_calculatevelocity(), UNSET_ONGROUND, UpdateCSQCProjectile(), vectoangles(), vector(), and VOL_BASE.

Referenced by trigger_push_findtarget(), and trigger_push_touch().

132 {
133  if (!isPushable(targ))
134  return false;
135 
136  vector org = targ.origin;
137 
138  if(STAT(Q3COMPAT))
139  {
140  org.z += targ.mins_z;
141  org.z += 1; // off by 1!
142  }
143 
144  if(this.enemy)
145  {
146  targ.velocity = trigger_push_calculatevelocity(org, this.enemy, this.height, targ);
147  }
148  else if(this.target && this.target != "")
149  {
150  entity e;
152  for(e = NULL; (e = find(e, targetname, this.target)); )
153  {
154  if(e.cnt)
155  RandomSelection_AddEnt(e, e.cnt, 1);
156  else
157  RandomSelection_AddEnt(e, 1, 1);
158  }
159  targ.velocity = trigger_push_calculatevelocity(org, RandomSelection_chosen_ent, this.height, targ);
160  }
161  else
162  {
163  targ.velocity = this.movedir;
164  }
165 
166  UNSET_ONGROUND(targ);
167 
168 #ifdef CSQC
169  if (targ.flags & FL_PROJECTILE)
170  {
171  targ.angles = vectoangles (targ.velocity);
172  switch(targ.move_movetype)
173  {
174  case MOVETYPE_FLY:
176  targ.gravity = 1;
177  break;
180  targ.gravity = 1;
181  break;
182  }
183  }
184 #endif
185 
186 #ifdef SVQC
187  if (IS_PLAYER(targ))
188  {
189  // reset tracking of oldvelocity for impact damage (sudden velocity changes)
190  targ.oldvelocity = targ.velocity;
191 
192  // prevent sound spam when a player hits the jumppad more than once
193  // or when a dead player gets stuck in the jumppad for some reason
194  if(this.pushltime < time && !(IS_DEAD(targ) && targ.velocity == '0 0 0'))
195  {
196  // flash when activated
197  Send_Effect(EFFECT_JUMPPAD, targ.origin, targ.velocity, 1);
198  _sound (targ, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
199  this.pushltime = time + 0.2;
200  }
201  if(IS_REAL_CLIENT(targ) || IS_BOT_CLIENT(targ))
202  {
203  bool found = false;
204  for(int i = 0; i < targ.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
205  if(targ.(jumppadsused[i]) == this)
206  found = true;
207  if(!found)
208  {
209  targ.(jumppadsused[targ.jumppadcount % NUM_JUMPPADSUSED]) = this;
210  targ.jumppadcount = targ.jumppadcount + 1;
211  }
212 
213  if(IS_REAL_CLIENT(targ))
214  {
215  if(this.message)
216  centerprint(targ, this.message);
217  }
218  else
219  {
220  targ.lastteleporttime = time;
221  targ.lastteleport_origin = targ.origin;
222  }
223 
224  if (!IS_DEAD(targ))
226  }
227  else
228  targ.jumppadcount = 1;
229 
230  // reset tracking of who pushed you into a hazard (for kill credit)
231  targ.pushltime = 0;
232  targ.istypefrag = 0;
233  }
234 
235  if(this.enemy.target)
236  SUB_UseTargets(this.enemy, targ, this);
237 
238  if (targ.flags & FL_PROJECTILE)
239  {
240  targ.angles = vectoangles (targ.velocity);
241  targ.com_phys_gravity_factor = 1;
242  switch(targ.move_movetype)
243  {
244  case MOVETYPE_FLY:
246  targ.gravity = 1;
247  break;
250  targ.gravity = 1;
251  break;
252  }
253  UpdateCSQCProjectile(targ);
254  }
255 #endif
256 
257  return true;
258 }
string noise
Definition: progsdefs.qc:209
float MOVETYPE_TOSS
Definition: progsdefs.qc:252
ERASEABLE void RandomSelection_Init()
Definition: random.qc:4
const int ANIMACTION_JUMP
Definition: animdecide.qh:141
entity() spawn
float MOVETYPE_BOUNCEMISSILE
Definition: progsdefs.qc:257
void SUB_UseTargets(entity this, entity actor, entity trigger)
Definition: triggers.qc:366
float pushltime
Definition: jumppads.qh:10
vector trigger_push_calculatevelocity(vector org, entity tgt, float ht, entity pushed_entity)
Definition: jumppads.qc:31
float MOVETYPE_BOUNCE
Definition: progsdefs.qc:256
#define UNSET_ONGROUND(s)
Definition: movetypes.qh:18
const int NUM_JUMPPADSUSED
Definition: jumppads.qh:14
#define IS_REAL_CLIENT(v)
Definition: utils.qh:17
#define RandomSelection_AddEnt(e, weight, priority)
Definition: random.qh:14
vector movedir
Definition: progsdefs.qc:203
entity enemy
Definition: sv_ctf.qh:143
void UpdateCSQCProjectile(entity e)
float height
Definition: jumppads.qh:12
void animdecide_setaction(entity e, float action, float restart)
Definition: animdecide.qc:338
const int CH_TRIGGER
Definition: sound.qh:12
entity RandomSelection_chosen_ent
Definition: random.qh:5
string message
Definition: powerups.qc:19
#define NULL
Definition: post.qh:17
const float VOL_BASE
Definition: sound.qh:36
#define IS_DEAD(s)
Definition: utils.qh:26
const float ATTEN_NORM
Definition: sound.qh:30
vector(float skel, float bonenum) _skel_get_boneabs_hidden
#define _sound(e, c, s, v, a)
Definition: sound.qh:50
string targetname
Definition: progsdefs.qc:194
#define IS_BOT_CLIENT(v)
want: (IS_CLIENT(v) && !IS_REAL_CLIENT(v))
Definition: utils.qh:15
string target
Definition: progsdefs.qc:193
float time
Definition: csprogsdefs.qc:16
bool isPushable(entity e)
Definition: triggers.qc:3
void set_movetype(entity this, int mt)
float MOVETYPE_FLY
Definition: progsdefs.qc:251
#define IS_PLAYER(v)
Definition: utils.qh:9
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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(), trigger_push_touch(), and W_Nexball_Attack2().

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: