2 float PUSH_SILENT = 2;
\r
7 void() SUB_UseTargets;
\r
9 float trigger_push_calculatevelocity_flighttime;
\r
11 void trigger_push_use()
\r
14 self.team = activator.team;
\r
18 trigger_push_calculatevelocity
\r
21 org - origin of the object which is to be pushed
\r
22 tgt - target entity (can be either a point or a model entity; if it is
\r
23 the latter, its midpoint is used)
\r
24 ht - jump height, measured from the higher one of org and tgt's midpoint
\r
26 Returns: velocity for the jump
\r
27 the global trigger_push_calculatevelocity_flighttime is set to the total
\r
31 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht)
\r
33 local float grav, sdist, zdist, vs, vz, jumpheight;
\r
34 local vector sdir, torg;
\r
36 torg = tgt.origin + (tgt.mins + tgt.maxs) * 0.5;
\r
38 grav = cvar("sv_gravity");
\r
40 zdist = torg_z - org_z;
\r
41 sdist = vlen(torg - org - zdist * '0 0 1');
\r
42 sdir = normalize(torg - org - zdist * '0 0 1');
\r
44 // how high do we need to push the player?
\r
45 jumpheight = fabs(ht);
\r
47 jumpheight = jumpheight + zdist;
\r
52 You will not understand the following equations anyway...
\r
53 But here is what I did to get them.
\r
55 I used the functions
\r
58 z(t) = t * vz - 1/2 grav t^2
\r
64 max(z, ti) = jumpheight
\r
66 From these three equations, you will find the three parameters vs, vz
\r
70 // push him so high...
\r
71 vz = sqrt(2 * grav * jumpheight); // NOTE: sqrt(positive)!
\r
73 // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump!
\r
79 solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
\r
80 // ALWAYS solvable because jumpheight >= zdist
\r
82 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)
\r
84 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)
\r
91 // almost straight line type
\r
92 // jump apex is before the jump
\r
93 // we must take the larger one
\r
94 trigger_push_calculatevelocity_flighttime = solution_y;
\r
99 // jump apex is during the jump
\r
100 // we must take the larger one too
\r
101 trigger_push_calculatevelocity_flighttime = solution_y;
\r
109 // almost straight line type
\r
110 // jump apex is after the jump
\r
111 // we must take the smaller one
\r
112 trigger_push_calculatevelocity_flighttime = solution_x;
\r
117 // jump apex is during the jump
\r
118 // we must take the larger one
\r
119 trigger_push_calculatevelocity_flighttime = solution_y;
\r
122 vs = sdist / trigger_push_calculatevelocity_flighttime;
\r
124 // finally calculate the velocity
\r
125 return sdir * vs + '0 0 1' * vz;
\r
128 void trigger_push_touch()
\r
130 // FIXME: add a .float for whether an entity should be tossed by jumppads
\r
131 if (!other.iscreature)
\r
132 if (other.classname != "corpse")
\r
133 if (other.classname != "body")
\r
134 if (other.classname != "gib")
\r
135 if (other.classname != "casing")
\r
136 if (other.classname != "droppedweapon")
\r
137 if (!other.projectiledeathtype || other.classname == "bullet")
\r
140 if (other.deadflag && other.iscreature)
\r
144 if((self.spawnflags & 4 == 0) == (self.team != other.team))
\r
147 EXACTTRIGGER_TOUCH;
\r
150 self.movedir = trigger_push_calculatevelocity(other.origin, self.enemy, self.height);
\r
152 other.flags &~= FL_ONGROUND;
\r
154 other.velocity = self.movedir;
\r
155 other.jumppadusetime = time;
\r
157 if (other.classname == "player")
\r
159 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
\r
160 other.oldvelocity = other.velocity;
\r
162 if(self.pushltime < time) // prevent "snorring" sound when a player hits the jumppad more than once
\r
164 // flash when activated
\r
165 pointparticles(particleeffectnum("jumppad_activate"), other.origin, other.velocity, 1);
\r
166 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NORM);
\r
167 self.pushltime = time + 0.2;
\r
170 ct = clienttype(other);
\r
171 if( ct == CLIENTTYPE_REAL)
\r
176 for(i = 0; i < other.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
\r
177 if(other.(jumppadsused[i]) == self)
\r
181 other.(jumppadsused[mod(other.jumppadcount, NUM_JUMPPADSUSED)]) = self;
\r
182 other.jumppadcount = other.jumppadcount + 1;
\r
186 centerprint(other, self.message);
\r
188 else if(ct == CLIENTTYPE_BOT)
\r
189 other.lastteleporttime = time;
\r
191 other.jumppadcount = TRUE;
\r
193 // reset tracking of who pushed you into a hazard (for kill credit)
\r
194 other.pushltime = 0;
\r
197 if(self.enemy.target)
\r
207 if (other.flags & FL_PROJECTILE)
\r
209 other.angles = vectoangles (other.velocity);
\r
210 switch(other.movetype)
\r
213 other.movetype = MOVETYPE_TOSS;
\r
216 case MOVETYPE_BOUNCEMISSILE:
\r
217 other.movetype = MOVETYPE_BOUNCE;
\r
221 UpdateCSQCProjectile(other);
\r
224 if (self.spawnflags & PUSH_ONCE)
\r
226 self.touch = SUB_Null;
\r
227 self.think = SUB_Remove;
\r
228 self.nextthink = time;
\r
234 void trigger_push_findtarget()
\r
238 local float flighttime;
\r
240 // first calculate a typical start point for the jump
\r
241 org = (self.absmin + self.absmax) * 0.5;
\r
242 org_z = self.absmax_z - PL_MIN_z;
\r
247 self.enemy = find(world, targetname, self.target);
\r
250 objerror("trigger_push: target not found\n");
\r
255 self.movedir = trigger_push_calculatevelocity(org, self.enemy, self.height);
\r
256 flighttime = trigger_push_calculatevelocity_flighttime;
\r
261 // calculate the destination and spawn a teleporter spawnfunc_waypoint
\r
264 setsize(e, PL_MIN, PL_MAX);
\r
265 e.velocity = self.movedir;
\r
267 self.dest = trace_endpos;
\r
270 waypoint_spawnforteleporter(self, self.dest, flighttime);
\r
274 * ENTITY PARAMETERS:
\r
276 * target: target of jump
\r
277 * height: the absolute value is the height of the highest point of the jump
\r
278 * trajectory above the higher one of the player and the target.
\r
279 * the sign indicates whether the highest point is INSIDE (positive)
\r
280 * or OUTSIDE (negative) of the jump trajectory. General rule: use
\r
281 * positive values for targets mounted on the floor, and use negative
\r
282 * values to target a point on the ceiling.
\r
283 * movedir: if target is not set, this * speed * 10 is the velocity to be reached.
\r
285 void spawnfunc_trigger_push()
\r
287 if (self.angles != '0 0 0')
\r
292 self.use = trigger_push_use;
\r
293 self.touch = trigger_push_touch;
\r
295 // normal push setup
\r
298 self.movedir = self.movedir * self.speed * 10;
\r
301 self.noise = "misc/jumppad.wav";
\r
302 precache_sound (self.noise);
\r
304 // this must be called to spawn the teleport waypoints for bots
\r
305 InitializeEntity(self, trigger_push_findtarget, INITPRIO_FINDTARGET);
\r
308 void spawnfunc_target_push() {};
\r
309 void spawnfunc_info_notnull() {};
\r
310 void spawnfunc_target_position() {};
\r