Fix ModifyPersonalityForNature (#3452)

This commit is contained in:
Martin Griffin 2023-10-23 13:37:40 +01:00 committed by GitHub
parent cd59e055c2
commit 5fd36a8e39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -1896,7 +1896,7 @@ static u32 GeneratePartyHash(const struct Trainer *trainer, u32 i)
void ModifyPersonalityForNature(u32 *personality, u32 newNature)
{
u32 nature = GetNatureFromPersonality(*personality);
s32 diff = abs(nature - newNature);
s32 diff = abs((s32)nature - (s32)newNature);
s32 sign = (nature > newNature) ? 1 : -1;
if (diff > NUM_NATURES / 2)
{

View File

@ -4,6 +4,7 @@
#include "battle_main.h"
#include "data.h"
#include "malloc.h"
#include "random.h"
#include "string_util.h"
#include "constants/item.h"
#include "constants/abilities.h"
@ -119,3 +120,17 @@ TEST("CreateNPCTrainerPartyForTrainer generates different personalities for diff
EXPECT(testParty[0].box.personality != testParty[1].box.personality);
Free(testParty);
}
TEST("ModifyPersonalityForNature can set any nature")
{
u32 personality, nature, j, k;
for (j = 0; j < 64; j++)
{
for (k = 0; k < NUM_NATURES; k++)
{
PARAMETRIZE { personality = Random32(); nature = k; }
}
}
ModifyPersonalityForNature(&personality, nature);
EXPECT_EQ(GetNatureFromPersonality(personality), nature);
}