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