9 #define ACTIVE_ACTIVE 1
12 #define ACTIVE_TOGGLE 3
17 const float PUSH_ONCE = 1;
18 const float PUSH_SILENT = 2;
23 void() SUB_UseTargets;
25 void trigger_push_use()
29 self.team = activator.team;
35 float trigger_push_calculatevelocity_flighttime;
38 trigger_push_calculatevelocity
41 org - origin of the object which is to be pushed
42 tgt - target entity (can be either a point or a model entity; if it is
43 the latter, its midpoint is used)
44 ht - jump height, measured from the higher one of org and tgt's midpoint
46 Returns: velocity for the jump
47 the global trigger_push_calculatevelocity_flighttime is set to the total
51 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht)
53 float grav, sdist, zdist, vs, vz, jumpheight;
56 torg = tgt.origin + (tgt.mins + tgt.maxs) * 0.5;
59 if(PHYS_ENTGRAVITY(other))
60 grav *= PHYS_ENTGRAVITY(other);
62 zdist = torg_z - org_z;
63 sdist = vlen(torg - org - zdist * '0 0 1');
64 sdir = normalize(torg - org - zdist * '0 0 1');
66 // how high do we need to push the player?
67 jumpheight = fabs(ht);
69 jumpheight = jumpheight + zdist;
74 You will not understand the following equations anyway...
75 But here is what I did to get them.
80 z(t) = t * vz - 1/2 grav t^2
86 max(z, ti) = jumpheight
88 From these three equations, you will find the three parameters vs, vz
92 // push him so high...
93 vz = sqrt(fabs(2 * grav * jumpheight)); // NOTE: sqrt(positive)!
95 // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump!
101 solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
102 // ALWAYS solvable because jumpheight >= zdist
104 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)
106 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)
113 // almost straight line type
114 // jump apex is before the jump
115 // we must take the larger one
116 trigger_push_calculatevelocity_flighttime = solution_y;
121 // jump apex is during the jump
122 // we must take the larger one too
123 trigger_push_calculatevelocity_flighttime = solution_y;
131 // almost straight line type
132 // jump apex is after the jump
133 // we must take the smaller one
134 trigger_push_calculatevelocity_flighttime = solution_x;
139 // jump apex is during the jump
140 // we must take the larger one
141 trigger_push_calculatevelocity_flighttime = solution_y;
144 vs = sdist / trigger_push_calculatevelocity_flighttime;
146 // finally calculate the velocity
147 return sdir * vs + '0 0 1' * vz;
150 void PM_ClientMovement_Move();
151 void trigger_push_touch()
153 if (self.active == ACTIVE_NOT)
157 if (!isPushable(other))
162 if(((self.spawnflags & 4) == 0) == (DIFF_TEAM(self, other)))
169 other.velocity = trigger_push_calculatevelocity(other.origin, self.enemy, self.height);
174 RandomSelection_Init();
175 for(e = world; (e = find(e, targetname, self.target)); )
178 RandomSelection_Add(e, 0, string_null, e.cnt, 1);
180 RandomSelection_Add(e, 0, string_null, 1, 1);
182 other.velocity = trigger_push_calculatevelocity(other.origin, RandomSelection_chosen_ent, self.height);
186 other.velocity = self.movedir;
189 UNSET_ONGROUND(other);
192 if (IS_PLAYER(other))
194 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
195 other.oldvelocity = other.velocity;
197 if(self.pushltime < time) // prevent "snorring" sound when a player hits the jumppad more than once
199 // flash when activated
200 pointparticles(particleeffectnum("jumppad_activate"), other.origin, other.velocity, 1);
201 sound (other, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NORM);
202 self.pushltime = time + 0.2;
205 if(IS_REAL_CLIENT(other) || IS_BOT_CLIENT(other))
210 for(i = 0; i < other.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
211 if(other.(jumppadsused[i]) == self)
215 other.(jumppadsused[mod(other.jumppadcount, NUM_JUMPPADSUSED)]) = self;
216 other.jumppadcount = other.jumppadcount + 1;
219 if(IS_REAL_CLIENT(other))
222 centerprint(other, self.message);
225 other.lastteleporttime = time;
227 if (other.deadflag == DEAD_NO)
228 animdecide_setaction(other, ANIMACTION_JUMP, TRUE);
231 other.jumppadcount = TRUE;
233 // reset tracking of who pushed you into a hazard (for kill credit)
235 other.istypefrag = 0;
238 if(self.enemy.target)
248 if (other.flags & FL_PROJECTILE)
250 other.angles = vectoangles (other.velocity);
251 switch(other.movetype)
254 other.movetype = MOVETYPE_TOSS;
257 case MOVETYPE_BOUNCEMISSILE:
258 other.movetype = MOVETYPE_BOUNCE;
262 UpdateCSQCProjectile(other);
265 if (self.spawnflags & PUSH_ONCE)
267 self.touch = func_null;
268 self.think = SUB_Remove;
269 self.nextthink = time;
275 float trigger_push_send(entity to, float sf)
277 WriteByte(MSG_ENTITY, ENT_CLIENT_TRIGGER_PUSH);
278 WriteByte(MSG_ENTITY, sf);
282 WriteString(MSG_ENTITY, self.target);
283 WriteByte(MSG_ENTITY, self.team);
284 WriteByte(MSG_ENTITY, self.active);
285 WriteByte(MSG_ENTITY, self.warpzone_isboxy);
286 WriteByte(MSG_ENTITY, self.height);
287 WriteByte(MSG_ENTITY, self.scale);
288 WriteCoord(MSG_ENTITY, self.origin_x);
289 WriteCoord(MSG_ENTITY, self.origin_y);
290 WriteCoord(MSG_ENTITY, self.origin_z);
292 WriteCoord(MSG_ENTITY, self.mins_x);
293 WriteCoord(MSG_ENTITY, self.mins_y);
294 WriteCoord(MSG_ENTITY, self.mins_z);
295 WriteCoord(MSG_ENTITY, self.maxs_x);
296 WriteCoord(MSG_ENTITY, self.maxs_y);
297 WriteCoord(MSG_ENTITY, self.maxs_z);
299 WriteCoord(MSG_ENTITY, self.movedir_x);
300 WriteCoord(MSG_ENTITY, self.movedir_y);
301 WriteCoord(MSG_ENTITY, self.movedir_z);
303 WriteCoord(MSG_ENTITY, self.angles_x);
304 WriteCoord(MSG_ENTITY, self.angles_y);
305 WriteCoord(MSG_ENTITY, self.angles_z);
310 WriteByte(MSG_ENTITY, self.team);
311 WriteByte(MSG_ENTITY, self.active);
317 void trigger_push_updatelink()
322 void trigger_push_link()
324 Net_LinkEntity(self, FALSE, 0, trigger_push_send);
329 void trigger_push_findtarget()
334 // first calculate a typical start point for the jump
335 org = (self.absmin + self.absmax) * 0.5;
336 org_z = self.absmax_z - PL_MIN_z;
341 for(t = world; (t = find(t, targetname, self.target)); )
347 setsize(e, PL_MIN, PL_MAX);
348 e.velocity = trigger_push_calculatevelocity(org, t, self.height);
350 if(e.movetype == MOVETYPE_NONE)
351 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
360 objerror ("Jumppad with nonexistant target");
366 // exactly one dest - bots love that
367 self.enemy = find(world, targetname, self.target);
371 // have to use random selection every single time
380 setsize(e, PL_MIN, PL_MAX);
381 e.velocity = self.movedir;
383 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
388 defer(0.1, trigger_push_updatelink);
396 * target: target of jump
397 * height: the absolute value is the height of the highest point of the jump
398 * trajectory above the higher one of the player and the target.
399 * the sign indicates whether the highest point is INSIDE (positive)
400 * or OUTSIDE (negative) of the jump trajectory. General rule: use
401 * positive values for targets mounted on the floor, and use negative
402 * values to target a point on the ceiling.
403 * movedir: if target is not set, this * speed * 10 is the velocity to be reached.
405 void spawnfunc_trigger_push()
411 self.active = ACTIVE_ACTIVE;
412 self.use = trigger_push_use;
413 self.touch = trigger_push_touch;
418 self.movedir = self.movedir * self.speed * 10;
421 self.noise = "misc/jumppad.wav";
422 precache_sound (self.noise);
424 // this must be called to spawn the teleport waypoints for bots
425 InitializeEntity(self, trigger_push_findtarget, INITPRIO_FINDTARGET);
429 float target_push_send(entity to, float sf)
431 WriteByte(MSG_ENTITY, ENT_CLIENT_TARGET_PUSH);
433 WriteByte(MSG_ENTITY, self.cnt);
434 WriteString(MSG_ENTITY, self.targetname);
435 WriteCoord(MSG_ENTITY, self.origin_x);
436 WriteCoord(MSG_ENTITY, self.origin_y);
437 WriteCoord(MSG_ENTITY, self.origin_z);
442 void target_push_link()
444 Net_LinkEntity(self, FALSE, 0, target_push_send);
445 self.SendFlags |= 1; // update
448 void spawnfunc_target_push() { target_push_link(); }
449 void spawnfunc_info_notnull() { target_push_link(); }
450 void spawnfunc_target_position() { target_push_link(); }
455 void trigger_push_draw()
457 /*float dt = time - self.move_time;
458 self.move_time = time;
462 tracebox(self.origin, self.mins, self.maxs, self.origin, MOVE_NORMAL, self);
464 //if(trace_fraction < 1)
466 if(time >= trace_ent.jpad_time)
469 trigger_push_touch();
470 trace_ent.jpad_time = time + 0.2;
474 void ent_trigger_push()
476 float sf = ReadByte();
480 self.classname = "jumppad";
481 self.target = strzone(ReadString());
482 float mytm = ReadByte(); if(mytm) { self.team = mytm - 1; }
483 self.active = ReadByte();
484 self.warpzone_isboxy = ReadByte();
485 self.height = ReadByte();
486 self.scale = ReadByte();
487 self.origin_x = ReadCoord();
488 self.origin_y = ReadCoord();
489 self.origin_z = ReadCoord();
490 setorigin(self, self.origin);
491 self.mins_x = ReadCoord();
492 self.mins_y = ReadCoord();
493 self.mins_z = ReadCoord();
494 self.maxs_x = ReadCoord();
495 self.maxs_y = ReadCoord();
496 self.maxs_z = ReadCoord();
497 setsize(self, self.mins, self.maxs);
498 self.movedir_x = ReadCoord();
499 self.movedir_y = ReadCoord();
500 self.movedir_z = ReadCoord();
501 self.angles_x = ReadCoord();
502 self.angles_y = ReadCoord();
503 self.angles_z = ReadCoord();
505 self.solid = SOLID_TRIGGER;
506 //self.draw = trigger_push_draw;
507 self.drawmask = MASK_NORMAL;
508 self.move_time = time;
509 //self.touch = trigger_push_touch;
510 trigger_push_findtarget();
515 self.team = ReadByte();
516 self.active = ReadByte();
520 void ent_target_push()
522 self.classname = "push_target";
523 self.cnt = ReadByte();
524 self.targetname = strzone(ReadString());
525 self.origin_x = ReadCoord();
526 self.origin_y = ReadCoord();
527 self.origin_z = ReadCoord();
528 setorigin(self, self.origin);
530 self.drawmask = MASK_NORMAL;