[nexuiz-commits] r6780 - in trunk/data/qcsrc: common server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Wed May 27 12:32:25 EDT 2009


Author: div0
Date: 2009-05-27 12:32:23 -0400 (Wed, 27 May 2009)
New Revision: 6780

Modified:
   trunk/data/qcsrc/common/util.qc
   trunk/data/qcsrc/common/util.qh
   trunk/data/qcsrc/server/cl_client.qc
   trunk/data/qcsrc/server/cl_weapons.qc
   trunk/data/qcsrc/server/g_world.qc
   trunk/data/qcsrc/server/miscfunctions.qc
   trunk/data/qcsrc/server/runematch.qc
   trunk/data/qcsrc/server/sv_main.qc
   trunk/data/qcsrc/server/t_items.qc
   trunk/data/qcsrc/server/t_teleporters.qc
Log:

- move RandomSelection to misc/
- allow strings to be randomly selected too


Modified: trunk/data/qcsrc/common/util.qc
===================================================================
--- trunk/data/qcsrc/common/util.qc	2009-05-27 12:31:47 UTC (rev 6779)
+++ trunk/data/qcsrc/common/util.qc	2009-05-27 16:32:23 UTC (rev 6780)
@@ -1533,3 +1533,34 @@
 		// end of siftdown
 	}
 }
+
+void RandomSelection_Init()
+{
+	RandomSelection_totalweight = 0;
+	RandomSelection_chosen_ent = world;
+	RandomSelection_chosen_float = 0;
+	RandomSelection_chosen_string = string_null;
+	RandomSelection_best_priority = -1;
+}
+void RandomSelection_Add(entity e, float f, string s, float weight, float priority)
+{
+	if(priority > RandomSelection_best_priority)
+	{
+		RandomSelection_best_priority = priority;
+		RandomSelection_chosen_ent = e;
+		RandomSelection_chosen_float = f;
+		RandomSelection_chosen_string = s;
+		RandomSelection_totalweight = weight;
+	}
+	else if(priority == RandomSelection_best_priority)
+	{
+		RandomSelection_totalweight += weight;
+		if(random() * RandomSelection_totalweight <= weight)
+		{
+			RandomSelection_chosen_ent = e;
+			RandomSelection_chosen_float = f;
+			RandomSelection_chosen_string = s;
+		}
+	}
+}
+

Modified: trunk/data/qcsrc/common/util.qh
===================================================================
--- trunk/data/qcsrc/common/util.qh	2009-05-27 12:31:47 UTC (rev 6779)
+++ trunk/data/qcsrc/common/util.qh	2009-05-27 16:32:23 UTC (rev 6780)
@@ -162,3 +162,11 @@
 vector decompressShotOrigin(float f);
 
 string records_reply, lsmaps_reply, maplist_reply; // cached replies
+
+float RandomSelection_totalweight;
+float RandomSelection_best_priority;
+entity RandomSelection_chosen_ent;
+float RandomSelection_chosen_float;
+string RandomSelection_chosen_string;
+void RandomSelection_Init();
+void RandomSelection_Add(entity e, float f, string s, float weight, float priority);

Modified: trunk/data/qcsrc/server/cl_client.qc
===================================================================
--- trunk/data/qcsrc/server/cl_client.qc	2009-05-27 12:31:47 UTC (rev 6779)
+++ trunk/data/qcsrc/server/cl_client.qc	2009-05-27 16:32:23 UTC (rev 6780)
@@ -261,7 +261,7 @@
 
 	RandomSelection_Init();
 	for(spot = firstspot; spot; spot = spot.chain)
-		RandomSelection_Add(spot, 0, pow(bound(lower, spot.SPAWNPOINT_SCORE, upper), exponent) * spot.cnt, spot.SPAWNPOINT_SCORE >= lower);
+		RandomSelection_Add(spot, 0, string_null, pow(bound(lower, spot.SPAWNPOINT_SCORE, upper), exponent) * spot.cnt, spot.SPAWNPOINT_SCORE >= lower);
 
 	return RandomSelection_chosen_ent;
 }

