Use macro for randomization with ISO value
This commit is contained in:
@@ -10,6 +10,9 @@ u16 Random2(void);
|
|||||||
|
|
||||||
//Returns a 32-bit pseudorandom number
|
//Returns a 32-bit pseudorandom number
|
||||||
#define Random32() (Random() | (Random() << 16))
|
#define Random32() (Random() | (Random() << 16))
|
||||||
|
|
||||||
|
// The number 1103515245 comes from the example implementation of rand and srand
|
||||||
|
// in the ISO C standard.
|
||||||
#define ISO_RANDOMIZE1(val)(1103515245 * (val) + 24691)
|
#define ISO_RANDOMIZE1(val)(1103515245 * (val) + 24691)
|
||||||
#define ISO_RANDOMIZE2(val)(1103515245 * (val) + 12345)
|
#define ISO_RANDOMIZE2(val)(1103515245 * (val) + 12345)
|
||||||
|
|
||||||
|
|||||||
@@ -559,8 +559,7 @@ static void StartRainSpriteFall(struct Sprite *sprite)
|
|||||||
if (sprite->tRandom == 0)
|
if (sprite->tRandom == 0)
|
||||||
sprite->tRandom = 361;
|
sprite->tRandom = 361;
|
||||||
|
|
||||||
// Standard RNG sequence.
|
rand = ISO_RANDOMIZE2(sprite->tRandom);
|
||||||
rand = sprite->tRandom * 1103515245 + 12345;
|
|
||||||
sprite->tRandom = ((rand & 0x7FFF0000) >> 16) % 600;
|
sprite->tRandom = ((rand & 0x7FFF0000) >> 16) % 600;
|
||||||
|
|
||||||
numFallingFrames = sRainSpriteFallingDurations[gWeatherPtr->isDownpour][0];
|
numFallingFrames = sRainSpriteFallingDurations[gWeatherPtr->isDownpour][0];
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ void SetRandomLotteryNumber(u16 i)
|
|||||||
u32 var = Random();
|
u32 var = Random();
|
||||||
|
|
||||||
while (--i != 0xFFFF)
|
while (--i != 0xFFFF)
|
||||||
var = var * 1103515245 + 12345;
|
var = ISO_RANDOMIZE2(var);
|
||||||
|
|
||||||
SetLotteryNumber(var);
|
SetLotteryNumber(var);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1674,8 +1674,7 @@ static void sub_802BF7C(void)
|
|||||||
|
|
||||||
static int sub_802C098(void)
|
static int sub_802C098(void)
|
||||||
{
|
{
|
||||||
// The number 1103515245 comes from the example implementation of rand and srand
|
gUnknown_02022CFC->unk24 = ISO_RANDOMIZE1(gUnknown_02022CFC->unk24);
|
||||||
gUnknown_02022CFC->unk24 = gUnknown_02022CFC->unk24 * 1103515245 + 24691;
|
|
||||||
return gUnknown_02022CFC->unk24 >> 16;
|
return gUnknown_02022CFC->unk24 >> 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "random.h"
|
#include "random.h"
|
||||||
|
|
||||||
// The number 1103515245 comes from the example implementation of rand and srand
|
|
||||||
// in the ISO C standard.
|
|
||||||
|
|
||||||
EWRAM_DATA static u8 sUnknown = 0;
|
EWRAM_DATA static u8 sUnknown = 0;
|
||||||
EWRAM_DATA static u32 sRandCount = 0;
|
EWRAM_DATA static u32 sRandCount = 0;
|
||||||
|
|
||||||
@@ -13,7 +10,7 @@ u32 gRng2Value;
|
|||||||
|
|
||||||
u16 Random(void)
|
u16 Random(void)
|
||||||
{
|
{
|
||||||
gRngValue = 1103515245 * gRngValue + 24691;
|
gRngValue = ISO_RANDOMIZE1(gRngValue);
|
||||||
sRandCount++;
|
sRandCount++;
|
||||||
return gRngValue >> 16;
|
return gRngValue >> 16;
|
||||||
}
|
}
|
||||||
@@ -31,6 +28,6 @@ void SeedRng2(u16 seed)
|
|||||||
|
|
||||||
u16 Random2(void)
|
u16 Random2(void)
|
||||||
{
|
{
|
||||||
gRng2Value = 1103515245 * gRng2Value + 24691;
|
gRng2Value = ISO_RANDOMIZE1(gRng2Value);
|
||||||
return gRng2Value >> 16;
|
return gRng2Value >> 16;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -434,7 +434,7 @@ void ScriptRandom(void)
|
|||||||
|
|
||||||
if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_LINK)
|
if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_LINK)
|
||||||
{
|
{
|
||||||
gContestRngValue = 1103515245 * gContestRngValue + 24691;
|
gContestRngValue = ISO_RANDOMIZE1(gContestRngValue);
|
||||||
random = gContestRngValue >> 16;
|
random = gContestRngValue >> 16;
|
||||||
scriptPtr = &gSpecialVar_Result;
|
scriptPtr = &gSpecialVar_Result;
|
||||||
}
|
}
|
||||||
@@ -448,7 +448,7 @@ void ScriptRandom(void)
|
|||||||
|
|
||||||
u16 GetContestRand(void)
|
u16 GetContestRand(void)
|
||||||
{
|
{
|
||||||
gContestRngValue = 1103515245 * gContestRngValue + 24691;
|
gContestRngValue = ISO_RANDOMIZE1(gContestRngValue);
|
||||||
return gContestRngValue >> 16;
|
return gContestRngValue >> 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ void UpdateMirageRnd(u16 days)
|
|||||||
s32 rnd = GetMirageRnd();
|
s32 rnd = GetMirageRnd();
|
||||||
while (days)
|
while (days)
|
||||||
{
|
{
|
||||||
rnd = 1103515245 * rnd + 12345;
|
rnd = ISO_RANDOMIZE2(rnd);
|
||||||
days--;
|
days--;
|
||||||
}
|
}
|
||||||
SetMirageRnd(rnd);
|
SetMirageRnd(rnd);
|
||||||
|
|||||||
@@ -1762,7 +1762,7 @@ void sub_810871C(struct Task *task, u8 taskId)
|
|||||||
}
|
}
|
||||||
task->data[11]++;
|
task->data[11]++;
|
||||||
task->data[8] = (task->data[8] + 39) & 0xFF;
|
task->data[8] = (task->data[8] + 39) & 0xFF;
|
||||||
task->data[7] = ((task->data[7] * 1103515245 + 12345) % task->data[5]) + task->data[4];
|
task->data[7] = (ISO_RANDOMIZE2(task->data[7]) % task->data[5]) + task->data[4];
|
||||||
}
|
}
|
||||||
|
|
||||||
void sub_81087C0(struct Sprite *sprite)
|
void sub_81087C0(struct Sprite *sprite)
|
||||||
|
|||||||
@@ -127,12 +127,9 @@ static bool8 CheckFeebas(void)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The number 1103515245 comes from the example implementation of rand and srand
|
|
||||||
// in the ISO C standard.
|
|
||||||
|
|
||||||
static u16 FeebasRandom(void)
|
static u16 FeebasRandom(void)
|
||||||
{
|
{
|
||||||
sFeebasRngValue = (1103515245 * sFeebasRngValue) + 12345;
|
sFeebasRngValue = ISO_RANDOMIZE2(sFeebasRngValue);
|
||||||
return sFeebasRngValue >> 16;
|
return sFeebasRngValue >> 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user