mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2024-11-09 23:11:39 +00:00
Fix random() builtin to avoid the monsters-are-statues bug.
This commit is contained in:
parent
78b5a73ee6
commit
0af9796e5a
1 changed files with 10 additions and 4 deletions
|
@ -562,11 +562,17 @@ bug: vanilla could return 1, contrary to the (unchanged) comment just above.
|
|||
*/
|
||||
static void PF_random (void)
|
||||
{
|
||||
float num;
|
||||
//don't return 1 (it would break array[random()*array.length];
|
||||
//don't return 0 either, it would break the self.nextthink = time+random()*foo; lines in walkmonster_start, resulting rarely in statue-monsters.
|
||||
G_FLOAT(OFS_RETURN) = (rand ()&0x7fff) / ((float)0x08000) + (0.5/0x08000);
|
||||
|
||||
num = (rand() & 0x7fff) / ((float)0x8000);
|
||||
|
||||
G_FLOAT(OFS_RETURN) = num;
|
||||
if (qcvm->argc)
|
||||
{
|
||||
if (qcvm->argc == 1) //maximum value
|
||||
G_FLOAT(OFS_RETURN) *= G_FLOAT(OFS_PARM0);
|
||||
else // min and max.
|
||||
G_FLOAT(OFS_RETURN) = G_FLOAT(OFS_PARM0) + G_FLOAT(OFS_RETURN)*(G_FLOAT(OFS_PARM1)-G_FLOAT(OFS_PARM0));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue