r4759 - in trunk/data/qcsrc: common server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Tue Oct 14 15:44:46 EDT 2008


Author: div0
Date: 2008-10-14 15:44:46 -0400 (Tue, 14 Oct 2008)
New Revision: 4759

Modified:
   trunk/data/qcsrc/common/gamecommand.qc
   trunk/data/qcsrc/common/mapinfo.qc
   trunk/data/qcsrc/server/cl_player.qc
   trunk/data/qcsrc/server/cl_weapons.qc
   trunk/data/qcsrc/server/g_world.qc
   trunk/data/qcsrc/server/runematch.qc
   trunk/data/qcsrc/server/t_items.qc
Log:
random does not ceil. Fixed.


Modified: trunk/data/qcsrc/common/gamecommand.qc
===================================================================
--- trunk/data/qcsrc/common/gamecommand.qc	2008-10-14 19:29:02 UTC (rev 4758)
+++ trunk/data/qcsrc/common/gamecommand.qc	2008-10-14 19:44:46 UTC (rev 4759)
@@ -127,7 +127,7 @@
 				//     to be on place n+1, their chance will be 1/(n+1)
 				//     1/n * n/(n+1) = 1/(n+1)
 				//     q.e.d.
-				f = ceil(random() * (i + 1)) - 1; // 0 to i
+				f = floor(random() * (i + 1)); // 0 to i
 				if(f == i)
 					continue; // no change
 
@@ -511,7 +511,7 @@
 					for(i = 0; i < f - 1; ++i) {
 						// move a random item from i..f-1 to position i
 						s = "";
-						f2 = ceil(random() * (f - i) + i) - 1;
+						f2 = floor(random() * (f - i) + i);
 						for(j = 0; j < i; ++j)
 							s = strcat(s, " ", argv(j));
 						s = strcat(s, " ", argv(f2));

Modified: trunk/data/qcsrc/common/mapinfo.qc
===================================================================
--- trunk/data/qcsrc/common/mapinfo.qc	2008-10-14 19:29:02 UTC (rev 4758)
+++ trunk/data/qcsrc/common/mapinfo.qc	2008-10-14 19:44:46 UTC (rev 4759)
@@ -543,7 +543,7 @@
 		fputs(fh, strcat("title ", MapInfo_Map_title, "\n"));
 		fputs(fh, strcat("description ", MapInfo_Map_description, "\n"));
 		fputs(fh, strcat("author ", MapInfo_Map_author, "\n"));
-		fputs(fh, strcat("cdtrack ", ftos(ceil(random() * 9 + 1)), "\n")); // track from 2 to 10
+		fputs(fh, strcat("cdtrack ", ftos(floor(random() * 9 + 2)), "\n")); // track from 2 to 10
 		if(MapInfo_Map_supportedFeatures & MAPINFO_FEATURE_WEAPONS)       fputs(fh, "has weapons\n");
 		if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_DEATHMATCH)      fputs(fh, "type dm 30 20\n");
 		if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_TEAM_DEATHMATCH) fputs(fh, "type tdm 50 20 2\n");

Modified: trunk/data/qcsrc/server/cl_player.qc
===================================================================
--- trunk/data/qcsrc/server/cl_player.qc	2008-10-14 19:29:02 UTC (rev 4758)
+++ trunk/data/qcsrc/server/cl_player.qc	2008-10-14 19:44:46 UTC (rev 4759)
@@ -906,7 +906,7 @@
 	tokenize_sane(sample);
 	n = stof(argv(1));
 	if(n > 0)
-		sample = strcat(argv(0), ftos(ceil(random() * n)), ".wav"); // randomization
+		sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
 	else
 		sample = strcat(argv(0), ".wav"); // randomization
 

Modified: trunk/data/qcsrc/server/cl_weapons.qc
===================================================================
--- trunk/data/qcsrc/server/cl_weapons.qc	2008-10-14 19:29:02 UTC (rev 4758)
+++ trunk/data/qcsrc/server/cl_weapons.qc	2008-10-14 19:44:46 UTC (rev 4759)
@@ -346,7 +346,7 @@
 	numberof = WEP_LAST - WEP_FIRST; // all but the current one
 	if(g_nixnex_with_laser)
 		numberof = numberof - 1;
-	id = WEP_FIRST + ceil(random() * numberof) - 1;
+	id = WEP_FIRST + floor(random() * numberof);
 
 	if(g_nixnex_with_laser) // skip the laser if needed
 		id = id + 1;

