Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
jumppads.qc
Go to the documentation of this file.
1#include "jumppads.qh"
2// TODO: split target_push and put it in the target folder
3#ifdef SVQC
5
6void trigger_push_use(entity this, entity actor, entity trigger)
7{
8 if(teamplay)
9 {
10 this.team = actor.team;
12 }
13}
14#endif
15
16REGISTER_NET_LINKED(ENT_CLIENT_TRIGGER_PUSH)
17REGISTER_NET_LINKED(ENT_CLIENT_TRIGGER_PUSH_VELOCITY)
18REGISTER_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 */
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(pushed_entity);
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.
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 += 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 = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
90 // ALWAYS solvable because jumpheight >= zdist
91 if(!solution.z)
92 // just in case it is not solvable due to roundoff errors,
93 // assume two equal solutions at their center (this is mainly for the usual case with ht == 0)
94 solution_y = solution.x;
95 if(zdist == 0)
96 // solution_x is 0 in this case, so don't use it,
97 // but rather use solution_y (which will be sqrt(0.5 * jumpheight / grav), actually)
98 solution_x = solution.y;
99
100 float flighttime;
101 if(zdist < 0)
102 {
103 // down-jump
104 if(ht < 0)
105 {
106 // almost straight line type
107 // jump apex is before the jump
108 // we must take the larger one
109 flighttime = solution.y;
110 }
111 else
112 {
113 // regular jump
114 // jump apex is during the jump
115 // we must take the larger one too
116 flighttime = solution.y;
117 }
118 }
119 else
120 {
121 // up-jump
122 if(ht < 0)
123 {
124 // almost straight line type
125 // jump apex is after the jump
126 // we must take the smaller one
127 flighttime = solution.x;
128 }
129 else
130 {
131 // regular jump
132 // jump apex is during the jump
133 // we must take the larger one
134 flighttime = solution.y;
135 }
136 }
137 vs = sdist / flighttime;
138
139 // finally calculate the velocity
140 return sdir * vs + '0 0 1' * vz;
141}
142
143vector trigger_push_velocity_calculatevelocity(entity this, vector org, entity tgt, float speed, float count, entity pushed_entity, bool already_pushed)
144{
145 bool is_playerdir_xy = boolean(this.spawnflags & PUSH_VELOCITY_PLAYERDIR_XY);
146 bool is_add_xy = boolean(this.spawnflags & PUSH_VELOCITY_ADD_XY);
147 bool is_playerdir_z = boolean(this.spawnflags & PUSH_VELOCITY_PLAYERDIR_Z);
148 bool is_add_z = boolean(this.spawnflags & PUSH_VELOCITY_ADD_Z);
149 bool is_bidirectional_xy = boolean(this.spawnflags & PUSH_VELOCITY_BIDIRECTIONAL_XY);
150 bool is_bidirectional_z = boolean(this.spawnflags & PUSH_VELOCITY_BIDIRECTIONAL_Z);
151 bool is_clamp_negative_adds = boolean(this.spawnflags & PUSH_VELOCITY_CLAMP_NEGATIVE_ADDS);
152
153 vector sdir = normalize(vec2(pushed_entity.velocity));
154 float zdir = pushed_entity.velocity.z;
155 if(zdir != 0) zdir = copysign(1, zdir);
156
157 vector vs_tgt = '0 0 0';
158 float vz_tgt = 0;
159 if (!is_playerdir_xy || !is_playerdir_z)
160 {
161 vector vel_tgt = trigger_push_calculatevelocity(org, tgt, 0, pushed_entity);
162 vs_tgt = vec2(vel_tgt);
163 vz_tgt = vel_tgt.z;
164
165 // bidirectional jump pads do not play nicely with xonotic's jump pad targets
166 if (is_bidirectional_xy)
167 {
168 if (normalize(vs_tgt) * sdir < 0)
169 {
170 vs_tgt *= -1;
171 }
172 }
173
174 if (is_bidirectional_z)
175 {
176 if (signbit(vz_tgt) != signbit(zdir))
177 {
178 vz_tgt *= -1;
179 }
180 }
181 }
182
183 vector vs;
184 if (is_playerdir_xy)
185 {
186 vs = sdir * speed;
187 }
188 else
189 {
190 vs = vs_tgt;
191 }
192
193 float vz;
194 if (is_playerdir_z)
195 {
196 vz = zdir * count;
197 }
198 else
199 {
200 vz = vz_tgt;
201 }
202
203 if (is_add_xy)
204 {
205 vector vs_add = vec2(pushed_entity.velocity);
206 if (already_pushed)
207 {
208 vs = vs_add;
209 }
210 else
211 {
212 vs += vs_add;
213
214 if (is_clamp_negative_adds)
215 {
216 if ((normalize(vs) * sdir) < 0)
217 {
218 vs = '0 0 0';
219 }
220 }
221 }
222 }
223
224 if (is_add_z)
225 {
226 float vz_add = pushed_entity.velocity.z;
227 if (already_pushed)
228 {
229 vz = vz_add;
230 }
231 else
232 {
233 vz += vz_add;
234
235 if (is_clamp_negative_adds)
236 {
237 if (signbit(vz) != signbit(zdir))
238 {
239 vz = 0;
240 }
241 }
242 }
243 }
244
245 return vs + '0 0 1' * vz;
246}
247
248#ifdef SVQC
250{
251 bool found = false;
252 IL_EACH(g_moveables, it.last_pushed == this,
253 {
254 if(!WarpZoneLib_ExactTrigger_Touch(this, it, false))
255 it.last_pushed = NULL;
256 else
257 found = true;
258 });
259
260 if(found)
261 this.nextthink = time;
262 else
263 setthink(this, func_null);
264}
265#endif
266
267bool jumppad_push(entity this, entity targ, bool is_velocity_pad)
268{
269 if (!isPushable(targ))
270 return false;
271
272 vector org = targ.origin;
273
275 org = (this.absmin + this.absmax) * 0.5;
276
277 bool already_pushed = false;
278 if(is_velocity_pad) // remember velocity jump pads
279 {
280 if(this == targ.last_pushed || (targ.last_pushed && !STAT(Q3COMPAT, targ))) // if q3compat is active overwrite last stored jump pad, otherwise ignore
281 {
282 already_pushed = true;
283 }
284 else
285 {
286 targ.last_pushed = this; // may be briefly out of sync between client and server if client prediction is toggled
287
288 #ifdef SVQC
290 this.nextthink = time;
291 #endif
292 }
293 }
294
295 if(this.enemy)
296 {
297 if(!is_velocity_pad)
298 {
299 targ.velocity = trigger_push_calculatevelocity(org, this.enemy, this.height, targ);
300 }
301 else
302 {
303 targ.velocity = trigger_push_velocity_calculatevelocity(this, org, this.enemy, this.speed, this.count, targ, already_pushed);
304 }
305 }
306 else if(this.target && this.target != "")
307 {
308 entity e;
310 for(e = NULL; (e = find(e, targetname, this.target)); )
311 {
312 if(e.cnt)
313 RandomSelection_AddEnt(e, e.cnt, 1);
314 else
315 RandomSelection_AddEnt(e, 1, 1);
316 }
317 if(!is_velocity_pad)
318 {
320 }
321 else
322 {
323 targ.velocity = trigger_push_velocity_calculatevelocity(this, org, RandomSelection_chosen_ent, this.speed, this.count, targ, already_pushed);
324 }
325 }
326 else
327 {
328 if(!is_velocity_pad)
329 {
330 targ.velocity = this.movedir;
331 }
332 else
333 {
334#ifdef SVQC
335 objerror (this, "Jumppad with no target");
336#endif
337 return false;
338 }
339 }
340
341 if(!is_velocity_pad) UNSET_ONGROUND(targ);
342
343#ifdef CSQC
344 if (targ.flags & FL_PROJECTILE)
345 {
346 targ.angles = vectoangles (targ.velocity);
347 switch(targ.move_movetype)
348 {
349 case MOVETYPE_FLY:
351 targ.gravity = 1;
352 break;
355 targ.gravity = 1;
356 break;
357 }
358 }
359#endif
360
361#ifdef SVQC
362 if (IS_PLAYER(targ))
363 {
364 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
365 targ.oldvelocity = targ.velocity;
366
367 // prevent sound spam when a player hits the jumppad more than once
368 // or when a dead player gets stuck in the jumppad for some reason
369 if(!already_pushed && this.pushltime < time && !(IS_DEAD(targ) && targ.velocity == '0 0 0'))
370 {
371 if (Q3COMPAT_COMMON && this.classname == "target_push")
372 this.pushltime = time + 1.5;
373 else
374 {
375 // flash when activated
376 Send_Effect(EFFECT_JUMPPAD, targ.origin, targ.velocity, 1);
377 this.pushltime = time + 0.2;
378 }
379 _sound (targ, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
380 }
381
382 if(IS_REAL_CLIENT(targ) || IS_BOT_CLIENT(targ))
383 {
384 bool found = false;
385 for(int i = 0; i < targ.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
386 if(targ.(jumppadsused[i]) == this)
387 found = true;
388 if(!found)
389 {
390 targ.(jumppadsused[targ.jumppadcount % NUM_JUMPPADSUSED]) = this;
391 ++targ.jumppadcount;
392 }
393
394 if(IS_REAL_CLIENT(targ))
395 {
396 if(this.message)
397 centerprint(targ, this.message);
398 }
399 else
400 {
401 targ.lastteleporttime = time;
402 targ.lastteleport_origin = targ.origin;
403 }
404
405 if (!IS_DEAD(targ))
407 }
408 else
409 targ.jumppadcount = 1;
410
411 // reset tracking of who pushed you into a hazard (for kill credit)
412 targ.pushltime = 0;
413 targ.istypefrag = 0;
414 }
415
416 if(this.enemy.target)
417 SUB_UseTargets(this.enemy, targ, this);
418
419 if (targ.flags & FL_PROJECTILE)
420 {
421 targ.angles = vectoangles (targ.velocity);
422 targ.com_phys_gravity_factor = 1;
423 switch(targ.move_movetype)
424 {
425 case MOVETYPE_FLY:
427 targ.gravity = 1;
428 break;
431 targ.gravity = 1;
432 break;
433 }
435 }
436#endif
437
438 return true;
439}
440
442{
443 if (this.active == ACTIVE_NOT)
444 return;
445
446 if(this.team)
447 if(((this.spawnflags & INVERT_TEAMS) == 0) == (DIFF_TEAM(this, toucher)))
448 return;
449
451
452 noref bool success = jumppad_push(this, toucher, false);
453
454#ifdef SVQC
455 if (success && (this.spawnflags & PUSH_ONCE))
456 {
457 settouch(this, func_null);
458 setthink(this, SUB_Remove);
459 this.nextthink = time;
460 }
461#endif
462}
463
465{
466 if (this.active == ACTIVE_NOT)
467 return;
468
469 if(this.team && DIFF_TEAM(this, toucher))
470 return;
471
473
474 jumppad_push(this, toucher, true);
475}
476
477#ifdef SVQC
478void trigger_push_link(entity this);
480bool trigger_push_testorigin(entity tracetest_ent, entity targ, entity jp, vector org)
481{
482 setorigin(tracetest_ent, org);
483 tracetoss(tracetest_ent, tracetest_ent);
485 return false;
486
487 if (!jp.height)
488 {
489 // since tracetoss starting from jumppad's origin often fails when target
490 // is very close to real destination, start it directly from target's
491 // origin instead
492 vector ofs = '0 0 0';
493 if (vdist(vec2(tracetest_ent.velocity), <, autocvar_sv_maxspeed))
494 ofs = stepheightvec;
495
496 tracetest_ent.velocity.z = 0;
497 setorigin(tracetest_ent, targ.origin + ofs);
498 tracetoss(tracetest_ent, tracetest_ent);
499 if (trace_startsolid && ofs.z)
500 {
501 setorigin(tracetest_ent, targ.origin + ofs * 0.5);
502 tracetoss(tracetest_ent, tracetest_ent);
503 if (trace_startsolid && ofs.z)
504 {
505 setorigin(tracetest_ent, targ.origin);
506 tracetoss(tracetest_ent, tracetest_ent);
508 return false;
509 }
510 }
511 }
512 tracebox(trace_endpos, tracetest_ent.mins, tracetest_ent.maxs, trace_endpos - eZ * 1500, true, tracetest_ent);
513 return true;
514}
515
517{
518 setorigin(tracetest_ent, org);
519 tracetoss(tracetest_ent, tracetest_ent);
520
522 return false;
523 if (trace_ent == item)
524 return true;
525
526 tracebox(trace_endpos, tracetest_ent.mins, tracetest_ent.maxs, trace_endpos - eZ * 1500, true, tracetest_ent);
527
528 if (trace_ent == item)
529 return true;
530
531 return false;
532}
533#endif
534
535#ifdef SVQC
536// get the push entity in cases where a non-push entity acts as the trigger of a jump pad
538{
539 // triggers could point to several pusher but each pusher would overwrite the effect of the previous one
540 // this means only one pusher has to be considered
541 // we still have to traverse the target list though since entities other than pushers could be in it
543 if(this.classname != "trigger_push")
544 {
545 for(entity t = ftoe(maxclients); (t = find(t, targetname, this.target)); )
546 {
547 if(t.classname == "target_push")
548 {
549 pusher = t;
550 break;
551 }
552 }
553
554 if(!pusher) objerror (this, "Jump pad with non-existent target");
555 }
556
557 if(pusher)
558 return pusher; // if the target field points to a target_push entity, return it
559 else
560 return this; // otherwise, return the original entity
561}
562
564{
565 // calculate a typical start point for the jump
566 vector org = (this.absmin + this.absmax) * 0.5;
567 org.z = this.absmax.z - PL_MIN_CONST.z - 7;
568 return org;
569}
570
572{
574 entity pusher = get_pusher_from_trigger(this); // function might get called from a non-push trigger entity
575
576 float grav = PHYS_GRAVITY(NULL);
577
578 entity t = pusher.enemy;
579 if (t)
580 {
581 entity e = spawn();
582 setsize(e, PL_MIN_CONST, PL_MAX_CONST);
585 vector v2 = trigger_push_calculatevelocity(endpos, t, pusher.height, e);
586 delete(e);
587 return (v.z + v2.z) / grav;
588 }
589 else if (!(pusher.target && pusher.target != ""))
590 {
591 if (!this.team)
592 {
593 vector v = pusher.movedir;
594
595 float t = v.z / grav;
596 float jump_height = 1/2 * grav * (t ** 2);
597 float remaining_height = org.z + jump_height - endpos.z;
598 float v2_z = sqrt(2 * grav * remaining_height);
599
600 return (v.z + v2_z) / grav;
601 }
602 }
603 return 0;
604}
605#endif
606
607// if (item != NULL) returns true if the item can be reached by using this jumppad, false otherwise
608// if (item == NULL) tests jumppad's trajectory and eventually spawns waypoints for it (return value doesn't matter)
609// NOTE: for simplicity's sake it improperly tests jumppad bboxes instead of bmodels
611{
612#ifdef SVQC
614 entity pusher = get_pusher_from_trigger(this); // function might get called from a non-push trigger entity
615#elif defined(CSQC)
616 entity pusher = this; // client-side code never calls this on a non-push entity
617#endif
618
619 if (pusher.target)
620 {
621 int n = 0;
622#ifdef SVQC
623 vector vel = '0 0 0';
624#endif
625 for(entity t = NULL; (t = find(t, targetname, pusher.target)); )
626 {
627 ++n;
628#ifdef SVQC
629 if(t.move_movetype != MOVETYPE_NONE)
630 continue;
631
632 // bots can't tell teamed jumppads from normal ones
633 if (this.team)
634 continue;
635
636 entity e = spawn();
637 setsize(e, PL_MIN_CONST, PL_MAX_CONST);
639 e.velocity = trigger_push_calculatevelocity(org, t, pusher.height, e);
640
641 vel = e.velocity;
642 vector best_target = '0 0 0';
643 vector best_org = '0 0 0';
644 vector best_vel = '0 0 0';
645 bool valid_best_target = false;
646 if (item)
647 {
649 {
650 delete(e);
651 return false;
652 }
653 }
654 else
655 {
656 // optimization: if horizontal velocity is 0 then target is not good since the trajectory
657 // will definitely go back to the jumppad (horizontal velocity of best_vel can't be 0 anyway)
658 if ((e.velocity.x != 0 || e.velocity.y != 0)
660 {
661 best_target = trace_endpos;
662 best_org = org;
663 best_vel = e.velocity;
664 valid_best_target = true;
665 }
666 }
667
668 vector new_org;
669 vector dist = t.origin - org;
670 if (dist.x || dist.y) // if not perfectly vertical
671 {
672 // test trajectory with different starting points, sometimes the trajectory
673 // starting from the jumppad origin can't reach the real destination
674 // and destination waypoint ends up near the jumppad itself
675 vector flatdir = normalize(dist - eZ * dist.z);
676 vector ofs = flatdir * 0.5 * min(fabs(this.absmax.x - this.absmin.x), fabs(this.absmax.y - this.absmin.y));
677 new_org = org + ofs;
678
679 LABEL(new_test)
680 e.velocity = trigger_push_calculatevelocity(new_org, t, pusher.height, e);
681 if (item)
682 {
683 if (!trigger_push_testorigin_for_item(e, item, new_org))
684 {
685 delete(e);
686 return false;
687 }
688 }
689 else
690 {
691 vel = e.velocity;
692 if (vdist(vec2(e.velocity), <, autocvar_sv_maxspeed))
693 e.velocity = autocvar_sv_maxspeed * flatdir;
694 if (trigger_push_testorigin(e, t, pusher, new_org) && (!valid_best_target || trace_endpos.z > best_target.z + 50))
695 {
696 best_target = trace_endpos;
697 best_org = new_org;
698 best_vel = vel;
699 valid_best_target = true;
700 }
701 }
702 if (ofs && new_org != org - ofs)
703 {
704 new_org = org - ofs;
705 goto new_test;
706 }
707 }
708
709 if (item)
710 {
711 delete(e);
712 return true;
713 }
714
715 if (valid_best_target)
716 {
717 if (!(boxesoverlap(this.absmin, this.absmax + eZ * 50, best_target + PL_MIN_CONST, best_target + PL_MAX_CONST)))
718 {
719 float velxy = vlen(vec2(best_vel));
720 float cost = vlen(vec2(t.origin - best_org)) / velxy;
721 if(velxy < autocvar_sv_maxspeed)
722 velxy = autocvar_sv_maxspeed;
723 cost += vlen(vec2(best_target - t.origin)) / velxy;
724 waypoint_spawnforteleporter(this, best_target, cost, e);
725 }
726 }
727 delete(e);
728#endif
729 }
730
731 if(item)
732 return false;
733
734 if(!n)
735 {
736 // no dest!
737#ifdef SVQC
738 objerror (this, "Jumppad with nonexistant target");
739#endif
740 return false;
741 }
742 else if(n == 1)
743 {
744 // exactly one dest - bots love that
745 if (!this.team)
746 pusher.enemy = find(NULL, targetname, pusher.target);
747 else // bots can't tell teamed jumppads from normal ones
748 pusher.enemy = NULL;
749 }
750 else
751 {
752 // have to use random selection every single time
753 pusher.enemy = NULL;
754 }
755
756 }
757#ifdef SVQC
758 else
759 {
760 if (!this.team)
761 {
762 entity e = spawn();
763 setsize(e, PL_MIN_CONST, PL_MAX_CONST);
765 setorigin(e, org);
766 e.velocity = pusher.movedir;
767 tracetoss(e, e);
768 if (item)
769 {
770 bool r = (trace_ent == item);
771 delete(e);
772 return r;
773 }
776 delete(e);
777 }
778 else if (item)
779 return false;
780 }
781
783#endif
784 return true;
785}
786
788{
789 trigger_push_test(this, NULL);
790}
791
792#ifdef SVQC
793float trigger_push_send(entity this, entity to, float sf)
794{
795 WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_PUSH);
796
798 WriteInt24_t(MSG_ENTITY, this.spawnflags);
801
802 trigger_common_write(this, true);
803
804 return true;
805}
806
807float trigger_push_velocity_send(entity this, entity to, float sf)
808{
809 WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_PUSH_VELOCITY);
810
812 WriteInt24_t(MSG_ENTITY, this.spawnflags);
816
817 trigger_common_write(this, true);
818
819 return true;
820}
821
823{
825}
826
831
836
837/*
838 * ENTITY PARAMETERS:
839 *
840 * target: target of jump
841 * height: the absolute value is the height of the highest point of the jump
842 * trajectory above the higher one of the player and the target.
843 * the sign indicates whether the highest point is INSIDE (positive)
844 * or OUTSIDE (negative) of the jump trajectory. General rule: use
845 * positive values for targets mounted on the floor, and use negative
846 * values to target a point on the ceiling.
847 * movedir: if target is not set, movedir * speed * 10 is the velocity to be reached.
848 */
849spawnfunc(trigger_push)
850{
851 SetMovedir(this);
852
855 this.active = ACTIVE_ACTIVE;
856 this.use = trigger_push_use;
858
859 // normal push setup
860 if (!this.speed)
861 this.speed = 1000;
862 this.movedir *= this.speed * 10;
863
864 if (!this.noise)
865 this.noise = "misc/jumppad.wav";
866 precache_sound (this.noise);
867
868 trigger_push_link(this); // link it now
869
870 IL_PUSH(g_jumppads, this);
871
872 // this must be called to spawn the teleport waypoints for bots
874}
875
876/*
877 * ENTITY PARAMETERS:
878 *
879 * target: this points to the target_position to which the player will jump.
880 * speed: XY speed for player-directional velocity pads - either sets or adds to the player's horizontal velocity.
881 * count: Z speed for player-directional velocity pads - either sets or adds to the player's vertical velocity.
882 */
883spawnfunc(trigger_push_velocity)
884{
887 this.active = ACTIVE_ACTIVE;
888 this.use = trigger_push_use;
890
891 // normal push setup
892 if (!this.noise)
893 this.noise = "misc/jumppad.wav";
894 precache_sound (this.noise);
895
896 trigger_push_velocity_link(this); // link it now
897}
898
899
900bool target_push_send(entity this, entity to, float sf)
901{
902 WriteHeader(MSG_ENTITY, ENT_CLIENT_TARGET_PUSH);
903
904 WriteByte(MSG_ENTITY, this.cnt);
906 WriteVector(MSG_ENTITY, this.origin);
907
908 WriteAngleVector(MSG_ENTITY, this.angles);
909
910 return true;
911}
912
913void target_push_use(entity this, entity actor, entity trigger)
914{
915 if(trigger.classname == "trigger_push" || trigger == this)
916 return; // WTF, why is this a thing
917
918 jumppad_push(this, actor, false);
919}
920
922{
924 Net_LinkEntity(this, false, 0, target_push_send);
925 //this.SendFlags |= 1; // update
926}
927
929{
930 this.mangle = this.angles;
931 setorigin(this, this.origin);
932 target_push_link(this);
933}
934
935spawnfunc(target_push)
936{
937 target_push_init(this); // normal push target behaviour can be combined with a legacy pusher?
938 this.use = target_push_use;
939
940 if(this.target && this.target != "") // Q3 or old style Nexuiz pusher
941 {
942 for (entity trigger_ent = findchain(target, this.targetname); trigger_ent; trigger_ent = trigger_ent.chain)
943 {
944 // add the triggering entity to the g_jumppads list
945 // multiple jump pads can use the same target_push
946 if(!IL_CONTAINS(g_jumppads, trigger_ent))
947 {
948 IL_PUSH(g_jumppads, trigger_ent);
950 }
951 }
952 }
953 else // Q3 .angles and .speed pusher
954 {
955 if (!this.speed)
956 this.speed = 1000;
957 SetMovedir(this); // this clears .angles so it must be after target_push_init()
958 this.movedir *= this.speed;
959 }
960
961 if (!this.noise)
962 {
964 this.noise = "sound/misc/windfly.wav"; // Q3 mappers provide this, it's not in pak0
965 else
966 this.noise = "misc/jumppad.wav";
967 }
968 precache_sound (this.noise);
969}
970
971spawnfunc(info_notnull)
972{
973 target_push_init(this);
974}
975spawnfunc(target_position)
976{
977 target_push_init(this);
978}
979
980#elif defined(CSQC)
981
982NET_HANDLE(ENT_CLIENT_TRIGGER_PUSH, bool isnew)
983{
984 int mytm = ReadByte(); if(mytm) { this.team = mytm - 1; }
985 this.spawnflags = ReadInt24_t();
986 this.active = ReadByte();
987 this.height = ReadCoord();
988
989 trigger_common_read(this, true);
990
991 this.entremove = trigger_remove_generic;
992 this.solid = SOLID_TRIGGER;
994 this.move_time = time;
995 defer(this, 0.25, trigger_push_findtarget);
996
997 return true;
998}
999
1000NET_HANDLE(ENT_CLIENT_TRIGGER_PUSH_VELOCITY, bool isnew)
1001{
1002 int mytm = ReadByte(); if(mytm) { this.team = mytm - 1; }
1003 this.spawnflags = ReadInt24_t();
1004 this.active = ReadByte();
1005 this.speed = ReadCoord();
1006 this.count = ReadCoord();
1007
1008 trigger_common_read(this, true);
1009
1010 this.entremove = trigger_remove_generic;
1011 this.solid = SOLID_TRIGGER;
1013 this.move_time = time;
1014
1015 return true;
1016}
1017
1018void target_push_remove(entity this)
1019{
1020 // strfree(this.classname);
1021 strfree(this.targetname);
1022}
1023
1024NET_HANDLE(ENT_CLIENT_TARGET_PUSH, bool isnew)
1025{
1026 this.cnt = ReadByte();
1027 this.targetname = strzone(ReadString());
1028 this.origin = ReadVector();
1029
1030 this.angles = ReadAngleVector();
1031
1032 return = true;
1033
1034 setorigin(this, this.origin);
1035
1036 this.drawmask = MASK_NORMAL;
1037 this.entremove = target_push_remove;
1038}
1039#endif
void animdecide_setaction(entity e, float action, float restart)
const int ANIMACTION_JUMP
void waypoint_spawnforteleporter(entity e, vector destination, float timetaken, entity tracetest_ent)
float height
Definition bobbing.qc:3
#define boolean(value)
Definition bool.qh:9
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define ReadString
float cnt
Definition powerups.qc:24
string message
Definition powerups.qc:19
float count
Definition powerups.qc:22
int team
Definition main.qh:188
int spawnflags
Definition ammo.qh:15
#define IS_DEAD(s)
Definition player.qh:244
float autocvar_sv_maxspeed
Definition player.qh:53
#define IS_PLAYER(s)
Definition player.qh:242
#define Q3COMPAT_COMMON
Definition stats.qh:370
#define LABEL(id)
Definition compiler.qh:34
const vector PL_MIN_CONST
Definition constants.qh:53
const int FL_PROJECTILE
Definition constants.qh:77
const int INITPRIO_FINDTARGET
Definition constants.qh:89
const vector PL_MAX_CONST
Definition constants.qh:52
string classname
float drawmask
float maxclients
entity trace_ent
float DPCONTENTS_BOTCLIP
const float SOLID_TRIGGER
float DPCONTENTS_SOLID
const float MASK_NORMAL
float DPCONTENTS_BODY
float effects
float DPCONTENTS_PLAYERCLIP
float time
vector trace_endpos
float trace_startsolid
float nextthink
vector absmax
const float EF_NODEPTHTEST
vector origin
float solid
vector absmin
#define spawn
#define use
void UpdateCSQCProjectile(entity e)
void defer(entity this, float fdelay, void(entity) func)
Execute func() after time + fdelay.
Definition defer.qh:26
void SUB_Remove(entity this)
Remove entity.
Definition defer.qh:12
const int ACTIVE_NOT
Definition defs.qh:36
const int INVERT_TEAMS
Definition defs.qh:10
const int SF_TRIGGER_INIT
Definition defs.qh:22
int active
Definition defs.qh:34
const int ACTIVE_ACTIVE
Definition defs.qh:37
const int SF_TRIGGER_UPDATE
Definition defs.qh:23
float speed
Definition dynlight.qc:9
void Send_Effect(entity eff, vector eff_loc, vector eff_vel, int eff_cnt)
Definition all.qc:155
WriteString(chan, ent.netname)
ent angles
Definition ent_cs.qc:146
WriteByte(chan, ent.angles.y/DEC_FACTOR)
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
ERASEABLE bool IL_CONTAINS(IntrusiveList this, entity it)
#define IL_EACH(this, cond, body)
float trigger_push_send(entity this, entity to, float sf)
Definition jumppads.qc:793
vector trigger_push_get_start_point(entity this)
Definition jumppads.qc:563
void target_push_link(entity this)
Definition jumppads.qc:921
bool trigger_push_testorigin(entity tracetest_ent, entity targ, entity jp, vector org)
Definition jumppads.qc:480
bool trigger_push_testorigin_for_item(entity tracetest_ent, entity item, vector org)
Definition jumppads.qc:516
void trigger_push_use(entity this, entity actor, entity trigger)
Definition jumppads.qc:6
void target_push_init(entity this)
Definition jumppads.qc:928
void trigger_push_findtarget(entity this)
Definition jumppads.qc:787
bool trigger_push_test(entity this, entity item)
Definition jumppads.qc:610
bool jumppad_push(entity this, entity targ, bool is_velocity_pad)
Definition jumppads.qc:267
entity get_pusher_from_trigger(entity this)
Definition jumppads.qc:537
float trigger_push_get_push_time(entity this, vector endpos)
Definition jumppads.qc:571
vector trigger_push_calculatevelocity(vector org, entity tgt, float ht, entity pushed_entity)
Definition jumppads.qc:32
bool target_push_send(entity this, entity to, float sf)
Definition jumppads.qc:900
void trigger_push_link(entity this)
Definition jumppads.qc:827
void trigger_push_velocity_think(entity this)
Definition jumppads.qc:249
float trigger_push_velocity_send(entity this, entity to, float sf)
Definition jumppads.qc:807
void trigger_push_updatelink(entity this)
Definition jumppads.qc:822
void trigger_push_velocity_link(entity this)
Definition jumppads.qc:832
vector trigger_push_velocity_calculatevelocity(entity this, vector org, entity tgt, float speed, float count, entity pushed_entity, bool already_pushed)
Definition jumppads.qc:143
void trigger_push_velocity_touch(entity this, entity toucher)
Definition jumppads.qc:464
void target_push_use(entity this, entity actor, entity trigger)
Definition jumppads.qc:913
void trigger_push_touch(entity this, entity toucher)
Definition jumppads.qc:441
#define PUSH_VELOCITY_PLAYERDIR_Z
Definition jumppads.qh:10
const int PUSH_ONCE
Definition jumppads.qh:4
#define PUSH_VELOCITY_ADD_Z
Definition jumppads.qh:11
void SUB_UseTargets(entity this, entity actor, entity trigger)
Definition triggers.qc:353
#define PUSH_VELOCITY_PLAYERDIR_XY
Definition jumppads.qh:8
#define PUSH_VELOCITY_CLAMP_NEGATIVE_ADDS
Definition jumppads.qh:14
const int NUM_JUMPPADSUSED
Definition jumppads.qh:27
#define Q3_TARGET_PUSH_JUMPPAD
Definition jumppads.qh:16
IntrusiveList g_jumppads
Definition jumppads.qh:18
#define PUSH_VELOCITY_BIDIRECTIONAL_XY
Definition jumppads.qh:12
#define PUSH_VELOCITY_BIDIRECTIONAL_Z
Definition jumppads.qh:13
#define PUSH_VELOCITY_ADD_XY
Definition jumppads.qh:9
float pushltime
Definition jumppads.qh:21
const int PUSH_STATIC
Definition jumppads.qh:6
entity pusher
Definition laser.qc:57
int SendFlags
Definition net.qh:159
#define NET_HANDLE(id, param)
Definition net.qh:15
const int MSG_ENTITY
Definition net.qh:156
#define ReadVector()
Definition net.qh:349
int ReadInt24_t()
Definition net.qh:337
#define ReadAngleVector()
Definition net.qh:351
#define WriteHeader(to, id)
Definition net.qh:265
#define REGISTER_NET_LINKED(id)
Definition net.qh:91
void Net_LinkEntity(entity e, bool docull, float dt, bool(entity this, entity to, int sendflags) sendfunc)
Definition net.qh:167
int ReadByte()
#define STAT(...)
Definition stats.qh:94
#define EXACTTRIGGER_TOUCH(e, t)
Definition common.qh:133
#define BITSET_ASSIGN(a, b)
Definition common.qh:122
vector movedir
Definition viewloc.qh:18
ERASEABLE vector solve_quadratic(float a, float b, float c)
ax^2 + bx + c = 0
Definition math.qh:312
bool signbit(float e)
Definition mathlib.qc:40
float copysign(float e, float f)
Definition mathlib.qc:220
entity find(entity start,.string field, string match)
float vlen(vector v)
vector vectoangles(vector v)
float sqrt(float f)
string precache_sound(string sample)
void WriteCoord(float data, float dest, float desto)
void centerprint(string text,...)
float min(float f,...)
vector normalize(vector v)
float fabs(float f)
string strzone(string s)
#define ftoe(i)
Definition misc.qh:26
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
const int MOVETYPE_NONE
Definition movetypes.qh:133
#define PHYS_GRAVITY(s)
Definition movetypes.qh:54
const int MOVETYPE_BOUNCEMISSILE
Definition movetypes.qh:144
float move_time
Definition movetypes.qh:81
#define UNSET_ONGROUND(s)
Definition movetypes.qh:18
const int MOVETYPE_FLY
Definition movetypes.qh:138
const int MOVETYPE_TOSS
Definition movetypes.qh:139
const int MOVETYPE_BOUNCE
Definition movetypes.qh:143
vector stepheightvec
Definition navigation.qh:11
var void func_null()
#define NULL
Definition post.qh:14
#define objerror
Definition pre.qh:8
ERASEABLE void RandomSelection_Init()
Definition random.qc:4
#define RandomSelection_AddEnt(e, weight, priority)
Definition random.qh:14
entity RandomSelection_chosen_ent
Definition random.qh:5
#define setthink(e, f)
vector
Definition self.qh:96
vector org
Definition self.qh:96
entity entity toucher
Definition self.qh:76
#define settouch(e, f)
Definition self.qh:77
const int CH_TRIGGER
Definition sound.qh:12
const float VOL_BASE
Definition sound.qh:36
#define _sound(e, c, s, v, a)
Definition sound.qh:43
const float ATTEN_NORM
Definition sound.qh:30
#define spawnfunc(id)
Definition spawnfunc.qh:107
#define strfree(this)
Definition string.qh:57
void SetMovedir(entity this)
Definition subs.qc:539
string noise
Definition subs.qh:83
vector mangle
Definition subs.qh:51
entity enemy
Definition sv_ctf.qh:152
vector trigger_push_calculatevelocity(vector org, entity tgt, float ht, entity pushed_entity)
Definition jumppads.qc:32
bool teamplay
Definition teams.qh:59
#define DIFF_TEAM(a, b)
Definition teams.qh:242
void trigger_link(entity this, bool(entity this, entity to, int sendflags) sendfunc)
Definition triggers.qc:102
bool isPushable(entity e)
Definition triggers.qc:3
void trigger_common_write(entity this, bool withtarget)
Definition triggers.qc:108
void trigger_remove_generic(entity this)
string targetname
Definition triggers.qh:56
void trigger_common_read(entity this, bool withtarget)
string target
Definition triggers.qh:55
void WarpZoneLib_ExactTrigger_Init(entity this, bool unsetmodel)
Definition util_server.qc:8
#define IS_REAL_CLIENT(v)
Definition utils.qh:17
#define IS_BOT_CLIENT(v)
want: (IS_CLIENT(v) && !IS_REAL_CLIENT(v))
Definition utils.qh:15
#define vlen2(v)
Definition vector.qh:4
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt().
Definition vector.qh:8
const vector eZ
Definition vector.qh:45
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:72
#define vec2(...)
Definition vector.qh:95
void InitializeEntity(entity e, void(entity this) func, int order)
Definition world.qc:2201
IntrusiveList g_moveables
Definition world.qh:156