]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/trigger/jumppads.qc
Merge remote-tracking branch 'origin/master' 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         // 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 bool jumppad_push(entity this, entity targ, bool is_velocity_pad)
246 {
247         if (!isPushable(targ))
248                 return false;
249
250         vector org = targ.origin;
251
252         if(STAT(Q3COMPAT, targ) || this.spawnflags & PUSH_STATIC)
253         {
254                 org = (this.absmin + this.absmax) * 0.5;
255         }
256
257         bool already_pushed = false;
258         if(is_velocity_pad) // remember velocity jump pads
259         {
260                 if(this == targ.last_pushed || (targ.last_pushed && !STAT(Q3COMPAT, targ))) // if q3compat is active overwrite last stored jump pad, otherwise ignore
261                 {
262                         already_pushed = true;
263                 }
264                 else
265                 {
266                         targ.last_pushed = this; // may be briefly out of sync between client and server if client prediction is toggled
267                 }
268         }
269
270         if(this.enemy)
271         {
272                 if(!is_velocity_pad)
273                 {
274                         targ.velocity = trigger_push_calculatevelocity(org, this.enemy, this.height, targ);
275                 }
276                 else
277                 {
278                         targ.velocity = trigger_push_velocity_calculatevelocity(this, org, this.enemy, this.speed, this.count, targ, already_pushed);
279                 }
280         }
281         else if(this.target && this.target != "")
282         {
283                 entity e;
284                 RandomSelection_Init();
285                 for(e = NULL; (e = find(e, targetname, this.target)); )
286                 {
287                         if(e.cnt)
288                                 RandomSelection_AddEnt(e, e.cnt, 1);
289                         else
290                                 RandomSelection_AddEnt(e, 1, 1);
291                 }
292                 if(!is_velocity_pad)
293                 {
294                         targ.velocity = trigger_push_calculatevelocity(org, RandomSelection_chosen_ent, this.height, targ);
295                 }
296                 else
297                 {
298                         targ.velocity = trigger_push_velocity_calculatevelocity(this, org, RandomSelection_chosen_ent, this.speed, this.count, targ, already_pushed);
299                 }
300         }
301         else
302         {
303                 if(!is_velocity_pad)
304                 {
305                         targ.velocity = this.movedir;
306                 }
307                 else
308                 {
309 #ifdef SVQC
310                         objerror (this, "Jumppad with no target");
311 #endif
312                         return false;
313                 }
314         }
315
316         if(!is_velocity_pad) UNSET_ONGROUND(targ);
317
318 #ifdef CSQC
319         if (targ.flags & FL_PROJECTILE)
320         {
321                 targ.angles = vectoangles (targ.velocity);
322                 switch(targ.move_movetype)
323                 {
324                         case MOVETYPE_FLY:
325                                 set_movetype(targ, MOVETYPE_TOSS);
326                                 targ.gravity = 1;
327                                 break;
328                         case MOVETYPE_BOUNCEMISSILE:
329                                 set_movetype(targ, MOVETYPE_BOUNCE);
330                                 targ.gravity = 1;
331                                 break;
332                 }
333         }
334 #endif
335
336 #ifdef SVQC
337         if (IS_PLAYER(targ))
338         {
339                 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
340                 targ.oldvelocity = targ.velocity;
341
342                 // prevent sound spam when a player hits the jumppad more than once
343                 // or when a dead player gets stuck in the jumppad for some reason
344                 if(!already_pushed && this.pushltime < time && !(IS_DEAD(targ) && targ.velocity == '0 0 0'))
345                 {
346                         // flash when activated
347                         Send_Effect(EFFECT_JUMPPAD, targ.origin, targ.velocity, 1);
348                         _sound (targ, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
349                         this.pushltime = time + 0.2;
350                 }
351                 if(IS_REAL_CLIENT(targ) || IS_BOT_CLIENT(targ))
352                 {
353                         bool found = false;
354                         for(int i = 0; i < targ.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
355                                 if(targ.(jumppadsused[i]) == this)
356                                         found = true;
357                         if(!found)
358                         {
359                                 targ.(jumppadsused[targ.jumppadcount % NUM_JUMPPADSUSED]) = this;
360                                 targ.jumppadcount = targ.jumppadcount + 1;
361                         }
362
363                         if(IS_REAL_CLIENT(targ))
364                         {
365                                 if(this.message)
366                                         centerprint(targ, this.message);
367                         }
368                         else
369                         {
370                                 targ.lastteleporttime = time;
371                                 targ.lastteleport_origin = targ.origin;
372                         }
373
374                         if (!IS_DEAD(targ))
375                                 animdecide_setaction(targ, ANIMACTION_JUMP, true);
376                 }
377                 else
378                         targ.jumppadcount = 1;
379
380                 // reset tracking of who pushed you into a hazard (for kill credit)
381                 targ.pushltime = 0;
382                 targ.istypefrag = 0;
383         }
384
385         if(this.enemy.target)
386                 SUB_UseTargets(this.enemy, targ, this);
387
388         if (targ.flags & FL_PROJECTILE)
389         {
390                 targ.angles = vectoangles (targ.velocity);
391                 targ.com_phys_gravity_factor = 1;
392                 switch(targ.move_movetype)
393                 {
394                         case MOVETYPE_FLY:
395                                 set_movetype(targ, MOVETYPE_TOSS);
396                                 targ.gravity = 1;
397                                 break;
398                         case MOVETYPE_BOUNCEMISSILE:
399                                 set_movetype(targ, MOVETYPE_BOUNCE);
400                                 targ.gravity = 1;
401                                 break;
402                 }
403                 UpdateCSQCProjectile(targ);
404         }
405 #endif
406
407         return true;
408 }
409
410 void trigger_push_touch(entity this, entity toucher)
411 {
412         if (this.active == ACTIVE_NOT)
413                 return;
414
415         if(this.team)
416                 if(((this.spawnflags & INVERT_TEAMS) == 0) == (DIFF_TEAM(this, toucher)))
417                         return;
418
419         EXACTTRIGGER_TOUCH(this, toucher);
420
421         noref bool success = jumppad_push(this, toucher, false);
422
423 #ifdef SVQC
424         if (success && (this.spawnflags & PUSH_ONCE))
425         {
426                 settouch(this, func_null);
427                 setthink(this, SUB_Remove);
428                 this.nextthink = time;
429         }
430 #endif
431 }
432
433 void trigger_push_velocity_touch(entity this, entity toucher)
434 {
435         if (this.active == ACTIVE_NOT)
436                 return;
437
438         if(this.team && DIFF_TEAM(this, toucher))
439                 return;
440
441         EXACTTRIGGER_TOUCH(this, toucher);
442
443         jumppad_push(this, toucher, true);
444 }
445
446 #ifdef SVQC
447 void trigger_push_link(entity this);
448 void trigger_push_updatelink(entity this);
449 bool trigger_push_testorigin(entity tracetest_ent, entity targ, entity jp, vector org)
450 {
451         setorigin(tracetest_ent, org);
452         tracetoss(tracetest_ent, tracetest_ent);
453         if(trace_startsolid)
454                 return false;
455
456         if (!jp.height)
457         {
458                 // since tracetoss starting from jumppad's origin often fails when target
459                 // is very close to real destination, start it directly from target's
460                 // origin instead
461                 vector ofs = '0 0 0';
462                 if (vdist(vec2(tracetest_ent.velocity), <, autocvar_sv_maxspeed))
463                         ofs = stepheightvec;
464
465                 tracetest_ent.velocity.z = 0;
466                 setorigin(tracetest_ent, targ.origin + ofs);
467                 tracetoss(tracetest_ent, tracetest_ent);
468                 if (trace_startsolid && ofs.z)
469                 {
470                         setorigin(tracetest_ent, targ.origin + ofs / 2);
471                         tracetoss(tracetest_ent, tracetest_ent);
472                         if (trace_startsolid && ofs.z)
473                         {
474                                 setorigin(tracetest_ent, targ.origin);
475                                 tracetoss(tracetest_ent, tracetest_ent);
476                                 if (trace_startsolid)
477                                         return false;
478                         }
479                 }
480         }
481         tracebox(trace_endpos, tracetest_ent.mins, tracetest_ent.maxs, trace_endpos - eZ * 1500, true, tracetest_ent);
482         return true;
483 }
484
485 bool trigger_push_testorigin_for_item(entity tracetest_ent, entity item, vector org)
486 {
487         setorigin(tracetest_ent, org);
488         tracetoss(tracetest_ent, tracetest_ent);
489
490         if(trace_startsolid)
491                 return false;
492         if (trace_ent == item)
493                 return true;
494
495         tracebox(trace_endpos, tracetest_ent.mins, tracetest_ent.maxs, trace_endpos - eZ * 1500, true, tracetest_ent);
496
497         if (trace_ent == item)
498                 return true;
499
500         return false;
501 }
502 #endif
503
504 #ifdef SVQC
505 vector trigger_push_get_start_point(entity this)
506 {
507         // calculate a typical start point for the jump
508         vector org = (this.absmin + this.absmax) * 0.5;
509         org.z = this.absmax.z - PL_MIN_CONST.z - 7;
510         return org;
511 }
512
513 float trigger_push_get_push_time(entity this, vector endpos)
514 {
515         vector org = trigger_push_get_start_point(this);
516
517         float grav = PHYS_GRAVITY(NULL);
518
519         entity t = this.enemy;
520         if (t)
521         {
522                 entity e = spawn();
523                 setsize(e, PL_MIN_CONST, PL_MAX_CONST);
524                 e.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
525                 vector v = trigger_push_calculatevelocity(org, t, this.height, e);
526                 vector v2 = trigger_push_calculatevelocity(endpos, t, this.height, e);
527                 delete(e);
528                 return (v.z + v2.z) / grav;
529         }
530         else if (!(this.target && this.target != ""))
531         {
532                 if (!this.team)
533                 {
534                         vector v = this.movedir;
535
536                         float t = v.z / grav;
537                         float jump_height = 1/2 * grav * (t ** 2);
538                         float remaining_height = org.z + jump_height - endpos.z;
539                         float v2_z = sqrt(2 * grav * remaining_height);
540
541                         return (v.z + v2_z) / grav;
542                 }
543         }
544         return 0;
545 }
546 #endif
547
548 /// if (item != NULL) returns true if the item can be reached by using this jumppad, false otherwise
549 /// if (item == NULL) tests jumppad's trajectory and eventually spawns waypoints for it (return value doesn't matter)
550 bool trigger_push_test(entity this, entity item)
551 {
552 #ifdef SVQC
553         vector org = trigger_push_get_start_point(this);
554 #endif
555
556         if (this.target)
557         {
558                 int n = 0;
559 #ifdef SVQC
560                 vector vel = '0 0 0';
561 #endif
562                 for(entity t = NULL; (t = find(t, targetname, this.target)); )
563                 {
564                         ++n;
565 #ifdef SVQC
566                         if(t.move_movetype != MOVETYPE_NONE)
567                                 continue;
568
569                         // bots can't tell teamed jumppads from normal ones
570                         if (this.team)
571                                 continue;
572
573                         entity e = spawn();
574                         setsize(e, PL_MIN_CONST, PL_MAX_CONST);
575                         e.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
576                         e.velocity = trigger_push_calculatevelocity(org, t, this.height, e);
577
578                         vel = e.velocity;
579                         vector best_target = '0 0 0';
580                         vector best_org = '0 0 0';
581                         vector best_vel = '0 0 0';
582                         bool valid_best_target = false;
583                         if (item)
584                         {
585                                 if (!trigger_push_testorigin_for_item(e, item, org))
586                                 {
587                                         delete(e);
588                                         return false;
589                                 }
590                         }
591                         else
592                         {
593                                 if (trigger_push_testorigin(e, t, this, org))
594                                 {
595                                         best_target = trace_endpos;
596                                         best_org = org;
597                                         best_vel = e.velocity;
598                                         valid_best_target = true;
599                                 }
600                         }
601
602                         vector new_org;
603                         vector dist = t.origin - org;
604                         if (dist.x || dist.y) // if not perfectly vertical
605                         {
606                                 // test trajectory with different starting points, sometimes the trajectory
607                                 // starting from the jumppad origin can't reach the real destination
608                                 // and destination waypoint ends up near the jumppad itself
609                                 vector flatdir = normalize(dist - eZ * dist.z);
610                                 vector ofs = flatdir * 0.5 * min(fabs(this.absmax.x - this.absmin.x), fabs(this.absmax.y - this.absmin.y));
611                                 new_org = org + ofs;
612
613                                 LABEL(new_test)
614                                 e.velocity = trigger_push_calculatevelocity(new_org, t, this.height, e);
615                                 if (item)
616                                 {
617                                         if (!trigger_push_testorigin_for_item(e, item, new_org))
618                                         {
619                                                 delete(e);
620                                                 return false;
621                                         }
622                                 }
623                                 else
624                                 {
625                                         vel = e.velocity;
626                                         if (vdist(vec2(e.velocity), <, autocvar_sv_maxspeed))
627                                                 e.velocity = autocvar_sv_maxspeed * flatdir;
628                                         if (trigger_push_testorigin(e, t, this, new_org) && (!valid_best_target || trace_endpos.z > best_target.z + 50))
629                                         {
630                                                 best_target = trace_endpos;
631                                                 best_org = new_org;
632                                                 best_vel = vel;
633                                                 valid_best_target = true;
634                                         }
635                                 }
636                                 if (ofs && new_org != org - ofs)
637                                 {
638                                         new_org = org - ofs;
639                                         goto new_test;
640                                 }
641                         }
642
643                         if (item)
644                         {
645                                 delete(e);
646                                 return true;
647                         }
648
649                         if (valid_best_target)
650                         {
651                                 if (!(boxesoverlap(this.absmin, this.absmax + eZ * 50, best_target + PL_MIN_CONST, best_target + PL_MAX_CONST)))
652                                 {
653                                         float velxy = vlen(vec2(best_vel));
654                                         float cost = vlen(vec2(t.origin - best_org)) / velxy;
655                                         if(velxy < autocvar_sv_maxspeed)
656                                                 velxy = autocvar_sv_maxspeed;
657                                         cost += vlen(vec2(best_target - t.origin)) / velxy;
658                                         waypoint_spawnforteleporter(this, best_target, cost, e);
659                                 }
660                         }
661                         delete(e);
662 #endif
663                 }
664
665                 if(item)
666                         return false;
667
668                 if(!n)
669                 {
670                         // no dest!
671 #ifdef SVQC
672                         objerror (this, "Jumppad with nonexistant target");
673 #endif
674                         return false;
675                 }
676                 else if(n == 1)
677                 {
678                         // exactly one dest - bots love that
679                         if (!this.team)
680                                 this.enemy = find(NULL, targetname, this.target);
681                         else // bots can't tell teamed jumppads from normal ones
682                                 this.enemy = NULL;
683                 }
684                 else
685                 {
686                         // have to use random selection every single time
687                         this.enemy = NULL;
688                 }
689
690         }
691 #ifdef SVQC
692         else
693         {
694                 if (!this.team)
695                 {
696                         entity e = spawn();
697                         setsize(e, PL_MIN_CONST, PL_MAX_CONST);
698                         e.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
699                         setorigin(e, org);
700                         e.velocity = this.movedir;
701                         tracetoss(e, e);
702                         if (item)
703                         {
704                                 bool r = (trace_ent == item);
705                                 delete(e);
706                                 return r;
707                         }
708                         if (!(boxesoverlap(this.absmin, this.absmax + eZ * 50, trace_endpos + PL_MIN_CONST, trace_endpos + PL_MAX_CONST)))
709                                 waypoint_spawnforteleporter(this, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity), e);
710                         delete(e);
711                 }
712                 else if (item)
713                         return false;
714         }
715
716         defer(this, 0.1, trigger_push_updatelink);
717 #endif
718         return true;
719 }
720
721 void trigger_push_findtarget(entity this)
722 {
723         trigger_push_test(this, NULL);
724 }
725
726 #ifdef SVQC
727 float trigger_push_send(entity this, entity to, float sf)
728 {
729         WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_PUSH);
730
731         WriteByte(MSG_ENTITY, this.team);
732         WriteInt24_t(MSG_ENTITY, this.spawnflags);
733         WriteByte(MSG_ENTITY, this.active);
734         WriteCoord(MSG_ENTITY, this.height);
735
736         trigger_common_write(this, true);
737
738         return true;
739 }
740
741 float trigger_push_velocity_send(entity this, entity to, float sf)
742 {
743         WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_PUSH_VELOCITY);
744
745         WriteByte(MSG_ENTITY, this.team);
746         WriteInt24_t(MSG_ENTITY, this.spawnflags);
747         WriteByte(MSG_ENTITY, this.active);
748         WriteCoord(MSG_ENTITY, this.speed);
749         WriteCoord(MSG_ENTITY, this.count);
750
751         trigger_common_write(this, true);
752
753         return true;
754 }
755
756 void trigger_push_updatelink(entity this)
757 {
758         this.SendFlags |= SF_TRIGGER_INIT;
759 }
760
761 void trigger_push_link(entity this)
762 {
763         trigger_link(this, trigger_push_send);
764 }
765
766 void trigger_push_velocity_link(entity this)
767 {
768         trigger_link(this, trigger_push_velocity_send);
769 }
770
771 /*
772  * ENTITY PARAMETERS:
773  *
774  *   target:  target of jump
775  *   height:  the absolute value is the height of the highest point of the jump
776  *            trajectory above the higher one of the player and the target.
777  *            the sign indicates whether the highest point is INSIDE (positive)
778  *            or OUTSIDE (negative) of the jump trajectory. General rule: use
779  *            positive values for targets mounted on the floor, and use negative
780  *            values to target a point on the ceiling.
781  *   movedir: if target is not set, this * speed * 10 is the velocity to be reached.
782  */
783 spawnfunc(trigger_push)
784 {
785         SetMovedir(this);
786
787         EXACTTRIGGER_INIT;
788         BITSET_ASSIGN(this.effects, EF_NODEPTHTEST);
789         this.active = ACTIVE_ACTIVE;
790         this.use = trigger_push_use;
791         settouch(this, trigger_push_touch);
792
793         // normal push setup
794         if (!this.speed)
795                 this.speed = 1000;
796         this.movedir = this.movedir * this.speed * 10;
797
798         if (!this.noise)
799                 this.noise = "misc/jumppad.wav";
800         precache_sound (this.noise);
801
802         trigger_push_link(this); // link it now
803
804         IL_PUSH(g_jumppads, this);
805
806         // this must be called to spawn the teleport waypoints for bots
807         InitializeEntity(this, trigger_push_findtarget, INITPRIO_FINDTARGET);
808 }
809
810 /*
811  * ENTITY PARAMETERS:
812  *
813  *   target:  this points to the target_position to which the player will jump.
814  *   speed:   XY speed for player-directional velocity pads - either sets or adds to the player's horizontal velocity.
815  *   count:   Z speed for player-directional velocity pads - either sets or adds to the player's vertical velocity.
816  */
817 spawnfunc(trigger_push_velocity)
818 {
819         trigger_init(this);
820
821         this.active = ACTIVE_ACTIVE;
822         this.use = trigger_push_use;
823         settouch(this, trigger_push_velocity_touch);
824
825         // normal push setup
826         if (!this.noise)
827                 this.noise = "misc/jumppad.wav";
828         precache_sound (this.noise);
829
830         trigger_push_velocity_link(this); // link it now
831 }
832
833
834 bool target_push_send(entity this, entity to, float sf)
835 {
836         WriteHeader(MSG_ENTITY, ENT_CLIENT_TARGET_PUSH);
837
838         WriteByte(MSG_ENTITY, this.cnt);
839         WriteString(MSG_ENTITY, this.targetname);
840         WriteVector(MSG_ENTITY, this.origin);
841
842         WriteAngleVector(MSG_ENTITY, this.angles);
843
844         return true;
845 }
846
847 void target_push_use(entity this, entity actor, entity trigger)
848 {
849         if(trigger.classname == "trigger_push" || trigger == this)
850                 return; // WTF, why is this a thing
851
852         jumppad_push(this, actor, false);
853 }
854
855 void target_push_link(entity this)
856 {
857         BITSET_ASSIGN(this.effects, EF_NODEPTHTEST);
858         Net_LinkEntity(this, false, 0, target_push_send);
859         //this.SendFlags |= 1; // update
860 }
861
862 void target_push_init(entity this)
863 {
864         this.mangle = this.angles;
865         setorigin(this, this.origin);
866         target_push_link(this);
867 }
868
869 void target_push_init2(entity this)
870 {
871         if(this.target && this.target != "") // we have an old style pusher!
872         {
873                 InitializeEntity(this, trigger_push_findtarget, INITPRIO_FINDTARGET);
874                 this.use = target_push_use;
875         }
876
877         target_push_init(this); // normal push target behaviour can be combined with a legacy pusher?
878 }
879
880 spawnfunc(target_push)
881 {
882         target_push_init2(this);
883 }
884
885 spawnfunc(info_notnull)
886 {
887         target_push_init(this);
888 }
889 spawnfunc(target_position)
890 {
891         target_push_init(this);
892 }
893
894 #elif defined(CSQC)
895
896 NET_HANDLE(ENT_CLIENT_TRIGGER_PUSH, bool isnew)
897 {
898         int mytm = ReadByte(); if(mytm) { this.team = mytm - 1; }
899         this.spawnflags = ReadInt24_t();
900         this.active = ReadByte();
901         this.height = ReadCoord();
902
903         trigger_common_read(this, true);
904
905         this.entremove = trigger_remove_generic;
906         this.solid = SOLID_TRIGGER;
907         settouch(this, trigger_push_touch);
908         this.move_time = time;
909         defer(this, 0.25, trigger_push_findtarget);
910
911         return true;
912 }
913
914 NET_HANDLE(ENT_CLIENT_TRIGGER_PUSH_VELOCITY, bool isnew)
915 {
916         int mytm = ReadByte(); if(mytm) { this.team = mytm - 1; }
917         this.spawnflags = ReadInt24_t();
918         this.active = ReadByte();
919         this.speed = ReadCoord();
920         this.count = ReadCoord();
921
922         trigger_common_read(this, true);
923
924         this.entremove = trigger_remove_generic;
925         this.solid = SOLID_TRIGGER;
926         settouch(this, trigger_push_velocity_touch);
927         this.move_time = time;
928
929         return true;
930 }
931
932 void target_push_remove(entity this)
933 {
934         // strfree(this.classname);
935         strfree(this.targetname);
936 }
937
938 NET_HANDLE(ENT_CLIENT_TARGET_PUSH, bool isnew)
939 {
940         this.cnt = ReadByte();
941         this.targetname = strzone(ReadString());
942         this.origin = ReadVector();
943
944         this.angles = ReadAngleVector();
945
946         return = true;
947
948         setorigin(this, this.origin);
949
950         this.drawmask = MASK_NORMAL;
951         this.entremove = target_push_remove;
952 }
953 #endif