Modified: trunk/data/qcsrc/server/g_world.qc
===================================================================
--- trunk/data/qcsrc/server/g_world.qc	2008-10-14 19:29:02 UTC (rev 4758)
+++ trunk/data/qcsrc/server/g_world.qc	2008-10-14 19:44:46 UTC (rev 4759)
@@ -629,7 +629,7 @@
 	for(i = 0; i <= imax; ++i)
 	{
 		float mapindex;
-		mapindex = mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
+		mapindex = mod(Map_Current + floor(random() * (Map_Count - 1) + 1), Map_Count); // any OTHER map
 		if(Map_Check(mapindex, 1))
 			return mapindex;
 	}
@@ -1399,7 +1399,7 @@
 		result = "";
 
 		// select a random item
-		selected = ceil(random() * (litems - start) + start) - 1;
+		selected = floor(random() * (litems - start) + start);
 
 		// shift this item to the place start
 		for(i = 0; i < start; ++i)
@@ -1747,7 +1747,7 @@
 			return "This map was already suggested.";
 	if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
 	{
-		i = ceil(random() * mapvote_suggestion_ptr) - 1;
+		i = floor(random() * mapvote_suggestion_ptr);
 	}
 	else
 	{
@@ -1797,7 +1797,7 @@
 
 	if(mapvote_suggestion_ptr)
 		for(i = 0; i < 100 && mapvote_count < smax; ++i)
-			MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
+			MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], TRUE);
 
 	for(i = 0; i < 100 && mapvote_count < nmax; ++i)
 		MapVote_AddVotable(GetNextMap(), FALSE);

Modified: trunk/data/qcsrc/server/runematch.qc
===================================================================
--- trunk/data/qcsrc/server/runematch.qc	2008-10-14 19:29:02 UTC (rev 4758)
+++ trunk/data/qcsrc/server/runematch.qc	2008-10-14 19:44:46 UTC (rev 4759)
@@ -228,7 +228,7 @@
 	float num, r;
 	entity spot;
 	num = count_rune_spawnpoints();
-	r = ceil(random()*num);
+	r = floor(random()*num) + 1;
 
 	if(self.owner.classname == "runematch_spawn_point")
 	{
@@ -380,7 +380,7 @@
 		{
 			// avoid pairing runes and curses that match each other
 			do{
-				rand = ceil(random()*ccount);
+				rand = floor(random()*ccount) + 1;
 				curse = FindRune(pl, "curse", rand);
 				tries = tries - 1;
 			}while(RuneMatchesCurse(rune.runes, curse.runes) && tries > 0);
@@ -391,7 +391,7 @@
 		}
 		else
 		{
-				rand = ceil(random()*ccount);
+				rand = floor(random()*ccount) + 1;
 				curse = FindRune(pl, "curse", rand);
 		}
 
@@ -476,7 +476,7 @@
 
 	while(numrunes > 0)
 	{
-		r = ceil(random()*numrunes);
+		r = floor(random()*numrunes) + 1;
 		if(r == 1)
 			rn = RUNE_STRENGTH;
 		else if(r == 2)
@@ -493,7 +493,7 @@
 			tries = 15;
 			// avoid pairing runes and curses that match each other
 			do{
-				r = ceil(random()*numrunes);
+				r = floor(random()*numrunes) + 1;
 				if(r == 1)
 					cs = CURSE_WEAK;
 				else if(r == 2)
@@ -513,7 +513,7 @@
 		}
 		else
 		{
-			r = ceil(random()*numrunes);
+			r = floor(random()*numrunes) + 1;
 			if(r == 1)
 				cs = CURSE_WEAK;
 			else if(r == 2)
@@ -531,7 +531,7 @@
 		if(num <= 1)
 			r = 1;
 		else
-			r = ceil(random()*num*1.25);
+			r = floor(random()*num*1.25) + 1;
 
 		spot = rune_find_spawnpoint(num, r);
 

Modified: trunk/data/qcsrc/server/t_items.qc
===================================================================
--- trunk/data/qcsrc/server/t_items.qc	2008-10-14 19:29:02 UTC (rev 4758)
+++ trunk/data/qcsrc/server/t_items.qc	2008-10-14 19:44:46 UTC (rev 4759)
@@ -898,7 +898,7 @@
 			self.colormap = 0x00;
 	}
 	else
-		self.colormap = ceil(random() * 256) - 1;
+		self.colormap = floor(random() * 256);
 	self.colormap |= 1024; // RENDER_COLORMAPPED
 }
 




More information about the nexuiz-commits mailing list