1 #include "t_jumppads.qh"
3 void trigger_push_use()
6 self.team = activator.team;
10 trigger_push_calculatevelocity
13 org - origin of the object which is to be pushed
14 tgt - target entity (can be either a point or a model entity; if it is
15 the latter, its midpoint is used)
16 ht - jump height, measured from the higher one of org and tgt's midpoint
18 Returns: velocity for the jump
19 the global trigger_push_calculatevelocity_flighttime is set to the total
23 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht)
25 float grav, sdist, zdist, vs, vz, jumpheight;
28 torg = tgt.origin + (tgt.mins + tgt.maxs) * 0.5;
30 grav = autocvar_sv_gravity;
32 grav *= other.gravity;
34 zdist = torg.z - org.z;
35 sdist = vlen(torg - org - zdist * '0 0 1');
36 sdir = normalize(torg - org - zdist * '0 0 1');
38 // how high do we need to push the player?
39 jumpheight = fabs(ht);
41 jumpheight = jumpheight + zdist;
46 You will not understand the following equations anyway...
47 But here is what I did to get them.
52 z(t) = t * vz - 1/2 grav t^2
58 max(z, ti) = jumpheight
60 From these three equations, you will find the three parameters vs, vz
64 // push him so high...
65 vz = sqrt(fabs(2 * grav * jumpheight)); // NOTE: sqrt(positive)!
67 // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump!
73 solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
74 // ALWAYS solvable because jumpheight >= zdist
76 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)
78 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)
85 // almost straight line type
86 // jump apex is before the jump
87 // we must take the larger one
88 trigger_push_calculatevelocity_flighttime = solution.y;
93 // jump apex is during the jump
94 // we must take the larger one too
95 trigger_push_calculatevelocity_flighttime = solution.y;
103 // almost straight line type
104 // jump apex is after the jump
105 // we must take the smaller one
106 trigger_push_calculatevelocity_flighttime = solution.x;
111 // jump apex is during the jump
112 // we must take the larger one
113 trigger_push_calculatevelocity_flighttime = solution.y;
116 vs = sdist / trigger_push_calculatevelocity_flighttime;
118 // finally calculate the velocity
119 return sdir * vs + '0 0 1' * vz;
122 void trigger_push_touch()
124 if (self.active == ACTIVE_NOT)
127 if (!isPushable(other))
131 if(((self.spawnflags & 4) == 0) == (self.team != other.team))
138 other.velocity = trigger_push_calculatevelocity(other.origin, self.enemy, self.height);
143 RandomSelection_Init();
144 for(e = world; (e = find(e, targetname, self.target)); )
147 RandomSelection_Add(e, 0, string_null, e.cnt, 1);
149 RandomSelection_Add(e, 0, string_null, 1, 1);
151 other.velocity = trigger_push_calculatevelocity(other.origin, RandomSelection_chosen_ent, self.height);
155 other.velocity = self.movedir;
158 other.flags &= ~FL_ONGROUND;
160 if (IS_PLAYER(other))
162 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
163 other.oldvelocity = other.velocity;
165 if(self.pushltime < time) // prevent "snorring" sound when a player hits the jumppad more than once
167 // flash when activated
168 pointparticles(particleeffectnum("jumppad_activate"), other.origin, other.velocity, 1);
169 sound (other, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NORM);
170 self.pushltime = time + 0.2;
172 if(IS_REAL_CLIENT(other) || IS_BOT_CLIENT(other))
177 for(i = 0; i < other.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
178 if(other.(jumppadsused[i]) == self)
182 other.(jumppadsused[other.jumppadcount % NUM_JUMPPADSUSED]) = self;
183 other.jumppadcount = other.jumppadcount + 1;
186 if(IS_REAL_CLIENT(other))
189 centerprint(other, self.message);
192 other.lastteleporttime = time;
194 if (other.deadflag == DEAD_NO)
195 animdecide_setaction(other, ANIMACTION_JUMP, true);
198 other.jumppadcount = true;
200 // reset tracking of who pushed you into a hazard (for kill credit)
202 other.istypefrag = 0;
205 if(self.enemy.target)
215 if (other.flags & FL_PROJECTILE)
217 other.angles = vectoangles (other.velocity);
218 switch(other.movetype)
221 other.movetype = MOVETYPE_TOSS;
224 case MOVETYPE_BOUNCEMISSILE:
225 other.movetype = MOVETYPE_BOUNCE;
229 UpdateCSQCProjectile(other);
232 if (self.spawnflags & PUSH_ONCE)
234 self.touch = func_null;
235 self.think = SUB_Remove;
236 self.nextthink = time;
240 void trigger_push_findtarget()
245 // first calculate a typical start point for the jump
246 org = (self.absmin + self.absmax) * 0.5;
247 org_z = self.absmax.z - PL_MIN_z;
253 for(t = world; (t = find(t, targetname, self.target)); )
258 setsize(e, PL_MIN, PL_MAX);
259 e.velocity = trigger_push_calculatevelocity(org, t, self.height);
261 if(e.movetype == MOVETYPE_NONE)
262 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
269 objerror ("Jumppad with nonexistant target");
274 // exactly one dest - bots love that
275 self.enemy = find(world, targetname, self.target);
279 // have to use random selection every single time
287 setsize(e, PL_MIN, PL_MAX);
288 e.velocity = self.movedir;
290 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
298 * target: target of jump
299 * height: the absolute value is the height of the highest point of the jump
300 * trajectory above the higher one of the player and the target.
301 * the sign indicates whether the highest point is INSIDE (positive)
302 * or OUTSIDE (negative) of the jump trajectory. General rule: use
303 * positive values for targets mounted on the floor, and use negative
304 * values to target a point on the ceiling.
305 * movedir: if target is not set, this * speed * 10 is the velocity to be reached.
307 void spawnfunc_trigger_push()
313 self.active = ACTIVE_ACTIVE;
314 self.use = trigger_push_use;
315 self.touch = trigger_push_touch;
320 self.movedir = self.movedir * self.speed * 10;
323 self.noise = "misc/jumppad.wav";
324 precache_sound (self.noise);
326 // this must be called to spawn the teleport waypoints for bots
327 InitializeEntity(self, trigger_push_findtarget, INITPRIO_FINDTARGET);
330 void spawnfunc_target_push() {}
331 void spawnfunc_info_notnull() {}
332 void spawnfunc_target_position() {}