r5717 - trunk/data/qcsrc/server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Mon Feb 2 09:28:47 EST 2009


Author: div0
Date: 2009-02-02 09:28:47 -0500 (Mon, 02 Feb 2009)
New Revision: 5717

Modified:
   trunk/data/qcsrc/server/cl_impulse.qc
   trunk/data/qcsrc/server/miscfunctions.qc
Log:
factor out impulse 911 into a function MoveToRandomMapLocation


Modified: trunk/data/qcsrc/server/cl_impulse.qc
===================================================================
--- trunk/data/qcsrc/server/cl_impulse.qc	2009-02-02 08:09:14 UTC (rev 5716)
+++ trunk/data/qcsrc/server/cl_impulse.qc	2009-02-02 14:28:47 UTC (rev 5717)
@@ -95,12 +95,8 @@
 void ImpulseCommands (void)
 {
 	local float imp;
-	vector start, end, enddown;
 	float i;
 	float m;
-	float good, evil, evilsurf;
-	float maxattempts;
-	vector org, delta;
 	float wep;
 	entity e;
 
@@ -394,99 +390,14 @@
 							sprint(self, "No waypoint set, cheater (use g_waypointsprite_personal to set one)\n");
 						break;
 					case 143:
-						good = DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP;
-						evil = DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER;
-						evilsurf = Q3SURFACEFLAG_SKY;
-
-						m = self.dphitcontentsmask;
-						self.dphitcontentsmask = good | evil;
-
-						org = world.mins;
-						delta = world.maxs - world.mins;
-
-						maxattempts = ((sv_cheats >= 2) ? 100000 : 100);
-
-						for(i = 0; i < maxattempts; ++i)
+						if(MoveToRandomMapLocation(self, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY, ((sv_cheats >= 2) ? 100000 : 100), 1024, 256))
 						{
-							start_x = org_x + random() * delta_x;
-							start_y = org_y + random() * delta_y;
-							start_z = org_z + random() * delta_z;
-
-							// rule 1: start inside world bounds, and outside
-							// solid, and don't start from somewhere where you can
-							// fall down to evil
-							tracebox(start, self.mins, self.maxs, start - '0 0 1' * delta_z, MOVE_NORMAL, self);
-							if(trace_fraction >= 1)
-								continue;
-							if(trace_startsolid)
-								continue;
-							dprint("hit contents ", ftos(trace_dphitcontents), "\n");
-							if(trace_dphitcontents & evil)
-								continue;
-							if(trace_dphitq3surfaceflags & evilsurf)
-								continue;
-
-							// rule 2: if we are too high, lower the point
-							if(trace_fraction * delta_z > 1024)
-								start = trace_endpos + '0 0 1024';
-							enddown = trace_endpos;
-
-							// these can be traceLINES as we already verified the starting box
-							traceline(start, start + '1 0 0' * delta_x, MOVE_NORMAL, self);
-							if(trace_fraction >= 1)
-								continue;
-							traceline(start, start - '1 0 0' * delta_x, MOVE_NORMAL, self);
-							if(trace_fraction >= 1)
-								continue;
-							traceline(start, start + '0 1 0' * delta_y, MOVE_NORMAL, self);
-							if(trace_fraction >= 1)
-								continue;
-							traceline(start, start - '0 1 0' * delta_y, MOVE_NORMAL, self);
-							if(trace_fraction >= 1)
-								continue;
-							traceline(start, start + '0 0 1' * delta_z, MOVE_NORMAL, self);
-							if(trace_fraction >= 1)
-								continue;
-
-							end_x = org_x + random() * delta_x;
-							end_y = org_y + random() * delta_y;
-							end_z = org_z + random() * delta_z;
-							end = start + normalize(end - start) * vlen(delta);
-
-							// rule 3: start TO end must not be too short
-							tracebox(start, self.mins, self.maxs, end, MOVE_NORMAL, self);
-							if(trace_startsolid)
-								continue;
-							if(trace_fraction < 256 / vlen(delta))
-								continue;
-
-							// rule 4: don't want to look at sky
-							if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
-								continue;
-
-							// rule 5: we must not end up in trigger_hurt
-							if(tracebox_hits_trigger_hurt(start, self.mins, self.maxs, enddown))
-							{
-								dprint("trigger_hurt! ouch! and nothing else could find it!\n");
-								continue;
-							}
-
-							break;
-						}
-
-						if(i < maxattempts)
-						{
-							self.origin = start;
-							self.angles = vectoangles(end - start);
 							self.angles_x = -self.angles_x;
 							self.fixangle = TRUE;
 							self.velocity = '0 0 0';
-							dprint("Needed ", ftos(i + 1), " attempts\n");
 						}
 						else
 							sprint(self, "Emergency teleport could not find a good location, forget it!\n");
-
-						self.dphitcontentsmask = m;
 						break;
 					case 144:
 						makevectors(self.v_angle);

Modified: trunk/data/qcsrc/server/miscfunctions.qc
===================================================================
--- trunk/data/qcsrc/server/miscfunctions.qc	2009-02-02 08:09:14 UTC (rev 5716)
+++ trunk/data/qcsrc/server/miscfunctions.qc	2009-02-02 14:28:47 UTC (rev 5717)
@@ -1858,3 +1858,98 @@
 	else
 		return strcat("Records on this server:\n", s);
 }