Modified: trunk/data/qcsrc/server/cl_weapons.qc
===================================================================
--- trunk/data/qcsrc/server/cl_weapons.qc	2009-05-27 12:31:47 UTC (rev 6779)
+++ trunk/data/qcsrc/server/cl_weapons.qc	2009-05-27 16:32:23 UTC (rev 6780)
@@ -428,7 +428,7 @@
 	RandomSelection_Init();
 	for(j = WEP_FIRST; j <= WEP_LAST; ++j)
 		if(NixNex_CanChooseWeapon(j))
-			RandomSelection_Add(world, j, 1, (j != nixnex_weapon));
+			RandomSelection_Add(world, j, string_null, 1, (j != nixnex_weapon));
 	nixnex_nextweapon = RandomSelection_chosen_float;
 }
 

Modified: trunk/data/qcsrc/server/g_world.qc
===================================================================
--- trunk/data/qcsrc/server/g_world.qc	2009-05-27 12:31:47 UTC (rev 6779)
+++ trunk/data/qcsrc/server/g_world.qc	2009-05-27 16:32:23 UTC (rev 6780)
@@ -2285,7 +2285,7 @@
 
 	RandomSelection_Init();
 	for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
-		RandomSelection_Add(world, i, 1, mapvote_votes[i]);
+		RandomSelection_Add(world, i, string_null, 1, mapvote_votes[i]);
 	firstPlace = RandomSelection_chosen_float;
 	firstPlaceVotes = RandomSelection_best_priority;
 	//dprint("First place: ", ftos(firstPlace), "\n");
@@ -2294,7 +2294,7 @@
 	RandomSelection_Init();
 	for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
 		if(i != firstPlace)
-			RandomSelection_Add(world, i, 1, mapvote_votes[i]);
+			RandomSelection_Add(world, i, string_null, 1, mapvote_votes[i]);
 	secondPlace = RandomSelection_chosen_float;
 	secondPlaceVotes = RandomSelection_best_priority;
 	//dprint("Second place: ", ftos(secondPlace), "\n");

Modified: trunk/data/qcsrc/server/miscfunctions.qc
===================================================================
--- trunk/data/qcsrc/server/miscfunctions.qc	2009-05-27 12:31:47 UTC (rev 6779)
+++ trunk/data/qcsrc/server/miscfunctions.qc	2009-05-27 16:32:23 UTC (rev 6780)
@@ -7,37 +7,6 @@
 void() spawnpoint_use;
 string ColoredTeamName(float t);
 
-float RandomSelection_totalweight;
-float RandomSelection_best_priority;
-entity RandomSelection_chosen_ent;
-float RandomSelection_chosen_float;
-void RandomSelection_Init()
-{
-	RandomSelection_totalweight = 0;
-	RandomSelection_chosen_ent = world;
-	RandomSelection_chosen_float = 0;
-	RandomSelection_best_priority = -1;
-}
-void RandomSelection_Add(entity e, float f, float weight, float priority)
-{
-	if(priority > RandomSelection_best_priority)
-	{
-		RandomSelection_best_priority = priority;
-		RandomSelection_chosen_ent = e;
-		RandomSelection_chosen_float = f;
-		RandomSelection_totalweight = weight;
-	}
-	else if(priority == RandomSelection_best_priority)
-	{
-		RandomSelection_totalweight += weight;
-		if(random() * RandomSelection_totalweight <= weight)
-		{
-			RandomSelection_chosen_ent = e;
-			RandomSelection_chosen_float = f;
-		}
-	}
-}
-
 float DistributeEvenly_amount;
 float DistributeEvenly_totalweight;
 void DistributeEvenly_Init(float amount, float totalweight)

