1 #include "t_jumppads.qh"
6 #include "bot/navigation.qh"
7 #include "bot/waypoints.qh"
9 #include "weapons/csqcprojectile.qh"
11 #include "../common/animdecide.qh"
13 #include "../warpzonelib/util_server.qh"
15 void trigger_push_use()
18 self.team = activator.team;
22 trigger_push_calculatevelocity
25 org - origin of the object which is to be pushed
26 tgt - target entity (can be either a point or a model entity; if it is
27 the latter, its midpoint is used)
28 ht - jump height, measured from the higher one of org and tgt's midpoint
30 Returns: velocity for the jump
31 the global trigger_push_calculatevelocity_flighttime is set to the total
35 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht)
37 float grav, sdist, zdist, vs, vz, jumpheight;
40 torg = tgt.origin + (tgt.mins + tgt.maxs) * 0.5;
42 grav = autocvar_sv_gravity;
44 grav *= other.gravity;
46 zdist = torg.z - org.z;
47 sdist = vlen(torg - org - zdist * '0 0 1');
48 sdir = normalize(torg - org - zdist * '0 0 1');
50 // how high do we need to push the player?
51 jumpheight = fabs(ht);
53 jumpheight = jumpheight + zdist;
58 You will not understand the following equations anyway...
59 But here is what I did to get them.
64 z(t) = t * vz - 1/2 grav t^2
70 max(z, ti) = jumpheight
72 From these three equations, you will find the three parameters vs, vz
76 // push him so high...
77 vz = sqrt(fabs(2 * grav * jumpheight)); // NOTE: sqrt(positive)!
79 // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump!
85 solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
86 // ALWAYS solvable because jumpheight >= zdist
88 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)
90 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)
97 // almost straight line type
98 // jump apex is before the jump
99 // we must take the larger one
100 trigger_push_calculatevelocity_flighttime = solution.y;
105 // jump apex is during the jump
106 // we must take the larger one too
107 trigger_push_calculatevelocity_flighttime = solution.y;
115 // almost straight line type
116 // jump apex is after the jump
117 // we must take the smaller one
118 trigger_push_calculatevelocity_flighttime = solution.x;
123 // jump apex is during the jump
124 // we must take the larger one
125 trigger_push_calculatevelocity_flighttime = solution.y;
128 vs = sdist / trigger_push_calculatevelocity_flighttime;
130 // finally calculate the velocity
131 return sdir * vs + '0 0 1' * vz;
134 void trigger_push_touch()
136 if (self.active == ACTIVE_NOT)
139 if (!isPushable(other))
143 if(((self.spawnflags & 4) == 0) == (self.team != other.team))
150 other.velocity = trigger_push_calculatevelocity(other.origin, self.enemy, self.height);
155 RandomSelection_Init();
156 for(e = world; (e = find(e, targetname, self.target)); )
159 RandomSelection_Add(e, 0, string_null, e.cnt, 1);
161 RandomSelection_Add(e, 0, string_null, 1, 1);
163 other.velocity = trigger_push_calculatevelocity(other.origin, RandomSelection_chosen_ent, self.height);
167 other.velocity = self.movedir;
170 other.flags &= ~FL_ONGROUND;
172 if (IS_PLAYER(other))
174 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
175 other.oldvelocity = other.velocity;
177 if(self.pushltime < time) // prevent "snorring" sound when a player hits the jumppad more than once
179 // flash when activated
180 pointparticles(particleeffectnum("jumppad_activate"), other.origin, other.velocity, 1);
181 sound (other, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NORM);
182 self.pushltime = time + 0.2;
184 if(IS_REAL_CLIENT(other) || IS_BOT_CLIENT(other))
187 for(int i = 0; i < other.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
188 if(other.(jumppadsused[i]) == self)
192 other.(jumppadsused[other.jumppadcount % NUM_JUMPPADSUSED]) = self;
193 other.jumppadcount = other.jumppadcount + 1;
196 if(IS_REAL_CLIENT(other))
199 centerprint(other, self.message);
202 other.lastteleporttime = time;
204 if (other.deadflag == DEAD_NO)
205 animdecide_setaction(other, ANIMACTION_JUMP, true);
208 other.jumppadcount = true;
210 // reset tracking of who pushed you into a hazard (for kill credit)
212 other.istypefrag = 0;
215 if(self.enemy.target)
225 if (other.flags & FL_PROJECTILE)
227 other.angles = vectoangles (other.velocity);
228 switch(other.movetype)
231 other.movetype = MOVETYPE_TOSS;
234 case MOVETYPE_BOUNCEMISSILE:
235 other.movetype = MOVETYPE_BOUNCE;
239 UpdateCSQCProjectile(other);
242 if (self.spawnflags & PUSH_ONCE)
244 self.touch = func_null;
245 self.think = SUB_Remove;
246 self.nextthink = time;
250 void trigger_push_findtarget()
255 // first calculate a typical start point for the jump
256 org = (self.absmin + self.absmax) * 0.5;
257 org.z = self.absmax.z - PL_MIN_z;
263 for(t = world; (t = find(t, targetname, self.target)); )
268 setsize(e, PL_MIN, PL_MAX);
269 e.velocity = trigger_push_calculatevelocity(org, t, self.height);
271 if(e.movetype == MOVETYPE_NONE)
272 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
279 objerror ("Jumppad with nonexistant target");
284 // exactly one dest - bots love that
285 self.enemy = find(world, targetname, self.target);
289 // have to use random selection every single time
297 setsize(e, PL_MIN, PL_MAX);
298 e.velocity = self.movedir;
300 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
308 * target: target of jump
309 * height: the absolute value is the height of the highest point of the jump
310 * trajectory above the higher one of the player and the target.
311 * the sign indicates whether the highest point is INSIDE (positive)
312 * or OUTSIDE (negative) of the jump trajectory. General rule: use
313 * positive values for targets mounted on the floor, and use negative
314 * values to target a point on the ceiling.
315 * movedir: if target is not set, this * speed * 10 is the velocity to be reached.
317 void spawnfunc_trigger_push()
323 self.active = ACTIVE_ACTIVE;
324 self.use = trigger_push_use;
325 self.touch = trigger_push_touch;
330 self.movedir = self.movedir * self.speed * 10;
333 self.noise = "misc/jumppad.wav";
334 precache_sound (self.noise);
336 // this must be called to spawn the teleport waypoints for bots
337 InitializeEntity(self, trigger_push_findtarget, INITPRIO_FINDTARGET);
340 void spawnfunc_target_push() {}
341 void spawnfunc_info_notnull() {}
342 void spawnfunc_target_position() {}