+
+float MoveToRandomMapLocation(entity e, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance)
+{
+	float m, i;
+	vector start, org, delta, end, enddown;
+
+	m = e.dphitcontentsmask;
+	e.dphitcontentsmask = goodcontents | badcontents;
+
+	org = world.mins;
+	delta = world.maxs - world.mins;
+
+	for(i = 0; i < attempts; ++i)
+	{
+		start_x = org_x + random() * delta_x;
+		start_y = org_y + random() * delta_y;
+		start_z = org_z + random() * delta_z;
+
+		// rule 1: start inside world bounds, and outside
+		// solid, and don't start from somewhere where you can
+		// fall down to evil
+		tracebox(start, e.mins, e.maxs, start - '0 0 1' * delta_z, MOVE_NORMAL, e);
+		if(trace_fraction >= 1)
+			continue;
+		if(trace_startsolid)
+			continue;
+		if(trace_dphitcontents & badcontents)
+			continue;
+		if(trace_dphitq3surfaceflags & badsurfaceflags)
+			continue;
+
+		// rule 2: if we are too high, lower the point
+		if(trace_fraction * delta_z > maxaboveground)
+			start = trace_endpos + '0 0 1' * maxaboveground;
+		enddown = trace_endpos;
+
+		// rule 3: make sure we aren't outside the map. This only works
+		// for somewhat well formed maps. A good rule of thumb is that
+		// the map should have a convex outside hull.
+		// these can be traceLINES as we already verified the starting box
+		traceline(start, start + '1 0 0' * delta_x, MOVE_NORMAL, e);
+		if(trace_fraction >= 1)
+			continue;
+		traceline(start, start - '1 0 0' * delta_x, MOVE_NORMAL, e);
+		if(trace_fraction >= 1)
+			continue;
+		traceline(start, start + '0 1 0' * delta_y, MOVE_NORMAL, e);
+		if(trace_fraction >= 1)
+			continue;
+		traceline(start, start - '0 1 0' * delta_y, MOVE_NORMAL, e);
+		if(trace_fraction >= 1)
+			continue;
+		traceline(start, start + '0 0 1' * delta_z, MOVE_NORMAL, e);
+		if(trace_fraction >= 1)
+			continue;
+
+		// find a random vector to "look at"
+		end_x = org_x + random() * delta_x;
+		end_y = org_y + random() * delta_y;
+		end_z = org_z + random() * delta_z;
+		end = start + normalize(end - start) * vlen(delta);
+
+		// rule 4: start TO end must not be too short
+		tracebox(start, e.mins, e.maxs, end, MOVE_NORMAL, e);
+		if(trace_startsolid)
+			continue;
+		if(trace_fraction < minviewdistance / vlen(delta))
+			continue;
+
+		// rule 5: don't want to look at sky
+		if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
+			continue;
+
+		// rule 6: we must not end up in trigger_hurt
+		if(tracebox_hits_trigger_hurt(start, e.mins, e.maxs, enddown))
+		{
+			dprint("trigger_hurt! ouch! and nothing else could find it!\n");
+			continue;
+		}
+
+		break;
+	}
+
+	e.dphitcontentsmask = m;
+
+	if(i < attempts)
+	{
+		setorigin(e, start);
+		e.angles = vectoangles(end - start);
+		dprint("Needed ", ftos(i + 1), " attempts\n");
+		return TRUE;
+	}
+	else
+		return FALSE;
+}




More information about the nexuiz-commits mailing list