Modified: trunk/data/qcsrc/server/runematch.qc
===================================================================
--- trunk/data/qcsrc/server/runematch.qc	2009-05-27 12:31:47 UTC (rev 6779)
+++ trunk/data/qcsrc/server/runematch.qc	2009-05-27 16:32:23 UTC (rev 6780)
@@ -59,7 +59,7 @@
 
 	for(e = world; (e = find(e, classname, "runematch_spawn_point")); )
 		if(e.owner == world)
-			RandomSelection_Add(e, 0, e.cnt, 0);
+			RandomSelection_Add(e, 0, string_null, e.cnt, 0);
 
 	return RandomSelection_chosen_ent;
 }
@@ -460,14 +460,14 @@
 		RandomSelection_Init();
 		for(rn = RUNE_FIRST; rn <= RUNE_LAST; rn *= 2)
 			if not(runes_used & rn)
-				RandomSelection_Add(world, rn, 1, 1);
+				RandomSelection_Add(world, rn, string_null, 1, 1);
 		rn = RandomSelection_chosen_float;
 
 		RandomSelection_Init();
 		for(cs = CURSE_FIRST; cs <= CURSE_LAST; cs *= 2)
 			if not(curses_used & cs)
 				if not(prevent_same && cs == RuneMatchesCurse(rn, cs))
-					RandomSelection_Add(world, cs, 1, 1);
+					RandomSelection_Add(world, cs, string_null, 1, 1);
 		cs = RandomSelection_chosen_float;
 
 		if(!rn || !cs)

Modified: trunk/data/qcsrc/server/sv_main.qc
===================================================================
--- trunk/data/qcsrc/server/sv_main.qc	2009-05-27 12:31:47 UTC (rev 6779)
+++ trunk/data/qcsrc/server/sv_main.qc	2009-05-27 16:32:23 UTC (rev 6780)
@@ -200,7 +200,7 @@
 	{
 		RandomSelection_Init();
 		for(self = world; (self = find(self, classname, "player")); )
-			RandomSelection_Add(self, 0, 1, 0);
+			RandomSelection_Add(self, 0, string_null, 1, 0);
 		self = RandomSelection_chosen_ent;
 		SelectSpawnPoint(0);
 	}

Modified: trunk/data/qcsrc/server/t_items.qc
===================================================================
--- trunk/data/qcsrc/server/t_items.qc	2009-05-27 12:31:47 UTC (rev 6779)
+++ trunk/data/qcsrc/server/t_items.qc	2009-05-27 16:32:23 UTC (rev 6780)
@@ -379,7 +379,7 @@
 		{
 			RandomSelection_Init();
 			for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
-				RandomSelection_Add(head, 0, head.cnt, 0);
+				RandomSelection_Add(head, 0, string_null, head.cnt, 0);
 			e = RandomSelection_chosen_ent;
 		}
 		else
@@ -398,7 +398,7 @@
 		dprint("Initializing item team ", ftos(self.team), "\n");
 		RandomSelection_Init();
 		for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
-			RandomSelection_Add(head, 0, head.cnt, 0);
+			RandomSelection_Add(head, 0, string_null, head.cnt, 0);
 		e = RandomSelection_chosen_ent;
 		e.state = 0;
 

Modified: trunk/data/qcsrc/server/t_teleporters.qc
===================================================================
--- trunk/data/qcsrc/server/t_teleporters.qc	2009-05-27 12:31:47 UTC (rev 6779)
+++ trunk/data/qcsrc/server/t_teleporters.qc	2009-05-27 16:32:23 UTC (rev 6780)
@@ -139,9 +139,9 @@
 		for(e = world; (e = find(e, targetname, self.target)); )
 		{
 			if(e.cnt)
-				RandomSelection_Add(e, 0, e.cnt, 0);
+				RandomSelection_Add(e, 0, string_null, e.cnt, 0);
 			else
-				RandomSelection_Add(e, 0, 1, 0);
+				RandomSelection_Add(e, 0, string_null, 1, 0);
 		}
 		e = RandomSelection_chosen_ent;
 	}



More information about the nexuiz-commits mailing list