Modify "FillPartnerParty" to work with "Everything Customized" (#2889)

This commit is contained in:
Eduardo Quezada D'Ottone 2023-04-08 13:02:47 -04:00 committed by GitHub
commit 1094861667
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 21 deletions

View File

@ -70,6 +70,8 @@ void SpecialStatusesClear(void);
void SetTypeBeforeUsingMove(u16 move, u8 battlerAtk); void SetTypeBeforeUsingMove(u16 move, u8 battlerAtk);
bool32 IsWildMonSmart(void); bool32 IsWildMonSmart(void);
u8 CreateNPCTrainerPartyFromTrainer(struct Pokemon *party, const struct Trainer *trainer, bool32 firstTrainer, u32 battleTypeFlags); u8 CreateNPCTrainerPartyFromTrainer(struct Pokemon *party, const struct Trainer *trainer, bool32 firstTrainer, u32 battleTypeFlags);
void ModifyPersonalityForNature(u32 *personality, u32 newNature);
u32 GeneratePersonalityForGender(u32 gender, u32 species);
extern struct MultiPartnerMenuPokemon gMultiPartnerParty[MULTI_PARTY_SIZE]; extern struct MultiPartnerMenuPokemon gMultiPartnerParty[MULTI_PARTY_SIZE];

View File

@ -120,8 +120,6 @@ static void SpriteCB_UnusedBattleInit_Main(struct Sprite *sprite);
static void TrySpecialEvolution(void); static void TrySpecialEvolution(void);
static u32 Crc32B (const u8 *data, u32 size); static u32 Crc32B (const u8 *data, u32 size);
static u32 GeneratePartyHash(const struct Trainer *trainer, u32 i); static u32 GeneratePartyHash(const struct Trainer *trainer, u32 i);
static void ModifyPersonalityForNature(u32 *personality, u32 newNature);
static u32 GeneratePersonalityForGender(u32 gender, u32 species);
EWRAM_DATA u16 gBattle_BG0_X = 0; EWRAM_DATA u16 gBattle_BG0_X = 0;
EWRAM_DATA u16 gBattle_BG0_Y = 0; EWRAM_DATA u16 gBattle_BG0_Y = 0;
@ -1925,7 +1923,7 @@ static u32 GeneratePartyHash(const struct Trainer *trainer, u32 i)
return Crc32B(buffer, n); return Crc32B(buffer, n);
} }
static void ModifyPersonalityForNature(u32 *personality, u32 newNature) void ModifyPersonalityForNature(u32 *personality, u32 newNature)
{ {
u32 nature = GetNatureFromPersonality(*personality); u32 nature = GetNatureFromPersonality(*personality);
s32 diff = abs(nature - newNature); s32 diff = abs(nature - newNature);
@ -1938,7 +1936,7 @@ static void ModifyPersonalityForNature(u32 *personality, u32 newNature)
*personality -= (diff * sign); *personality -= (diff * sign);
} }
static u32 GeneratePersonalityForGender(u32 gender, u32 species) u32 GeneratePersonalityForGender(u32 gender, u32 species)
{ {
const struct SpeciesInfo *speciesInfo = &gSpeciesInfo[species]; const struct SpeciesInfo *speciesInfo = &gSpeciesInfo[species];
if (gender == MON_MALE) if (gender == MON_MALE)

View File

@ -3103,25 +3103,38 @@ static void FillPartnerParty(u16 trainerId)
case F_TRAINER_PARTY_EVERYTHING_CUSTOMIZED: case F_TRAINER_PARTY_EVERYTHING_CUSTOMIZED:
{ {
const struct TrainerMonCustomized *partyData = gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].party.EverythingCustomized; const struct TrainerMonCustomized *partyData = gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].party.EverythingCustomized;
u32 otIdType = OT_ID_RANDOM_NO_SHINY;
CreateMon(&gPlayerParty[i], partyData[i].species, partyData[i].lvl, 0, TRUE, j, TRUE, otID); if (partyData[i].gender == TRAINER_MON_MALE)
SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &partyData[i].heldItem); j = (j & 0xFFFFFF00) | GeneratePersonalityForGender(MON_MALE, partyData[i].species);
else if (partyData[i].gender == TRAINER_MON_FEMALE)
j = (j & 0xFFFFFF00) | GeneratePersonalityForGender(MON_FEMALE, partyData[i].species);
if (partyData[i].nature != 0)
ModifyPersonalityForNature(&j, partyData[i].nature - 1);
if (partyData[i].isShiny)
{
otIdType = OT_ID_PRESET;
otID = HIHALF(j) ^ LOHALF(j);
}
CreateMon(&gPlayerParty[i + 3], partyData[i].species, partyData[i].lvl, 0, TRUE, j, otIdType, otID);
SetMonData(&gPlayerParty[i + 3], MON_DATA_HELD_ITEM, &partyData[i].heldItem);
// TODO: Figure out a default strategy when moves are not set, to generate a good moveset // TODO: Figure out a default strategy when moves are not set, to generate a good moveset
for (j = 0; j < MAX_MON_MOVES; ++j) for (j = 0; j < MAX_MON_MOVES; ++j)
{ {
SetMonData(&gPlayerParty[i], MON_DATA_MOVE1 + j, &partyData[i].moves[j]); SetMonData(&gPlayerParty[i+3], MON_DATA_MOVE1 + j, &partyData[i].moves[j]);
SetMonData(&gPlayerParty[i], MON_DATA_PP1 + j, &gBattleMoves[partyData[i].moves[j]].pp); SetMonData(&gPlayerParty[i+3], MON_DATA_PP1 + j, &gBattleMoves[partyData[i].moves[j]].pp);
} }
SetMonData(&gPlayerParty[i], MON_DATA_IVS, &(partyData[i].iv)); SetMonData(&gPlayerParty[i+3], MON_DATA_IVS, &(partyData[i].iv));
if (partyData[i].ev != NULL) if (partyData[i].ev != NULL)
{ {
SetMonData(&gPlayerParty[i], MON_DATA_HP_EV, &(partyData[i].ev[0])); SetMonData(&gPlayerParty[i+3], MON_DATA_HP_EV, &(partyData[i].ev[0]));
SetMonData(&gPlayerParty[i], MON_DATA_ATK_EV, &(partyData[i].ev[1])); SetMonData(&gPlayerParty[i+3], MON_DATA_ATK_EV, &(partyData[i].ev[1]));
SetMonData(&gPlayerParty[i], MON_DATA_DEF_EV, &(partyData[i].ev[2])); SetMonData(&gPlayerParty[i+3], MON_DATA_DEF_EV, &(partyData[i].ev[2]));
SetMonData(&gPlayerParty[i], MON_DATA_SPATK_EV, &(partyData[i].ev[3])); SetMonData(&gPlayerParty[i+3], MON_DATA_SPATK_EV, &(partyData[i].ev[3]));
SetMonData(&gPlayerParty[i], MON_DATA_SPDEF_EV, &(partyData[i].ev[4])); SetMonData(&gPlayerParty[i+3], MON_DATA_SPDEF_EV, &(partyData[i].ev[4]));
SetMonData(&gPlayerParty[i], MON_DATA_SPEED_EV, &(partyData[i].ev[5])); SetMonData(&gPlayerParty[i+3], MON_DATA_SPEED_EV, &(partyData[i].ev[5]));
} }
if (partyData[i].ability != ABILITY_NONE) if (partyData[i].ability != ABILITY_NONE)
{ {
@ -3133,19 +3146,19 @@ static void FillPartnerParty(u16 trainerId)
break; break;
} }
if (j < maxAbilities) if (j < maxAbilities)
SetMonData(&gPlayerParty[i], MON_DATA_ABILITY_NUM, &j); SetMonData(&gPlayerParty[i+3], MON_DATA_ABILITY_NUM, &j);
} }
SetMonData(&gPlayerParty[i], MON_DATA_FRIENDSHIP, &(partyData[i].friendship)); SetMonData(&gPlayerParty[i+3], MON_DATA_FRIENDSHIP, &(partyData[i].friendship));
if (partyData[i].ball != ITEM_NONE) if (partyData[i].ball != ITEM_NONE)
{ {
ball = partyData[i].ball; ball = partyData[i].ball;
SetMonData(&gPlayerParty[i], MON_DATA_POKEBALL, &ball); SetMonData(&gPlayerParty[i+3], MON_DATA_POKEBALL, &ball);
} }
if (partyData[i].nickname != NULL) if (partyData[i].nickname != NULL)
{ {
SetMonData(&gPlayerParty[i], MON_DATA_NICKNAME, partyData[i].nickname); SetMonData(&gPlayerParty[i+3], MON_DATA_NICKNAME, partyData[i].nickname);
} }
CalculateMonStats(&gPlayerParty[i]); CalculateMonStats(&gPlayerParty[i+3]);
} }
} }

View File

@ -81,7 +81,7 @@ TEST("CreateNPCTrainerPartyForTrainer generates customized Pokémon")
EXPECT(GetMonData(&testParty[0], MON_DATA_HELD_ITEM, 0) == ITEM_ASSAULT_VEST); EXPECT(GetMonData(&testParty[0], MON_DATA_HELD_ITEM, 0) == ITEM_ASSAULT_VEST);
EXPECT(GetMonData(&testParty[1], MON_DATA_HELD_ITEM, 0) == ITEM_NONE); EXPECT(GetMonData(&testParty[1], MON_DATA_HELD_ITEM, 0) == ITEM_NONE);
EXPECT(GetMonData(&testParty[0], MON_DATA_HP_IV, 0) == 25); EXPECT(GetMonData(&testParty[0], MON_DATA_HP_IV, 0) == 25);
EXPECT(GetMonData(&testParty[0], MON_DATA_ATK_IV, 0) == 26); EXPECT(GetMonData(&testParty[0], MON_DATA_ATK_IV, 0) == 26);
EXPECT(GetMonData(&testParty[0], MON_DATA_DEF_IV, 0) == 27); EXPECT(GetMonData(&testParty[0], MON_DATA_DEF_IV, 0) == 27);