]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/trigger/jumppads.qc
Transifex autosync
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapobjects / trigger / jumppads.qc
1 #include "jumppads.qh"
2 // TODO: split target_push and put it in the target folder
3 #ifdef SVQC
4 #include <common/physics/movetypes/movetypes.qh>
5
6 void trigger_push_use(entity this, entity actor, entity trigger)
7 {
8         if(teamplay)
9         {
10                 this.team = actor.team;
11                 this.SendFlags |= SF_TRIGGER_UPDATE;
12         }
13 }
14 #endif
15
16 REGISTER_NET_LINKED(ENT_CLIENT_TRIGGER_PUSH)
17 REGISTER_NET_LINKED(ENT_CLIENT_TRIGGER_PUSH_VELOCITY)
18 REGISTER_NET_LINKED(ENT_CLIENT_TARGET_PUSH)
19
20 /*
21         trigger_push_calculatevelocity
22
23         Arguments:
24           org - origin of the object which is to be pushed
25           tgt - target entity (can be either a point or a model entity; if it is
26                 the latter, its midpoint is used)
27           ht  - jump height, measured from the higher one of org and tgt's midpoint
28           pushed_entity - object that is to be pushed
29
30         Returns: velocity for the jump
31  */
32 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht, entity pushed_entity)
33 {
34         float grav, sdist, zdist, vs, vz, jumpheight;
35         vector sdir, torg;
36
37         torg = tgt.origin + (tgt.mins + tgt.maxs) * 0.5;
38
39         grav = PHYS_GRAVITY(NULL);
40         if(pushed_entity && pushed_entity.gravity)
41                 grav *= pushed_entity.gravity;
42
43         // Q3 has frametime-dependent gravity, but its trigger_push velocity calculation doesn't account for that.
44         // This discrepancy can be simulated accurately which ensures that all entities will arrive
45         // where they would in Q3 with gravity 800 at 125fps, even if entity-specific gravity is applied.
46         // This can be hard-coded because we don't support the Q3 world.gravity field at this time.
47         // See physicsCPMA.cfg for maths and test results.
48         if (Q3COMPAT_COMMON)
49                 grav /= 750/800; // exact float, unlike 800/750
50
51         zdist = torg.z - org.z;
52         sdist = vlen(torg - org - zdist * '0 0 1');
53         sdir = normalize(torg - org - zdist * '0 0 1');
54
55         // how high do we need to push the player?
56         jumpheight = fabs(ht);
57         if(zdist > 0)
58                 jumpheight = jumpheight + zdist;
59
60         /*
61                 STOP.
62
63                 You will not understand the following equations anyway...
64                 But here is what I did to get them.
65
66                 I used the functions
67
68                   s(t) = t * vs
69                   z(t) = t * vz - 1/2 grav t^2
70
71                 and solved for:
72
73                   s(ti) = sdist
74                   z(ti) = zdist
75                   max(z, ti) = jumpheight
76
77                 From these three equations, you will find the three parameters vs, vz
78                 and ti.
79          */
80
81         // push them so high...
82         vz = sqrt(fabs(2 * grav * jumpheight)); // NOTE: sqrt(positive)!
83
84         // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump!
85         if(ht < 0)
86                 if(zdist < 0)
87                         vz = -vz;
88
89         vector solution;
90         solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
91         // ALWAYS solvable because jumpheight >= zdist
92         if(!solution.z)
93                 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)
94         if(zdist == 0)
95                 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)
96
97         float flighttime;
98         if(zdist < 0)
99         {
100                 // down-jump
101                 if(ht < 0)
102                 {
103                         // almost straight line type
104                         // jump apex is before the jump
105                         // we must take the larger one
106                         flighttime = solution.y;
107                 }
108                 else
109                 {
110                         // regular jump
111                         // jump apex is during the jump
112                         // we must take the larger one too
113                         flighttime = solution.y;
114                 }
115         }
116         else
117         {
118                 // up-jump
119                 if(ht < 0)
120                 {
121                         // almost straight line type
122                         // jump apex is after the jump
123                         // we must take the smaller one
124                         flighttime = solution.x;
125                 }
126                 else
127                 {
128                         // regular jump
129                         // jump apex is during the jump
130                         // we must take the larger one
131                         flighttime = solution.y;
132                 }
133         }
134         vs = sdist / flighttime;
135
136         // finally calculate the velocity
137         return sdir * vs + '0 0 1' * vz;
138 }
139
140 vector trigger_push_velocity_calculatevelocity(entity this, vector org, entity tgt, float speed, float count, entity pushed_entity, bool already_pushed)
141 {
142         bool is_playerdir_xy = boolean(this.spawnflags & PUSH_VELOCITY_PLAYERDIR_XY);
143         bool is_add_xy = boolean(this.spawnflags & PUSH_VELOCITY_ADD_XY);
144         bool is_playerdir_z = boolean(this.spawnflags & PUSH_VELOCITY_PLAYERDIR_Z);
145         bool is_add_z = boolean(this.spawnflags & PUSH_VELOCITY_ADD_Z);
146         bool is_bidirectional_xy = boolean(this.spawnflags & PUSH_VELOCITY_BIDIRECTIONAL_XY);
147         bool is_bidirectional_z = boolean(this.spawnflags & PUSH_VELOCITY_BIDIRECTIONAL_Z);
148         bool is_clamp_negative_adds = boolean(this.spawnflags & PUSH_VELOCITY_CLAMP_NEGATIVE_ADDS);
149
150         vector sdir = normalize(vec2(pushed_entity.velocity));
151         float zdir = pushed_entity.velocity.z;
152         if(zdir != 0) zdir = copysign(1, zdir);
153
154         vector vs_tgt = '0 0 0';
155         float vz_tgt = 0;
156         if (!is_playerdir_xy || !is_playerdir_z)
157         {
158                 vector vel_tgt = trigger_push_calculatevelocity(org, tgt, 0, pushed_entity);
159                 vs_tgt = vec2(vel_tgt);
160                 vz_tgt = vel_tgt.z;
161
162                 // bidirectional jump pads do not play nicely with xonotic's jump pad targets
163                 if (is_bidirectional_xy)
164                 {
165                         if (normalize(vs_tgt) * sdir < 0)
166                         {
167                                 vs_tgt *= -1;
168                         }
169                 }
170
171                 if (is_bidirectional_z)
172                 {
173                         if (signbit(vz_tgt) != signbit(zdir))
174                         {
175                                 vz_tgt *= -1;
176                         }
177                 }
178         }
179
180         vector vs;
181         if (is_playerdir_xy)
182         {
183                 vs = sdir * speed;
184         }
185         else
186         {
187                 vs = vs_tgt;
188         }
189
190         float vz;
191         if (is_playerdir_z)
192         {
193                 vz = zdir * count;
194         }
195         else
196         {
197                 vz = vz_tgt;
198         }
199
200         if (is_add_xy)
201         {
202                 vector vs_add = vec2(pushed_entity.velocity);
203                 if (already_pushed)
204                 {
205                         vs = vs_add;
206                 }
207                 else
208                 {
209                         vs += vs_add;
210
211                         if (is_clamp_negative_adds)
212                         {
213                                 if ((normalize(vs) * sdir) < 0)
214                                 {
215                                         vs = '0 0 0';
216                                 }
217                         }
218                 }
219         }
220
221         if (is_add_z)
222         {
223                 float vz_add = pushed_entity.velocity.z;
224                 if (already_pushed)
225                 {
226                         vz = vz_add;
227                 }
228                 else
229                 {
230                         vz += vz_add;
231
232                         if (is_clamp_negative_adds)
233                         {
234                                 if (signbit(vz) != signbit(zdir))
235                                 {
236                                         vz = 0;
237                                 }
238                         }
239                 }
240         }
241
242         return vs + '0 0 1' * vz;
243 }
244
245 #ifdef SVQC
246 void trigger_push_velocity_think(entity this)
247 {
248         bool found = false;
249         IL_EACH(g_moveables, it.last_pushed == this,
250         {
251                 if(!WarpZoneLib_ExactTrigger_Touch(this, it, false))
252                         it.last_pushed = NULL;
253                 else
254                         found = true;
255         });
256
257         if(found)
258                 this.nextthink = time;
259         else
260                 setthink(this, func_null);
261 }
262 #endif
263
264 bool jumppad_push(entity this, entity targ, bool is_velocity_pad)
265 {
266         if (!isPushable(targ))
267                 return false;
268
269         vector org = targ.origin;
270
271         if(Q3COMPAT_COMMON || (this.spawnflags & PUSH_STATIC))
272                 org = (this.absmin + this.absmax) * 0.5;
273
274         bool already_pushed = false;
275         if(is_velocity_pad) // remember velocity jump pads
276         {
277                 if(this == targ.last_pushed || (targ.last_pushed && !STAT(Q3COMPAT, targ))) // if q3compat is active overwrite last stored jump pad, otherwise ignore
278                 {
279                         already_pushed = true;
280                 }
281                 else
282                 {
283                         targ.last_pushed = this; // may be briefly out of sync between client and server if client prediction is toggled
284
285                         #ifdef SVQC
286                         setthink(this, trigger_push_velocity_think);
287                         this.nextthink = time;
288                         #endif
289                 }
290         }
291
292         if(this.enemy)
293         {
294                 if(!is_velocity_pad)
295                 {
296                         targ.velocity = trigger_push_calculatevelocity(org, this.enemy, this.height, targ);
297                 }
298                 else
299                 {
300                         targ.velocity = trigger_push_velocity_calculatevelocity(this, org, this.enemy, this.speed, this.count, targ, already_pushed);
301                 }
302         }
303         else if(this.target && this.target != "")
304         {
305                 entity e;
306                 RandomSelection_Init();
307                 for(e = NULL; (e = find(e, targetname, this.target)); )
308                 {
309                         if(e.cnt)
310                                 RandomSelection_AddEnt(e, e.cnt, 1);
311                         else
312                                 RandomSelection_AddEnt(e, 1, 1);
313                 }
314                 if(!is_velocity_pad)
315                 {
316                         targ.velocity = trigger_push_calculatevelocity(org, RandomSelection_chosen_ent, this.height, targ);
317                 }
318                 else
319                 {
320                         targ.velocity = trigger_push_velocity_calculatevelocity(this, org, RandomSelection_chosen_ent, this.speed, this.count, targ, already_pushed);
321                 }
322         }
323         else
324         {
325                 if(!is_velocity_pad)
326                 {
327                         targ.velocity = this.movedir;
328                 }
329                 else
330                 {
331 #ifdef SVQC
332                         objerror (this, "Jumppad with no target");
333 #endif
334                         return false;
335                 }
336         }
337
338         if(!is_velocity_pad) UNSET_ONGROUND(targ);
339
340 #ifdef CSQC
341         if (targ.flags & FL_PROJECTILE)
342         {
343                 targ.angles = vectoangles (targ.velocity);
344                 switch(targ.move_movetype)
345                 {
346                         case MOVETYPE_FLY:
347                                 set_movetype(targ, MOVETYPE_TOSS);
348                                 targ.gravity = 1;
349                                 break;
350                         case MOVETYPE_BOUNCEMISSILE:
351                                 set_movetype(targ, MOVETYPE_BOUNCE);
352                                 targ.gravity = 1;
353                                 break;
354                 }
355         }
356 #endif
357
358 #ifdef SVQC
359         if (IS_PLAYER(targ))
360         {
361                 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
362                 targ.oldvelocity = targ.velocity;
363
364                 // prevent sound spam when a player hits the jumppad more than once
365                 // or when a dead player gets stuck in the jumppad for some reason
366                 if(!already_pushed && this.pushltime < time && !(IS_DEAD(targ) && targ.velocity == '0 0 0'))
367                 {
368                         if (Q3COMPAT_COMMON && this.classname == "target_push")
369                                 this.pushltime = time + 1.5;
370                         else
371                         {
372                                 // flash when activated
373                                 Send_Effect(EFFECT_JUMPPAD, targ.origin, targ.velocity, 1);
374                                 this.pushltime = time + 0.2;
375                         }
376                         _sound (targ, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
377                 }
378
379                 if(IS_REAL_CLIENT(targ) || IS_BOT_CLIENT(targ))
380                 {
381                         bool found = false;
382                         for(int i = 0; i < targ.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
383                                 if(targ.(jumppadsused[i]) == this)
384                                         found = true;
385                         if(!found)
386                         {
387                                 targ.(jumppadsused[targ.jumppadcount % NUM_JUMPPADSUSED]) = this;
388                                 targ.jumppadcount = targ.jumppadcount + 1;
389                         }
390
391                         if(IS_REAL_CLIENT(targ))
392                         {
393                                 if(this.message)
394                                         centerprint(targ, this.message);
395                         }
396                         else
397                         {
398                                 targ.lastteleporttime = time;
399                                 targ.lastteleport_origin = targ.origin;
400                         }
401
402                         if (!IS_DEAD(targ))
403                                 animdecide_setaction(targ, ANIMACTION_JUMP, true);
404                 }
405                 else
406                         targ.jumppadcount = 1;
407
408                 // reset tracking of who pushed you into a hazard (for kill credit)
409                 targ.pushltime = 0;
410                 targ.istypefrag = 0;
411         }
412
413         if(this.enemy.target)
414                 SUB_UseTargets(this.enemy, targ, this);
415
416         if (targ.flags & FL_PROJECTILE)
417         {
418                 targ.angles = vectoangles (targ.velocity);
419                 targ.com_phys_gravity_factor = 1;
420                 switch(targ.move_movetype)
421                 {
422                         case MOVETYPE_FLY:
423                                 set_movetype(targ, MOVETYPE_TOSS);
424                                 targ.gravity = 1;
425                                 break;
426                         case MOVETYPE_BOUNCEMISSILE:
427                                 set_movetype(targ, MOVETYPE_BOUNCE);
428                                 targ.gravity = 1;
429                                 break;
430                 }
431                 UpdateCSQCProjectile(targ);
432         }
433 #endif
434
435         return true;
436 }
437
438 void trigger_push_touch(entity this, entity toucher)
439 {
440         if (this.active == ACTIVE_NOT)
441                 return;
442
443         if(this.team)
444                 if(((this.spawnflags & INVERT_TEAMS) == 0) == (DIFF_TEAM(this, toucher)))
445                         return;
446
447         EXACTTRIGGER_TOUCH(this, toucher);
448
449         noref bool success = jumppad_push(this, toucher, false);
450
451 #ifdef SVQC
452         if (success && (this.spawnflags & PUSH_ONCE))
453         {
454                 settouch(this, func_null);
455                 setthink(this, SUB_Remove);
456                 this.nextthink = time;
457         }
458 #endif
459 }
460
461 void trigger_push_velocity_touch(entity this, entity toucher)
462 {
463         if (this.active == ACTIVE_NOT)
464                 return;
465
466         if(this.team && DIFF_TEAM(this, toucher))
467                 return;
468
469         EXACTTRIGGER_TOUCH(this, toucher);
470
471         jumppad_push(this, toucher, true);
472 }
473
474 #ifdef SVQC
475 void trigger_push_link(entity this);
476 void trigger_push_updatelink(entity this);
477 bool trigger_push_testorigin(entity tracetest_ent, entity targ, entity jp, vector org)
478 {
479         setorigin(tracetest_ent, org);
480         tracetoss(tracetest_ent, tracetest_ent);
481         if(trace_startsolid)
482                 return false;
483
484         if (!jp.height)
485         {
486                 // since tracetoss starting from jumppad's origin often fails when target
487                 // is very close to real destination, start it directly from target's
488                 // origin instead
489                 vector ofs = '0 0 0';
490                 if (vdist(vec2(tracetest_ent.velocity), <, autocvar_sv_maxspeed))
491                         ofs = stepheightvec;
492
493                 tracetest_ent.velocity.z = 0;
494                 setorigin(tracetest_ent, targ.origin + ofs);
495                 tracetoss(tracetest_ent, tracetest_ent);
496                 if (trace_startsolid && ofs.z)
497                 {
498                         setorigin(tracetest_ent, targ.origin + ofs / 2);
499                         tracetoss(tracetest_ent, tracetest_ent);
500                         if (trace_startsolid && ofs.z)
501                         {
502                                 setorigin(tracetest_ent, targ.origin);
503                                 tracetoss(tracetest_ent, tracetest_ent);
504                                 if (trace_startsolid)
505                                         return false;
506                         }
507                 }
508         }
509         tracebox(trace_endpos, tracetest_ent.mins, tracetest_ent.maxs, trace_endpos - eZ * 1500, true, tracetest_ent);
510         return true;
511 }
512
513 bool trigger_push_testorigin_for_item(entity tracetest_ent, entity item, vector org)
514 {
515         setorigin(tracetest_ent, org);
516         tracetoss(tracetest_ent, tracetest_ent);
517
518         if(trace_startsolid)
519                 return false;
520         if (trace_ent == item)
521                 return true;
522
523         tracebox(trace_endpos, tracetest_ent.mins, tracetest_ent.maxs, trace_endpos - eZ * 1500, true, tracetest_ent);
524
525         if (trace_ent == item)
526                 return true;
527
528         return false;
529 }
530 #endif
531
532 #ifdef SVQC
533 vector trigger_push_get_start_point(entity this)
534 {
535         // calculate a typical start point for the jump
536         vector org = (this.absmin + this.absmax) * 0.5;
537         org.z = this.absmax.z - PL_MIN_CONST.z - 7;
538         return org;
539 }
540
541 float trigger_push_get_push_time(entity this, vector endpos)
542 {
543         vector org = trigger_push_get_start_point(this);
544
545         float grav = PHYS_GRAVITY(NULL);
546
547         entity t = this.enemy;
548         if (t)
549         {
550                 entity e = spawn();
551                 setsize(e, PL_MIN_CONST, PL_MAX_CONST);
552                 e.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
553                 vector v = trigger_push_calculatevelocity(org, t, this.height, e);
554                 vector v2 = trigger_push_calculatevelocity(endpos, t, this.height, e);
555                 delete(e);
556                 return (v.z + v2.z) / grav;
557         }
558         else if (!(this.target && this.target != ""))
559         {
560                 if (!this.team)
561                 {
562                         vector v = this.movedir;
563
564                         float t = v.z / grav;
565                         float jump_height = 1/2 * grav * (t ** 2);
566                         float remaining_height = org.z + jump_height - endpos.z;
567                         float v2_z = sqrt(2 * grav * remaining_height);
568
569                         return (v.z + v2_z) / grav;
570                 }
571         }
572         return 0;
573 }
574 #endif
575
576 /// if (item != NULL) returns true if the item can be reached by using this jumppad, false otherwise
577 /// if (item == NULL) tests jumppad's trajectory and eventually spawns waypoints for it (return value doesn't matter)
578 bool trigger_push_test(entity this, entity item)
579 {
580 #ifdef SVQC
581         vector org = trigger_push_get_start_point(this);
582 #endif
583
584         if (this.target)
585         {
586                 int n = 0;
587 #ifdef SVQC
588                 vector vel = '0 0 0';
589 #endif
590                 for(entity t = NULL; (t = find(t, targetname, this.target)); )
591                 {
592                         ++n;
593 #ifdef SVQC
594                         if(t.move_movetype != MOVETYPE_NONE)
595                                 continue;
596
597                         // bots can't tell teamed jumppads from normal ones
598                         if (this.team)
599                                 continue;
600
601                         entity e = spawn();
602                         setsize(e, PL_MIN_CONST, PL_MAX_CONST);
603                         e.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
604                         e.velocity = trigger_push_calculatevelocity(org, t, this.height, e);
605
606                         vel = e.velocity;
607                         vector best_target = '0 0 0';
608                         vector best_org = '0 0 0';
609                         vector best_vel = '0 0 0';
610                         bool valid_best_target = false;
611                         if (item)
612                         {
613                                 if (!trigger_push_testorigin_for_item(e, item, org))
614                                 {
615                                         delete(e);
616                                         return false;
617                                 }
618                         }
619                         else
620                         {
621                                 // optimization: if horizontal velocity is 0 then target is not good since the trajectory
622                                 // will definitely go back to the jumppad (horizontal velocity of best_vel can't be 0 anyway)
623                                 if ((e.velocity.x != 0 || e.velocity.y != 0)
624                                         && trigger_push_testorigin(e, t, this, org))
625                                 {
626                                         best_target = trace_endpos;
627                                         best_org = org;
628                                         best_vel = e.velocity;
629                                         valid_best_target = true;
630                                 }
631                         }
632
633                         vector new_org;
634                         vector dist = t.origin - org;
635                         if (dist.x || dist.y) // if not perfectly vertical
636                         {
637                                 // test trajectory with different starting points, sometimes the trajectory
638                                 // starting from the jumppad origin can't reach the real destination
639                                 // and destination waypoint ends up near the jumppad itself
640                                 vector flatdir = normalize(dist - eZ * dist.z);
641                                 vector ofs = flatdir * 0.5 * min(fabs(this.absmax.x - this.absmin.x), fabs(this.absmax.y - this.absmin.y));
642                                 new_org = org + ofs;
643
644                                 LABEL(new_test)
645                                 e.velocity = trigger_push_calculatevelocity(new_org, t, this.height, e);
646                                 if (item)
647                                 {
648                                         if (!trigger_push_testorigin_for_item(e, item, new_org))
649                                         {
650                                                 delete(e);
651                                                 return false;
652                                         }
653                                 }
654                                 else
655                                 {
656                                         vel = e.velocity;
657                                         if (vdist(vec2(e.velocity), <, autocvar_sv_maxspeed))
658                                                 e.velocity = autocvar_sv_maxspeed * flatdir;
659                                         if (trigger_push_testorigin(e, t, this, new_org) && (!valid_best_target || trace_endpos.z > best_target.z + 50))
660                                         {
661                                                 best_target = trace_endpos;
662                                                 best_org = new_org;
663                                                 best_vel = vel;
664                                                 valid_best_target = true;
665                                         }
666                                 }
667                                 if (ofs && new_org != org - ofs)
668                                 {
669                                         new_org = org - ofs;
670                                         goto new_test;
671                                 }
672                         }
673
674                         if (item)
675                         {
676                                 delete(e);
677                                 return true;
678                         }
679
680                         if (valid_best_target)
681                         {
682                                 if (!(boxesoverlap(this.absmin, this.absmax + eZ * 50, best_target + PL_MIN_CONST, best_target + PL_MAX_CONST)))
683                                 {
684                                         float velxy = vlen(vec2(best_vel));
685                                         float cost = vlen(vec2(t.origin - best_org)) / velxy;
686                                         if(velxy < autocvar_sv_maxspeed)
687                                                 velxy = autocvar_sv_maxspeed;
688                                         cost += vlen(vec2(best_target - t.origin)) / velxy;
689                                         waypoint_spawnforteleporter(this, best_target, cost, e);
690                                 }
691                         }
692                         delete(e);
693 #endif
694                 }
695
696                 if(item)
697                         return false;
698
699                 if(!n)
700                 {
701                         // no dest!
702 #ifdef SVQC
703                         objerror (this, "Jumppad with nonexistant target");
704 #endif
705                         return false;
706                 }
707                 else if(n == 1)
708                 {
709                         // exactly one dest - bots love that
710                         if (!this.team)
711                                 this.enemy = find(NULL, targetname, this.target);
712                         else // bots can't tell teamed jumppads from normal ones
713                                 this.enemy = NULL;
714                 }
715                 else
716                 {
717                         // have to use random selection every single time
718                         this.enemy = NULL;
719                 }
720
721         }
722 #ifdef SVQC
723         else
724         {
725                 if (!this.team)
726                 {
727                         entity e = spawn();
728                         setsize(e, PL_MIN_CONST, PL_MAX_CONST);
729                         e.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
730                         setorigin(e, org);
731                         e.velocity = this.movedir;
732                         tracetoss(e, e);
733                         if (item)
734                         {
735                                 bool r = (trace_ent == item);
736                                 delete(e);
737                                 return r;
738                         }
739                         if (!(boxesoverlap(this.absmin, this.absmax + eZ * 50, trace_endpos + PL_MIN_CONST, trace_endpos + PL_MAX_CONST)))
740                                 waypoint_spawnforteleporter(this, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity), e);
741                         delete(e);
742                 }
743                 else if (item)
744                         return false;
745         }
746
747         defer(this, 0.1, trigger_push_updatelink);
748 #endif
749         return true;
750 }
751
752 void trigger_push_findtarget(entity this)
753 {
754         trigger_push_test(this, NULL);
755 }
756
757 #ifdef SVQC
758 float trigger_push_send(entity this, entity to, float sf)
759 {
760         WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_PUSH);
761
762         WriteByte(MSG_ENTITY, this.team);
763         WriteInt24_t(MSG_ENTITY, this.spawnflags);
764         WriteByte(MSG_ENTITY, this.active);
765         WriteCoord(MSG_ENTITY, this.height);
766
767         trigger_common_write(this, true);
768
769         return true;
770 }
771
772 float trigger_push_velocity_send(entity this, entity to, float sf)
773 {
774         WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_PUSH_VELOCITY);
775
776         WriteByte(MSG_ENTITY, this.team);
777         WriteInt24_t(MSG_ENTITY, this.spawnflags);
778         WriteByte(MSG_ENTITY, this.active);
779         WriteCoord(MSG_ENTITY, this.speed);
780         WriteCoord(MSG_ENTITY, this.count);
781
782         trigger_common_write(this, true);
783
784         return true;
785 }
786
787 void trigger_push_updatelink(entity this)
788 {
789         this.SendFlags |= SF_TRIGGER_INIT;
790 }
791
792 void trigger_push_link(entity this)
793 {
794         trigger_link(this, trigger_push_send);
795 }
796
797 void trigger_push_velocity_link(entity this)
798 {
799         trigger_link(this, trigger_push_velocity_send);
800 }
801
802 /*
803  * ENTITY PARAMETERS:
804  *
805  *   target:  target of jump
806  *   height:  the absolute value is the height of the highest point of the jump
807  *            trajectory above the higher one of the player and the target.
808  *            the sign indicates whether the highest point is INSIDE (positive)
809  *            or OUTSIDE (negative) of the jump trajectory. General rule: use
810  *            positive values for targets mounted on the floor, and use negative
811  *            values to target a point on the ceiling.
812  *   movedir: if target is not set, movedir * speed * 10 is the velocity to be reached.
813  */
814 spawnfunc(trigger_push)
815 {
816         SetMovedir(this);
817
818         WarpZoneLib_ExactTrigger_Init(this, false);
819         BITSET_ASSIGN(this.effects, EF_NODEPTHTEST);
820         this.active = ACTIVE_ACTIVE;
821         this.use = trigger_push_use;
822         settouch(this, trigger_push_touch);
823
824         // normal push setup
825         if (!this.speed)
826                 this.speed = 1000;
827         this.movedir = this.movedir * this.speed * 10;
828
829         if (!this.noise)
830                 this.noise = "misc/jumppad.wav";
831         precache_sound (this.noise);
832
833         trigger_push_link(this); // link it now
834
835         IL_PUSH(g_jumppads, this);
836
837         // this must be called to spawn the teleport waypoints for bots
838         InitializeEntity(this, trigger_push_findtarget, INITPRIO_FINDTARGET);
839 }
840
841 /*
842  * ENTITY PARAMETERS:
843  *
844  *   target:  this points to the target_position to which the player will jump.
845  *   speed:   XY speed for player-directional velocity pads - either sets or adds to the player's horizontal velocity.
846  *   count:   Z speed for player-directional velocity pads - either sets or adds to the player's vertical velocity.
847  */
848 spawnfunc(trigger_push_velocity)
849 {
850         WarpZoneLib_ExactTrigger_Init(this, false);
851         BITSET_ASSIGN(this.effects, EF_NODEPTHTEST);
852         this.active = ACTIVE_ACTIVE;
853         this.use = trigger_push_use;
854         settouch(this, trigger_push_velocity_touch);
855
856         // normal push setup
857         if (!this.noise)
858                 this.noise = "misc/jumppad.wav";
859         precache_sound (this.noise);
860
861         trigger_push_velocity_link(this); // link it now
862 }
863
864
865 bool target_push_send(entity this, entity to, float sf)
866 {
867         WriteHeader(MSG_ENTITY, ENT_CLIENT_TARGET_PUSH);
868
869         WriteByte(MSG_ENTITY, this.cnt);
870         WriteString(MSG_ENTITY, this.targetname);
871         WriteVector(MSG_ENTITY, this.origin);
872
873         WriteAngleVector(MSG_ENTITY, this.angles);
874
875         return true;
876 }
877
878 void target_push_use(entity this, entity actor, entity trigger)
879 {
880         if(trigger.classname == "trigger_push" || trigger == this)
881                 return; // WTF, why is this a thing
882
883         jumppad_push(this, actor, false);
884 }
885
886 void target_push_link(entity this)
887 {
888         BITSET_ASSIGN(this.effects, EF_NODEPTHTEST);
889         Net_LinkEntity(this, false, 0, target_push_send);
890         //this.SendFlags |= 1; // update
891 }
892
893 void target_push_init(entity this)
894 {
895         this.mangle = this.angles;
896         setorigin(this, this.origin);
897         target_push_link(this);
898 }
899
900 spawnfunc(target_push)
901 {
902         target_push_init(this); // normal push target behaviour can be combined with a legacy pusher?
903         this.use = target_push_use;
904
905         if(this.target && this.target != "") // Q3 or old style Nexuiz pusher
906                 InitializeEntity(this, trigger_push_findtarget, INITPRIO_FINDTARGET);
907         else // Q3 .angles and .speed pusher
908         {
909                 if (!this.speed)
910                         this.speed = 1000;
911                 SetMovedir(this); // this clears .angles so it must be after target_push_init()
912                 this.movedir *= this.speed;
913         }
914
915         if (!this.noise)
916         {
917                 if (Q3COMPAT_COMMON && !(this.spawnflags & Q3_TARGET_PUSH_JUMPPAD))
918                         this.noise = "sound/misc/windfly.wav"; // Q3 mappers provide this, it's not in pak0
919                 else
920                         this.noise = "misc/jumppad.wav";
921         }
922         precache_sound (this.noise);
923 }
924
925 spawnfunc(info_notnull)
926 {
927         target_push_init(this);
928 }
929 spawnfunc(target_position)
930 {
931         target_push_init(this);
932 }
933
934 #elif defined(CSQC)
935
936 NET_HANDLE(ENT_CLIENT_TRIGGER_PUSH, bool isnew)
937 {
938         int mytm = ReadByte(); if(mytm) { this.team = mytm - 1; }
939         this.spawnflags = ReadInt24_t();
940         this.active = ReadByte();
941         this.height = ReadCoord();
942
943         trigger_common_read(this, true);
944
945         this.entremove = trigger_remove_generic;
946         this.solid = SOLID_TRIGGER;
947         settouch(this, trigger_push_touch);
948         this.move_time = time;
949         defer(this, 0.25, trigger_push_findtarget);
950
951         return true;
952 }
953
954 NET_HANDLE(ENT_CLIENT_TRIGGER_PUSH_VELOCITY, bool isnew)
955 {
956         int mytm = ReadByte(); if(mytm) { this.team = mytm - 1; }
957         this.spawnflags = ReadInt24_t();
958         this.active = ReadByte();
959         this.speed = ReadCoord();
960         this.count = ReadCoord();
961
962         trigger_common_read(this, true);
963
964         this.entremove = trigger_remove_generic;
965         this.solid = SOLID_TRIGGER;
966         settouch(this, trigger_push_velocity_touch);
967         this.move_time = time;
968
969         return true;
970 }
971
972 void target_push_remove(entity this)
973 {
974         // strfree(this.classname);
975         strfree(this.targetname);
976 }
977
978 NET_HANDLE(ENT_CLIENT_TARGET_PUSH, bool isnew)
979 {
980         this.cnt = ReadByte();
981         this.targetname = strzone(ReadString());
982         this.origin = ReadVector();
983
984         this.angles = ReadAngleVector();
985
986         return = true;
987
988         setorigin(this, this.origin);
989
990         this.drawmask = MASK_NORMAL;
991         this.entremove = target_push_remove;
992 }
993 #endif