]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
made lhrandom never return MIN (it already never returned MAX), to fix
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 13 Mar 2009 06:41:13 +0000 (06:41 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 13 Mar 2009 06:41:13 +0000 (06:41 +0000)
the "stone monster" bug from Quake, where occasionally a monster never
even spawns properly because its walkmonster_start_go function had a
nextthink value of exactly 0

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8806 d7cf8633-e32d-0410-b094-e92efae38249

mathlib.h

index 70f7198165d102ec321183f00ce2cb0c6fc8d4c4..c862564e4ceda322e3523f45c9aa7d3cc4f466f0 100644 (file)
--- a/mathlib.h
+++ b/mathlib.h
@@ -49,8 +49,14 @@ extern vec3_t vec3_origin;
 #define max(A,B) ((A) > (B) ? (A) : (B))
 #endif
 
-//#define lhrandom(MIN,MAX) ((rand() & 32767) * (((MAX)-(MIN)) * (1.0f / 32768.0f)) + (MIN))
-#define lhrandom(MIN,MAX) (((double)rand() / ((double)RAND_MAX + 1)) * ((MAX)-(MIN)) + (MIN))
+// LordHavoc: this function never returns exactly MIN or exactly MAX, because
+// of a QuakeC bug in id1 where the line
+// self.nextthink = self.nexthink + random() * 0.5;
+// can result in 0 (self.nextthink is 0 at this point in the code to begin
+// with), causing "stone monsters" that never spawned properly, also MAX is
+// avoided because some people use random() as an index into arrays or for
+// loop conditions, where hitting exactly MAX may be a fatal error
+#define lhrandom(MIN,MAX) (((double)(rand() + 0.5) / ((double)RAND_MAX + 1)) * ((MAX)-(MIN)) + (MIN))
 
 #define invpow(base,number) (log(number) / log(base))