+ setsize(e, PL_MIN_CONST, PL_MAX_CONST);
+ e.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
+ e.velocity = trigger_push_calculatevelocity(org, t, this.height, e);
+
+ if(item)
+ {
+ setorigin(e, org);
+ tracetoss(e, e);
+ bool r = (trace_ent == item);
+ delete(e);
+ return r;
+ }
+
+ vel = e.velocity;
+ vector best_target = '0 0 0';
+ vector best_org = '0 0 0';
+ vector best_vel = '0 0 0';
+ bool valid_best_target = false;
+ if (trigger_push_testorigin(e, t, this, org))
+ {
+ best_target = trace_endpos;
+ best_org = org;
+ best_vel = e.velocity;
+ valid_best_target = true;
+ }
+
+ vector new_org;
+ vector dist = t.origin - org;
+ if (dist.x || dist.y) // if not perfectly vertical
+ {
+ // test trajectory with different starting points, sometimes the trajectory
+ // starting from the jumppad origin can't reach the real destination
+ // and destination waypoint ends up near the jumppad itself
+ vector flatdir = normalize(dist - eZ * dist.z);
+ vector ofs = flatdir * 0.5 * min(fabs(this.absmax.x - this.absmin.x), fabs(this.absmax.y - this.absmin.y));
+ new_org = org + ofs;
+ e.velocity = trigger_push_calculatevelocity(new_org, t, this.height, e);
+ vel = e.velocity;
+ if (vdist(vec2(e.velocity), <, autocvar_sv_maxspeed))
+ e.velocity = autocvar_sv_maxspeed * flatdir;
+ if (trigger_push_testorigin(e, t, this, new_org) && (!valid_best_target || trace_endpos.z > best_target.z + 50))
+ {
+ best_target = trace_endpos;
+ best_org = new_org;
+ best_vel = vel;
+ valid_best_target = true;
+ }
+ new_org = org - ofs;
+ e.velocity = trigger_push_calculatevelocity(new_org, t, this.height, e);
+ vel = e.velocity;
+ if (vdist(vec2(e.velocity), <, autocvar_sv_maxspeed))
+ e.velocity = autocvar_sv_maxspeed * flatdir;
+ if (trigger_push_testorigin(e, t, this, new_org) && (!valid_best_target || trace_endpos.z > best_target.z + 50))
+ {
+ best_target = trace_endpos;
+ best_org = new_org;
+ best_vel = vel;
+ valid_best_target = true;
+ }
+ }
+
+ if (valid_best_target)
+ {
+ if (!(boxesoverlap(this.absmin, this.absmax + eZ * 50, best_target + PL_MIN_CONST, best_target + PL_MAX_CONST)))
+ {
+ float velxy = vlen(vec2(best_vel));
+ float cost = vlen(vec2(t.origin - best_org)) / velxy;
+ if(velxy < autocvar_sv_maxspeed)
+ velxy = autocvar_sv_maxspeed;
+ cost += vlen(vec2(best_target - t.origin)) / velxy;
+ waypoint_spawnforteleporter(this, best_target, cost, e);
+ }
+ }
+ delete(e);