4 #include "../dpdefs/progsdefs.qc"
5 #include "../dpdefs/dpextensions.qc"
7 #include "../warpzonelib/util_server.qh"
8 #include "../common/constants.qh"
9 #include "../common/util.qh"
10 #include "../common/animdecide.qh"
11 #include "../common/weapons/weapons.qh"
12 #include "weapons/csqcprojectile.qh"
13 #include "constants.qh"
17 const float PUSH_ONCE = 1;
18 const float PUSH_SILENT = 2;
24 void() SUB_UseTargets;
26 float trigger_push_calculatevelocity_flighttime;
28 void trigger_push_use()
31 self.team = activator.team;
35 trigger_push_calculatevelocity
38 org - origin of the object which is to be pushed
39 tgt - target entity (can be either a point or a model entity; if it is
40 the latter, its midpoint is used)
41 ht - jump height, measured from the higher one of org and tgt's midpoint
43 Returns: velocity for the jump
44 the global trigger_push_calculatevelocity_flighttime is set to the total
48 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht)
50 float grav, sdist, zdist, vs, vz, jumpheight;
53 torg = tgt.origin + (tgt.mins + tgt.maxs) * 0.5;
55 grav = autocvar_sv_gravity;
57 grav *= other.gravity;
59 zdist = torg.z - org.z;
60 sdist = vlen(torg - org - zdist * '0 0 1');
61 sdir = normalize(torg - org - zdist * '0 0 1');
63 // how high do we need to push the player?
64 jumpheight = fabs(ht);
66 jumpheight = jumpheight + zdist;
71 You will not understand the following equations anyway...
72 But here is what I did to get them.
77 z(t) = t * vz - 1/2 grav t^2
83 max(z, ti) = jumpheight
85 From these three equations, you will find the three parameters vs, vz
89 // push him so high...
90 vz = sqrt(fabs(2 * grav * jumpheight)); // NOTE: sqrt(positive)!
92 // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump!
98 solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
99 // ALWAYS solvable because jumpheight >= zdist
101 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)
103 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)
110 // almost straight line type
111 // jump apex is before the jump
112 // we must take the larger one
113 trigger_push_calculatevelocity_flighttime = solution.y;
118 // jump apex is during the jump
119 // we must take the larger one too
120 trigger_push_calculatevelocity_flighttime = solution.y;
128 // almost straight line type
129 // jump apex is after the jump
130 // we must take the smaller one
131 trigger_push_calculatevelocity_flighttime = solution.x;
136 // jump apex is during the jump
137 // we must take the larger one
138 trigger_push_calculatevelocity_flighttime = solution.y;
141 vs = sdist / trigger_push_calculatevelocity_flighttime;
143 // finally calculate the velocity
144 return sdir * vs + '0 0 1' * vz;
147 void trigger_push_touch()
149 if (self.active == ACTIVE_NOT)
152 if (!isPushable(other))
156 if(((self.spawnflags & 4) == 0) == (self.team != other.team))
163 other.velocity = trigger_push_calculatevelocity(other.origin, self.enemy, self.height);
168 RandomSelection_Init();
169 for(e = world; (e = find(e, targetname, self.target)); )
172 RandomSelection_Add(e, 0, string_null, e.cnt, 1);
174 RandomSelection_Add(e, 0, string_null, 1, 1);
176 other.velocity = trigger_push_calculatevelocity(other.origin, RandomSelection_chosen_ent, self.height);
180 other.velocity = self.movedir;
183 other.flags &= ~FL_ONGROUND;
185 if (IS_PLAYER(other))
187 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
188 other.oldvelocity = other.velocity;
190 if(self.pushltime < time) // prevent "snorring" sound when a player hits the jumppad more than once
192 // flash when activated
193 pointparticles(particleeffectnum("jumppad_activate"), other.origin, other.velocity, 1);
194 sound (other, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NORM);
195 self.pushltime = time + 0.2;
197 if(IS_REAL_CLIENT(other) || IS_BOT_CLIENT(other))
202 for(i = 0; i < other.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
203 if(other.(jumppadsused[i]) == self)
207 other.(jumppadsused[other.jumppadcount % NUM_JUMPPADSUSED]) = self;
208 other.jumppadcount = other.jumppadcount + 1;
211 if(IS_REAL_CLIENT(other))
214 centerprint(other, self.message);
217 other.lastteleporttime = time;
219 if (other.deadflag == DEAD_NO)
220 animdecide_setaction(other, ANIMACTION_JUMP, true);
223 other.jumppadcount = true;
225 // reset tracking of who pushed you into a hazard (for kill credit)
227 other.istypefrag = 0;
230 if(self.enemy.target)
240 if (other.flags & FL_PROJECTILE)
242 other.angles = vectoangles (other.velocity);
243 switch(other.movetype)
246 other.movetype = MOVETYPE_TOSS;
249 case MOVETYPE_BOUNCEMISSILE:
250 other.movetype = MOVETYPE_BOUNCE;
254 UpdateCSQCProjectile(other);
257 if (self.spawnflags & PUSH_ONCE)
259 self.touch = func_null;
260 self.think = SUB_Remove;
261 self.nextthink = time;
266 void trigger_push_findtarget()
271 // first calculate a typical start point for the jump
272 org = (self.absmin + self.absmax) * 0.5;
273 org_z = self.absmax.z - PL_MIN_z;
279 for(t = world; (t = find(t, targetname, self.target)); )
284 setsize(e, PL_MIN, PL_MAX);
285 e.velocity = trigger_push_calculatevelocity(org, t, self.height);
287 if(e.movetype == MOVETYPE_NONE)
288 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
295 objerror ("Jumppad with nonexistant target");
300 // exactly one dest - bots love that
301 self.enemy = find(world, targetname, self.target);
305 // have to use random selection every single time
313 setsize(e, PL_MIN, PL_MAX);
314 e.velocity = self.movedir;
316 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
324 * target: target of jump
325 * height: the absolute value is the height of the highest point of the jump
326 * trajectory above the higher one of the player and the target.
327 * the sign indicates whether the highest point is INSIDE (positive)
328 * or OUTSIDE (negative) of the jump trajectory. General rule: use
329 * positive values for targets mounted on the floor, and use negative
330 * values to target a point on the ceiling.
331 * movedir: if target is not set, this * speed * 10 is the velocity to be reached.
333 void spawnfunc_trigger_push()
339 self.active = ACTIVE_ACTIVE;
340 self.use = trigger_push_use;
341 self.touch = trigger_push_touch;
346 self.movedir = self.movedir * self.speed * 10;
349 self.noise = "misc/jumppad.wav";
350 precache_sound (self.noise);
352 // this must be called to spawn the teleport waypoints for bots
353 InitializeEntity(self, trigger_push_findtarget, INITPRIO_FINDTARGET);
356 void spawnfunc_target_push() {}
357 void spawnfunc_info_notnull() {}
358 void spawnfunc_target_position() {}