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