4 #include "../dpdefs/progsdefs.qh"
5 #include "../dpdefs/dpextensions.qh"
6 #include "../warpzonelib/util_server.qh"
7 #include "../common/constants.qh"
8 #include "../common/util.qh"
9 #include "../common/animdecide.qh"
10 #include "../common/weapons/weapons.qh"
11 #include "weapons/csqcprojectile.qh"
12 #include "constants.qh"
16 const float PUSH_ONCE = 1;
17 const float PUSH_SILENT = 2;
23 void() SUB_UseTargets;
25 float trigger_push_calculatevelocity_flighttime;
27 void trigger_push_use()
30 self.team = activator.team;
34 trigger_push_calculatevelocity
37 org - origin of the object which is to be pushed
38 tgt - target entity (can be either a point or a model entity; if it is
39 the latter, its midpoint is used)
40 ht - jump height, measured from the higher one of org and tgt's midpoint
42 Returns: velocity for the jump
43 the global trigger_push_calculatevelocity_flighttime is set to the total
47 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht)
49 float grav, sdist, zdist, vs, vz, jumpheight;
52 torg = tgt.origin + (tgt.mins + tgt.maxs) * 0.5;
54 grav = autocvar_sv_gravity;
56 grav *= other.gravity;
58 zdist = torg.z - org.z;
59 sdist = vlen(torg - org - zdist * '0 0 1');
60 sdir = normalize(torg - org - zdist * '0 0 1');
62 // how high do we need to push the player?
63 jumpheight = fabs(ht);
65 jumpheight = jumpheight + zdist;
70 You will not understand the following equations anyway...
71 But here is what I did to get them.
76 z(t) = t * vz - 1/2 grav t^2
82 max(z, ti) = jumpheight
84 From these three equations, you will find the three parameters vs, vz
88 // push him so high...
89 vz = sqrt(fabs(2 * grav * jumpheight)); // NOTE: sqrt(positive)!
91 // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump!
97 solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
98 // ALWAYS solvable because jumpheight >= zdist
100 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)
102 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)
109 // almost straight line type
110 // jump apex is before the jump
111 // we must take the larger one
112 trigger_push_calculatevelocity_flighttime = solution.y;
117 // jump apex is during the jump
118 // we must take the larger one too
119 trigger_push_calculatevelocity_flighttime = solution.y;
127 // almost straight line type
128 // jump apex is after the jump
129 // we must take the smaller one
130 trigger_push_calculatevelocity_flighttime = solution.x;
135 // jump apex is during the jump
136 // we must take the larger one
137 trigger_push_calculatevelocity_flighttime = solution.y;
140 vs = sdist / trigger_push_calculatevelocity_flighttime;
142 // finally calculate the velocity
143 return sdir * vs + '0 0 1' * vz;
146 void trigger_push_touch()
148 if (self.active == ACTIVE_NOT)
151 if (!isPushable(other))
155 if(((self.spawnflags & 4) == 0) == (self.team != other.team))
162 other.velocity = trigger_push_calculatevelocity(other.origin, self.enemy, self.height);
167 RandomSelection_Init();
168 for(e = world; (e = find(e, targetname, self.target)); )
171 RandomSelection_Add(e, 0, string_null, e.cnt, 1);
173 RandomSelection_Add(e, 0, string_null, 1, 1);
175 other.velocity = trigger_push_calculatevelocity(other.origin, RandomSelection_chosen_ent, self.height);
179 other.velocity = self.movedir;
182 other.flags &= ~FL_ONGROUND;
184 if (IS_PLAYER(other))
186 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
187 other.oldvelocity = other.velocity;
189 if(self.pushltime < time) // prevent "snorring" sound when a player hits the jumppad more than once
191 // flash when activated
192 pointparticles(particleeffectnum("jumppad_activate"), other.origin, other.velocity, 1);
193 sound (other, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NORM);
194 self.pushltime = time + 0.2;
196 if(IS_REAL_CLIENT(other) || IS_BOT_CLIENT(other))
201 for(i = 0; i < other.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
202 if(other.(jumppadsused[i]) == self)
206 other.(jumppadsused[other.jumppadcount % NUM_JUMPPADSUSED]) = self;
207 other.jumppadcount = other.jumppadcount + 1;
210 if(IS_REAL_CLIENT(other))
213 centerprint(other, self.message);
216 other.lastteleporttime = time;
218 if (other.deadflag == DEAD_NO)
219 animdecide_setaction(other, ANIMACTION_JUMP, true);
222 other.jumppadcount = true;
224 // reset tracking of who pushed you into a hazard (for kill credit)
226 other.istypefrag = 0;
229 if(self.enemy.target)
239 if (other.flags & FL_PROJECTILE)
241 other.angles = vectoangles (other.velocity);
242 switch(other.movetype)
245 other.movetype = MOVETYPE_TOSS;
248 case MOVETYPE_BOUNCEMISSILE:
249 other.movetype = MOVETYPE_BOUNCE;
253 UpdateCSQCProjectile(other);
256 if (self.spawnflags & PUSH_ONCE)
258 self.touch = func_null;
259 self.think = SUB_Remove;
260 self.nextthink = time;
265 void trigger_push_findtarget()
270 // first calculate a typical start point for the jump
271 org = (self.absmin + self.absmax) * 0.5;
272 org_z = self.absmax.z - PL_MIN_z;
278 for(t = world; (t = find(t, targetname, self.target)); )
283 setsize(e, PL_MIN, PL_MAX);
284 e.velocity = trigger_push_calculatevelocity(org, t, self.height);
286 if(e.movetype == MOVETYPE_NONE)
287 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
294 objerror ("Jumppad with nonexistant target");
299 // exactly one dest - bots love that
300 self.enemy = find(world, targetname, self.target);
304 // have to use random selection every single time
312 setsize(e, PL_MIN, PL_MAX);
313 e.velocity = self.movedir;
315 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
323 * target: target of jump
324 * height: the absolute value is the height of the highest point of the jump
325 * trajectory above the higher one of the player and the target.
326 * the sign indicates whether the highest point is INSIDE (positive)
327 * or OUTSIDE (negative) of the jump trajectory. General rule: use
328 * positive values for targets mounted on the floor, and use negative
329 * values to target a point on the ceiling.
330 * movedir: if target is not set, this * speed * 10 is the velocity to be reached.
332 void spawnfunc_trigger_push()
338 self.active = ACTIVE_ACTIVE;
339 self.use = trigger_push_use;
340 self.touch = trigger_push_touch;
345 self.movedir = self.movedir * self.speed * 10;
348 self.noise = "misc/jumppad.wav";
349 precache_sound (self.noise);
351 // this must be called to spawn the teleport waypoints for bots
352 InitializeEntity(self, trigger_push_findtarget, INITPRIO_FINDTARGET);
355 void spawnfunc_target_push() {}
356 void spawnfunc_info_notnull() {}
357 void spawnfunc_target_position() {}