Don't use SeedRng some places where it isn't necessary (#6156)
This commit is contained in:
parent
37dd57b1b5
commit
14178edfe3
@ -30,7 +30,7 @@ struct Sfc32State {
|
||||
|
||||
typedef struct Sfc32State rng_value_t;
|
||||
|
||||
#define RNG_VALUE_EMPTY {}
|
||||
#define RNG_VALUE_EMPTY {0}
|
||||
|
||||
// Calling this function directly is discouraged.
|
||||
// Use LocalRandom() instead.
|
||||
@ -43,9 +43,14 @@ static inline u32 _SFC32_Next(struct Sfc32State *state)
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline u32 LocalRandom32(rng_value_t *val)
|
||||
{
|
||||
return _SFC32_Next(val);
|
||||
}
|
||||
|
||||
static inline u16 LocalRandom(rng_value_t *val)
|
||||
{
|
||||
return _SFC32_Next(val) >> 16;
|
||||
return LocalRandom32(val) >> 16;
|
||||
}
|
||||
|
||||
u32 Random32(void);
|
||||
|
||||
@ -983,8 +983,10 @@ static void SetPickupItem(void)
|
||||
{
|
||||
int i;
|
||||
int itemIndex;
|
||||
int rand;
|
||||
int randVal;
|
||||
u32 randSeedIndex, randSeed;
|
||||
u8 id;
|
||||
rng_value_t rand;
|
||||
u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode;
|
||||
u32 floor = gSaveBlock2Ptr->frontier.curChallengeBattleNum;
|
||||
u32 round = (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / FRONTIER_STAGES_PER_CHALLENGE) % TOTAL_PYRAMID_ROUNDS;
|
||||
@ -994,15 +996,19 @@ static void SetPickupItem(void)
|
||||
|
||||
id = GetPyramidFloorTemplateId();
|
||||
itemIndex = (gSpecialVar_LastTalked - sPyramidFloorTemplates[id].numTrainers) - 1;
|
||||
rand = gSaveBlock2Ptr->frontier.pyramidRandoms[itemIndex / 2];
|
||||
SeedRng2(rand);
|
||||
randSeedIndex = (itemIndex & 1) * 2;
|
||||
randSeed = (u32)gSaveBlock2Ptr->frontier.pyramidRandoms[randSeedIndex + 1] << 16;
|
||||
randSeed |= gSaveBlock2Ptr->frontier.pyramidRandoms[randSeedIndex];
|
||||
rand = LocalRandomSeed(randSeed);
|
||||
|
||||
for (i = 0; i < itemIndex + 1; i++)
|
||||
rand = Random2() % 100;
|
||||
for (i = 0; i < itemIndex / 2; i++)
|
||||
LocalRandom(&rand);
|
||||
|
||||
randVal = LocalRandom(&rand) % 100;
|
||||
|
||||
for (i = sPickupItemOffsets[floor]; i < ARRAY_COUNT(sPickupItemSlots); i++)
|
||||
{
|
||||
if (rand < sPickupItemSlots[i][0])
|
||||
if (randVal < sPickupItemSlots[i][0])
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@ -212,7 +212,6 @@ static void ShowContestPainting(void)
|
||||
gMain.state++;
|
||||
break;
|
||||
case 2:
|
||||
SeedRng(gMain.vblankCounter1);
|
||||
InitKeys();
|
||||
InitContestPaintingWindow();
|
||||
gMain.state++;
|
||||
@ -595,4 +594,3 @@ static void CreateContestPaintingPicture(u8 contestWinnerId, bool8 isForArtist)
|
||||
InitPaintingMonOamData(contestWinnerId);
|
||||
LoadContestPaintingFrame(contestWinnerId, isForArtist);
|
||||
}
|
||||
|
||||
|
||||
@ -549,14 +549,15 @@ static void _TriggerPendingDaycareEgg(struct DayCare *daycare)
|
||||
{
|
||||
s32 parent;
|
||||
s32 natureTries = 0;
|
||||
rng_value_t personalityRand;
|
||||
|
||||
SeedRng2(gMain.vblankCounter2);
|
||||
personalityRand = LocalRandomSeed(gMain.vblankCounter2);
|
||||
parent = GetParentToInheritNature(daycare);
|
||||
|
||||
// don't inherit nature
|
||||
if (parent < 0)
|
||||
{
|
||||
daycare->offspringPersonality = (Random2() << 16) | ((Random() % 0xfffe) + 1);
|
||||
daycare->offspringPersonality = (LocalRandom(&personalityRand) << 16) | ((Random() % 0xfffe) + 1);
|
||||
}
|
||||
// inherit nature
|
||||
else
|
||||
@ -566,7 +567,7 @@ static void _TriggerPendingDaycareEgg(struct DayCare *daycare)
|
||||
|
||||
do
|
||||
{
|
||||
personality = (Random2() << 16) | (Random());
|
||||
personality = (LocalRandom(&personalityRand) << 16) | (Random());
|
||||
if (wantedNature == GetNatureFromPersonality(personality) && personality != 0)
|
||||
break; // found a personality with the same nature
|
||||
|
||||
@ -1566,4 +1567,3 @@ static u8 ModifyBreedingScoreForOvalCharm(u8 score)
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
|
||||
@ -770,14 +770,12 @@ static void ReceiveDaycareMailData(struct RecordMixingDaycareMail *records, size
|
||||
bool8 canHoldItem[MAX_LINK_PLAYERS][DAYCARE_MON_COUNT];
|
||||
u8 idxs[MAX_LINK_PLAYERS][2];
|
||||
u8 numDaycareCanHold;
|
||||
u16 oldSeed;
|
||||
bool32 anyRS;
|
||||
rng_value_t localRngState = LocalRandomSeed(gLinkPlayers[0].trainerId);
|
||||
|
||||
// Seed RNG to the first player's trainer id so that
|
||||
// every player has the same random swap occur
|
||||
// (see the other use of Random2 in this function)
|
||||
oldSeed = Random2();
|
||||
SeedRng2(gLinkPlayers[0].trainerId);
|
||||
linkPlayerCount = GetLinkPlayerCount();
|
||||
for (i = 0; i < MAX_LINK_PLAYERS; i++)
|
||||
{
|
||||
@ -907,7 +905,7 @@ static void ReceiveDaycareMailData(struct RecordMixingDaycareMail *records, size
|
||||
itemId2 = GetDaycareMailItemId(&mixMail->mail[1]);
|
||||
|
||||
if ((!itemId1 && !itemId2) || (itemId1 && itemId2))
|
||||
idxs[j][DAYCARE_SLOT] = Random2() % 2;
|
||||
idxs[j][DAYCARE_SLOT] = LocalRandom32(&localRngState) % 2;
|
||||
else if (itemId1 && !itemId2)
|
||||
idxs[j][DAYCARE_SLOT] = 0;
|
||||
else if (!itemId1 && itemId2)
|
||||
@ -958,7 +956,6 @@ static void ReceiveDaycareMailData(struct RecordMixingDaycareMail *records, size
|
||||
mixMail = (void *)records + multiplayerId * recordSize;
|
||||
memcpy(&gSaveBlock1Ptr->daycare.mons[0].mail, &mixMail->mail[0], sizeof(struct DaycareMail));
|
||||
memcpy(&gSaveBlock1Ptr->daycare.mons[1].mail, &mixMail->mail[1], sizeof(struct DaycareMail));
|
||||
SeedRng(oldSeed);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user