8 #define ACTIVE_ACTIVE 1
11 #define ACTIVE_TOGGLE 3
16 const float PUSH_ONCE = 1;
17 const float PUSH_SILENT = 2;
22 void() SUB_UseTargets;
24 void trigger_push_use()
28 self.team = activator.team;
34 float trigger_push_calculatevelocity_flighttime;
37 trigger_push_calculatevelocity
40 org - origin of the object which is to be pushed
41 tgt - target entity (can be either a point or a model entity; if it is
42 the latter, its midpoint is used)
43 ht - jump height, measured from the higher one of org and tgt's midpoint
45 Returns: velocity for the jump
46 the global trigger_push_calculatevelocity_flighttime is set to the total
50 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht)
52 float grav, sdist, zdist, vs, vz, jumpheight;
55 torg = tgt.origin + (tgt.mins + tgt.maxs) * 0.5;
58 if(PHYS_ENTGRAVITY(other))
59 grav *= PHYS_ENTGRAVITY(other);
61 zdist = torg_z - org_z;
62 sdist = vlen(torg - org - zdist * '0 0 1');
63 sdir = normalize(torg - org - zdist * '0 0 1');
65 // how high do we need to push the player?
66 jumpheight = fabs(ht);
68 jumpheight = jumpheight + zdist;
73 You will not understand the following equations anyway...
74 But here is what I did to get them.
79 z(t) = t * vz - 1/2 grav t^2
85 max(z, ti) = jumpheight
87 From these three equations, you will find the three parameters vs, vz
91 // push him so high...
92 vz = sqrt(fabs(2 * grav * jumpheight)); // NOTE: sqrt(positive)!
94 // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump!
100 solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
101 // ALWAYS solvable because jumpheight >= zdist
103 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)
105 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)
112 // almost straight line type
113 // jump apex is before the jump
114 // we must take the larger one
115 trigger_push_calculatevelocity_flighttime = solution_y;
120 // jump apex is during the jump
121 // we must take the larger one too
122 trigger_push_calculatevelocity_flighttime = solution_y;
130 // almost straight line type
131 // jump apex is after the jump
132 // we must take the smaller one
133 trigger_push_calculatevelocity_flighttime = solution_x;
138 // jump apex is during the jump
139 // we must take the larger one
140 trigger_push_calculatevelocity_flighttime = solution_y;
143 vs = sdist / trigger_push_calculatevelocity_flighttime;
145 // finally calculate the velocity
146 return sdir * vs + '0 0 1' * vz;
149 void trigger_push_touch()
151 if (self.active == ACTIVE_NOT)
155 if (!isPushable(other))
160 if(((self.spawnflags & 4) == 0) == (DIFF_TEAM(self, other)))
167 other.velocity = trigger_push_calculatevelocity(other.origin, self.enemy, self.height);
172 RandomSelection_Init();
173 for(e = world; (e = find(e, targetname, self.target)); )
176 RandomSelection_Add(e, 0, string_null, e.cnt, 1);
178 RandomSelection_Add(e, 0, string_null, 1, 1);
180 other.velocity = trigger_push_calculatevelocity(other.origin, RandomSelection_chosen_ent, self.height);
184 other.velocity = self.movedir;
187 UNSET_ONGROUND(other);
190 if (IS_PLAYER(other))
192 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
193 other.oldvelocity = other.velocity;
195 if(self.pushltime < time) // prevent "snorring" sound when a player hits the jumppad more than once
197 // flash when activated
198 pointparticles(particleeffectnum("jumppad_activate"), other.origin, other.velocity, 1);
199 sound (other, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NORM);
200 self.pushltime = time + 0.2;
203 if(IS_REAL_CLIENT(other) || IS_BOT_CLIENT(other))
208 for(i = 0; i < other.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
209 if(other.(jumppadsused[i]) == self)
213 other.(jumppadsused[other.jumppadcount % NUM_JUMPPADSUSED]) = self;
214 other.jumppadcount = other.jumppadcount + 1;
217 if(IS_REAL_CLIENT(other))
220 centerprint(other, self.message);
223 other.lastteleporttime = time;
225 if (other.deadflag == DEAD_NO)
226 animdecide_setaction(other, ANIMACTION_JUMP, TRUE);
229 other.jumppadcount = TRUE;
231 // reset tracking of who pushed you into a hazard (for kill credit)
233 other.istypefrag = 0;
236 if(self.enemy.target)
246 if (other.flags & FL_PROJECTILE)
248 other.angles = vectoangles (other.velocity);
249 switch(other.movetype)
252 other.movetype = MOVETYPE_TOSS;
255 case MOVETYPE_BOUNCEMISSILE:
256 other.movetype = MOVETYPE_BOUNCE;
260 UpdateCSQCProjectile(other);
263 if (self.spawnflags & PUSH_ONCE)
265 self.touch = func_null;
266 self.think = SUB_Remove;
267 self.nextthink = time;
274 void trigger_push_link();
275 void trigger_push_updatelink();
277 void trigger_push_findtarget()
282 // first calculate a typical start point for the jump
283 org = (self.absmin + self.absmax) * 0.5;
284 org_z = self.absmax_z - PL_MIN_z;
289 for(t = world; (t = find(t, targetname, self.target)); )
295 setsize(e, PL_MIN, PL_MAX);
296 e.velocity = trigger_push_calculatevelocity(org, t, self.height);
298 if(e.movetype == MOVETYPE_NONE)
299 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
308 objerror ("Jumppad with nonexistant target");
314 // exactly one dest - bots love that
315 self.enemy = find(world, targetname, self.target);
319 // have to use random selection every single time
328 setsize(e, PL_MIN, PL_MAX);
329 e.velocity = self.movedir;
331 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
336 defer(0.1, trigger_push_updatelink);
341 float trigger_push_send(entity to, float sf)
343 WriteByte(MSG_ENTITY, ENT_CLIENT_TRIGGER_PUSH);
344 WriteByte(MSG_ENTITY, sf);
348 WriteString(MSG_ENTITY, self.target);
349 WriteByte(MSG_ENTITY, self.team);
350 WriteInt24_t(MSG_ENTITY, self.spawnflags);
351 WriteByte(MSG_ENTITY, self.active);
352 WriteByte(MSG_ENTITY, self.warpzone_isboxy);
353 WriteByte(MSG_ENTITY, self.height);
354 WriteByte(MSG_ENTITY, self.scale);
355 WriteCoord(MSG_ENTITY, self.origin_x);
356 WriteCoord(MSG_ENTITY, self.origin_y);
357 WriteCoord(MSG_ENTITY, self.origin_z);
359 WriteCoord(MSG_ENTITY, self.mins_x);
360 WriteCoord(MSG_ENTITY, self.mins_y);
361 WriteCoord(MSG_ENTITY, self.mins_z);
362 WriteCoord(MSG_ENTITY, self.maxs_x);
363 WriteCoord(MSG_ENTITY, self.maxs_y);
364 WriteCoord(MSG_ENTITY, self.maxs_z);
366 WriteCoord(MSG_ENTITY, self.movedir_x);
367 WriteCoord(MSG_ENTITY, self.movedir_y);
368 WriteCoord(MSG_ENTITY, self.movedir_z);
370 WriteCoord(MSG_ENTITY, self.angles_x);
371 WriteCoord(MSG_ENTITY, self.angles_y);
372 WriteCoord(MSG_ENTITY, self.angles_z);
377 WriteByte(MSG_ENTITY, self.team);
378 WriteByte(MSG_ENTITY, self.active);
384 void trigger_push_updatelink()
389 void trigger_push_link()
391 Net_LinkEntity(self, FALSE, 0, trigger_push_send);
398 * target: target of jump
399 * height: the absolute value is the height of the highest point of the jump
400 * trajectory above the higher one of the player and the target.
401 * the sign indicates whether the highest point is INSIDE (positive)
402 * or OUTSIDE (negative) of the jump trajectory. General rule: use
403 * positive values for targets mounted on the floor, and use negative
404 * values to target a point on the ceiling.
405 * movedir: if target is not set, this * speed * 10 is the velocity to be reached.
407 void spawnfunc_trigger_push()
413 self.active = ACTIVE_ACTIVE;
414 self.use = trigger_push_use;
415 self.touch = trigger_push_touch;
420 self.movedir = self.movedir * self.speed * 10;
423 self.noise = "misc/jumppad.wav";
424 precache_sound (self.noise);
426 // this must be called to spawn the teleport waypoints for bots
427 InitializeEntity(self, trigger_push_findtarget, INITPRIO_FINDTARGET);
431 float target_push_send(entity to, float sf)
433 WriteByte(MSG_ENTITY, ENT_CLIENT_TARGET_PUSH);
435 WriteByte(MSG_ENTITY, self.cnt);
436 WriteString(MSG_ENTITY, self.targetname);
437 WriteCoord(MSG_ENTITY, self.origin_x);
438 WriteCoord(MSG_ENTITY, self.origin_y);
439 WriteCoord(MSG_ENTITY, self.origin_z);
444 void target_push_link()
446 Net_LinkEntity(self, FALSE, 0, target_push_send);
447 self.SendFlags |= 1; // update
450 void spawnfunc_target_push() { target_push_link(); }
451 void spawnfunc_info_notnull() { target_push_link(); }
452 void spawnfunc_target_position() { target_push_link(); }
457 void trigger_push_draw()
459 float dt = time - self.move_time;
460 self.move_time = time;
461 if(dt <= 0) { return; }
463 trigger_touch_generic(trigger_push_touch);
466 void ent_trigger_push()
468 float sf = ReadByte();
472 self.classname = "jumppad";
473 self.target = strzone(ReadString());
474 float mytm = ReadByte(); if(mytm) { self.team = mytm - 1; }
475 self.spawnflags = ReadInt24_t();
476 self.active = ReadByte();
477 self.warpzone_isboxy = ReadByte();
478 self.height = ReadByte();
479 self.scale = ReadByte();
480 self.origin_x = ReadCoord();
481 self.origin_y = ReadCoord();
482 self.origin_z = ReadCoord();
483 setorigin(self, self.origin);
484 self.mins_x = ReadCoord();
485 self.mins_y = ReadCoord();
486 self.mins_z = ReadCoord();
487 self.maxs_x = ReadCoord();
488 self.maxs_y = ReadCoord();
489 self.maxs_z = ReadCoord();
490 setsize(self, self.mins, self.maxs);
491 self.movedir_x = ReadCoord();
492 self.movedir_y = ReadCoord();
493 self.movedir_z = ReadCoord();
494 self.angles_x = ReadCoord();
495 self.angles_y = ReadCoord();
496 self.angles_z = ReadCoord();
498 self.solid = SOLID_TRIGGER;
499 //self.draw = trigger_push_draw;
500 self.drawmask = MASK_ENGINE;
501 self.move_time = time;
502 //self.touch = trigger_push_touch;
503 trigger_push_findtarget();
508 self.team = ReadByte();
509 self.active = ReadByte();
513 void ent_target_push()
515 self.classname = "push_target";
516 self.cnt = ReadByte();
517 self.targetname = strzone(ReadString());
518 self.origin_x = ReadCoord();
519 self.origin_y = ReadCoord();
520 self.origin_z = ReadCoord();
521 setorigin(self, self.origin);
523 self.drawmask = MASK_ENGINE;