Removed uses of F_TRAINER_PARTY_EVERYTHING_CUSTOMIZED

This commit is contained in:
Eduardo Quezada 2023-07-05 18:22:48 -04:00
parent 0b3c7b7d3b
commit 2f9e0ecd9f
8 changed files with 111 additions and 155 deletions

View File

@ -371,11 +371,6 @@
#define F_TRAINER_FEMALE (1 << 7) #define F_TRAINER_FEMALE (1 << 7)
// All trainer parties specify the IV, level, and species for each Pokémon in the
// party. Some trainer parties also specify held items and custom moves for each
// Pokémon.
#define F_TRAINER_PARTY_EVERYTHING_CUSTOMIZED (1 << 3)
// Trainer party defines // Trainer party defines
#define TRAINER_MON_MALE 1 #define TRAINER_MON_MALE 1
#define TRAINER_MON_FEMALE 2 #define TRAINER_MON_FEMALE 2

View File

@ -52,7 +52,7 @@ struct TrainerMonCustomized
bool8 isShiny : 1; bool8 isShiny : 1;
}; };
#define EVERYTHING_CUSTOMIZED(party) { .EverythingCustomized = party}, .partySize = ARRAY_COUNT(party), .partyFlags = F_TRAINER_PARTY_EVERYTHING_CUSTOMIZED #define EVERYTHING_CUSTOMIZED(party) { .EverythingCustomized = party}, .partySize = ARRAY_COUNT(party)
union TrainerMonPtr union TrainerMonPtr
{ {
@ -69,7 +69,7 @@ struct Trainer
/*0x12*/ u8 trainerPic; /*0x12*/ u8 trainerPic;
/*0x13*/ u8 trainerName[TRAINER_NAME_LENGTH + 1]; /*0x13*/ u8 trainerName[TRAINER_NAME_LENGTH + 1];
/*0x1E*/ bool8 doubleBattle:1; /*0x1E*/ bool8 doubleBattle:1;
u8 partyFlags:7; u8 padding:7;
/*0x1F*/ u8 partySize; /*0x1F*/ u8 partySize;
}; };

View File

@ -1883,13 +1883,8 @@ 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)
{ {
const u8 *buffer; const u8 *buffer = (const u8 *) &trainer->party.EverythingCustomized[i];
u32 n; u32 n = sizeof(*trainer->party.EverythingCustomized);
if (trainer->partyFlags == F_TRAINER_PARTY_EVERYTHING_CUSTOMIZED)
{
buffer = (const u8 *) &trainer->party.EverythingCustomized[i];
n = sizeof(*trainer->party.EverythingCustomized);
}
return Crc32B(buffer, n); return Crc32B(buffer, n);
} }
@ -1967,6 +1962,10 @@ u8 CreateNPCTrainerPartyFromTrainer(struct Pokemon *party, const struct Trainer
for (i = 0; i < monsCount; i++) for (i = 0; i < monsCount; i++)
{ {
u32 personalityHash = GeneratePartyHash(trainer, i); u32 personalityHash = GeneratePartyHash(trainer, i);
const struct TrainerMonCustomized *partyData = trainer->party.EverythingCustomized;
u32 otIdType = OT_ID_RANDOM_NO_SHINY;
u32 fixedOtId = 0;
if (trainer->doubleBattle == TRUE) if (trainer->doubleBattle == TRUE)
personalityValue = 0x80; personalityValue = 0x80;
else if (trainer->encounterMusic_gender & F_TRAINER_FEMALE) else if (trainer->encounterMusic_gender & F_TRAINER_FEMALE)
@ -1975,63 +1974,54 @@ u8 CreateNPCTrainerPartyFromTrainer(struct Pokemon *party, const struct Trainer
personalityValue = 0x88; // Use personality more likely to result in a male Pokémon personalityValue = 0x88; // Use personality more likely to result in a male Pokémon
personalityValue += personalityHash << 8; personalityValue += personalityHash << 8;
switch (trainer->partyFlags) if (partyData[i].gender == TRAINER_MON_MALE)
personalityValue = (personalityValue & 0xFFFFFF00) | GeneratePersonalityForGender(MON_MALE, partyData[i].species);
else if (partyData[i].gender == TRAINER_MON_FEMALE)
personalityValue = (personalityValue & 0xFFFFFF00) | GeneratePersonalityForGender(MON_FEMALE, partyData[i].species);
if (partyData[i].nature != 0)
ModifyPersonalityForNature(&personalityValue, partyData[i].nature - 1);
if (partyData[i].isShiny)
{ {
case F_TRAINER_PARTY_EVERYTHING_CUSTOMIZED: otIdType = OT_ID_PRESET;
{ fixedOtId = HIHALF(personalityValue) ^ LOHALF(personalityValue);
const struct TrainerMonCustomized *partyData = trainer->party.EverythingCustomized; }
u32 otIdType = OT_ID_RANDOM_NO_SHINY; CreateMon(&party[i], partyData[i].species, partyData[i].lvl, 0, TRUE, personalityValue, otIdType, fixedOtId);
u32 fixedOtId = 0; SetMonData(&party[i], MON_DATA_HELD_ITEM, &partyData[i].heldItem);
if (partyData[i].gender == TRAINER_MON_MALE)
personalityValue = (personalityValue & 0xFFFFFF00) | GeneratePersonalityForGender(MON_MALE, partyData[i].species);
else if (partyData[i].gender == TRAINER_MON_FEMALE)
personalityValue = (personalityValue & 0xFFFFFF00) | GeneratePersonalityForGender(MON_FEMALE, partyData[i].species);
if (partyData[i].nature != 0)
ModifyPersonalityForNature(&personalityValue, partyData[i].nature - 1);
if (partyData[i].isShiny)
{
otIdType = OT_ID_PRESET;
fixedOtId = HIHALF(personalityValue) ^ LOHALF(personalityValue);
}
CreateMon(&party[i], partyData[i].species, partyData[i].lvl, 0, TRUE, personalityValue, otIdType, fixedOtId);
SetMonData(&party[i], MON_DATA_HELD_ITEM, &partyData[i].heldItem);
CustomTrainerPartyAssignMoves(&party[i], &partyData[i]); CustomTrainerPartyAssignMoves(&party[i], &partyData[i]);
SetMonData(&party[i], MON_DATA_IVS, &(partyData[i].iv)); SetMonData(&party[i], MON_DATA_IVS, &(partyData[i].iv));
if (partyData[i].ev != NULL) if (partyData[i].ev != NULL)
{ {
SetMonData(&party[i], MON_DATA_HP_EV, &(partyData[i].ev[0])); SetMonData(&party[i], MON_DATA_HP_EV, &(partyData[i].ev[0]));
SetMonData(&party[i], MON_DATA_ATK_EV, &(partyData[i].ev[1])); SetMonData(&party[i], MON_DATA_ATK_EV, &(partyData[i].ev[1]));
SetMonData(&party[i], MON_DATA_DEF_EV, &(partyData[i].ev[2])); SetMonData(&party[i], MON_DATA_DEF_EV, &(partyData[i].ev[2]));
SetMonData(&party[i], MON_DATA_SPATK_EV, &(partyData[i].ev[3])); SetMonData(&party[i], MON_DATA_SPATK_EV, &(partyData[i].ev[3]));
SetMonData(&party[i], MON_DATA_SPDEF_EV, &(partyData[i].ev[4])); SetMonData(&party[i], MON_DATA_SPDEF_EV, &(partyData[i].ev[4]));
SetMonData(&party[i], MON_DATA_SPEED_EV, &(partyData[i].ev[5])); SetMonData(&party[i], MON_DATA_SPEED_EV, &(partyData[i].ev[5]));
}
if (partyData[i].ability != ABILITY_NONE)
{
const struct SpeciesInfo *speciesInfo = &gSpeciesInfo[partyData[i].species];
u32 maxAbilities = ARRAY_COUNT(speciesInfo->abilities);
for (j = 0; j < maxAbilities; ++j)
{
if (speciesInfo->abilities[j] == partyData[i].ability)
break;
}
if (j < maxAbilities)
SetMonData(&party[i], MON_DATA_ABILITY_NUM, &j);
}
SetMonData(&party[i], MON_DATA_FRIENDSHIP, &(partyData[i].friendship));
if (partyData[i].ball != ITEM_NONE)
{
ball = partyData[i].ball;
SetMonData(&party[i], MON_DATA_POKEBALL, &ball);
}
if (partyData[i].nickname != NULL)
{
SetMonData(&party[i], MON_DATA_NICKNAME, partyData[i].nickname);
}
CalculateMonStats(&party[i]);
} }
if (partyData[i].ability != ABILITY_NONE)
{
const struct SpeciesInfo *speciesInfo = &gSpeciesInfo[partyData[i].species];
u32 maxAbilities = ARRAY_COUNT(speciesInfo->abilities);
for (j = 0; j < maxAbilities; ++j)
{
if (speciesInfo->abilities[j] == partyData[i].ability)
break;
}
if (j < maxAbilities)
SetMonData(&party[i], MON_DATA_ABILITY_NUM, &j);
} }
SetMonData(&party[i], MON_DATA_FRIENDSHIP, &(partyData[i].friendship));
if (partyData[i].ball != ITEM_NONE)
{
ball = partyData[i].ball;
SetMonData(&party[i], MON_DATA_POKEBALL, &ball);
}
if (partyData[i].nickname != NULL)
{
SetMonData(&party[i], MON_DATA_NICKNAME, partyData[i].nickname);
}
CalculateMonStats(&party[i]);
#if B_TRAINER_CLASS_POKE_BALLS >= GEN_7 #if B_TRAINER_CLASS_POKE_BALLS >= GEN_7
if (ball == -1) if (ball == -1)

View File

@ -7337,15 +7337,8 @@ static u32 GetTrainerMoneyToGive(u16 trainerId)
} }
else else
{ {
switch (gTrainers[trainerId].partyFlags) const struct TrainerMonCustomized *party = gTrainers[trainerId].party.EverythingCustomized;
{ lastMonLevel = party[gTrainers[trainerId].partySize - 1].lvl;
case F_TRAINER_PARTY_EVERYTHING_CUSTOMIZED:
{
const struct TrainerMonCustomized *party = gTrainers[trainerId].party.EverythingCustomized;
lastMonLevel = party[gTrainers[trainerId].partySize - 1].lvl;
}
break;
}
for (; gTrainerMoneyTable[i].classId != 0xFF; i++) for (; gTrainerMoneyTable[i].classId != 0xFF; i++)
{ {

View File

@ -758,23 +758,16 @@ static u8 GetSumOfEnemyPartyLevel(u16 opponentId, u8 numMons)
u8 i; u8 i;
u8 sum; u8 sum;
u32 count = numMons; u32 count = numMons;
const struct TrainerMonCustomized *party;
if (gTrainers[opponentId].partySize < count) if (gTrainers[opponentId].partySize < count)
count = gTrainers[opponentId].partySize; count = gTrainers[opponentId].partySize;
sum = 0; sum = 0;
switch (gTrainers[opponentId].partyFlags) party = gTrainers[opponentId].party.EverythingCustomized;
{ for (i = 0; i < count; i++)
case F_TRAINER_PARTY_EVERYTHING_CUSTOMIZED: sum += party[i].lvl;
{
const struct TrainerMonCustomized *party;
party = gTrainers[opponentId].party.EverythingCustomized;
for (i = 0; i < count; i++)
sum += party[i].lvl;
}
break;
}
return sum; return sum;
} }

View File

@ -3049,74 +3049,67 @@ static void FillPartnerParty(u16 trainerId)
for (i = 0; i < 3 && i < gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].partySize; i++) for (i = 0; i < 3 && i < gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].partySize; i++)
{ {
const struct TrainerMonCustomized *partyData = gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].party.EverythingCustomized;
u32 otIdType = OT_ID_RANDOM_NO_SHINY;
do do
{ {
j = Random32(); j = Random32();
} while (IsShinyOtIdPersonality(otID, j)); } while (IsShinyOtIdPersonality(otID, j));
switch (gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].partyFlags) if (partyData[i].gender == TRAINER_MON_MALE)
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)
{ {
case F_TRAINER_PARTY_EVERYTHING_CUSTOMIZED: 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
for (j = 0; j < MAX_MON_MOVES; ++j)
{ {
const struct TrainerMonCustomized *partyData = gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].party.EverythingCustomized; SetMonData(&gPlayerParty[i+3], MON_DATA_MOVE1 + j, &partyData[i].moves[j]);
u32 otIdType = OT_ID_RANDOM_NO_SHINY; SetMonData(&gPlayerParty[i+3], MON_DATA_PP1 + j, &gBattleMoves[partyData[i].moves[j]].pp);
if (partyData[i].gender == TRAINER_MON_MALE)
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
for (j = 0; j < MAX_MON_MOVES; ++j)
{
SetMonData(&gPlayerParty[i+3], MON_DATA_MOVE1 + j, &partyData[i].moves[j]);
SetMonData(&gPlayerParty[i+3], MON_DATA_PP1 + j, &gBattleMoves[partyData[i].moves[j]].pp);
}
SetMonData(&gPlayerParty[i+3], MON_DATA_IVS, &(partyData[i].iv));
if (partyData[i].ev != NULL)
{
SetMonData(&gPlayerParty[i+3], MON_DATA_HP_EV, &(partyData[i].ev[0]));
SetMonData(&gPlayerParty[i+3], MON_DATA_ATK_EV, &(partyData[i].ev[1]));
SetMonData(&gPlayerParty[i+3], MON_DATA_DEF_EV, &(partyData[i].ev[2]));
SetMonData(&gPlayerParty[i+3], MON_DATA_SPATK_EV, &(partyData[i].ev[3]));
SetMonData(&gPlayerParty[i+3], MON_DATA_SPDEF_EV, &(partyData[i].ev[4]));
SetMonData(&gPlayerParty[i+3], MON_DATA_SPEED_EV, &(partyData[i].ev[5]));
}
if (partyData[i].ability != ABILITY_NONE)
{
const struct SpeciesInfo *speciesInfo = &gSpeciesInfo[partyData[i].species];
u32 maxAbilities = ARRAY_COUNT(speciesInfo->abilities);
for (j = 0; j < maxAbilities; ++j)
{
if (speciesInfo->abilities[j] == partyData[i].ability)
break;
}
if (j < maxAbilities)
SetMonData(&gPlayerParty[i+3], MON_DATA_ABILITY_NUM, &j);
}
SetMonData(&gPlayerParty[i+3], MON_DATA_FRIENDSHIP, &(partyData[i].friendship));
if (partyData[i].ball != ITEM_NONE)
{
ball = partyData[i].ball;
SetMonData(&gPlayerParty[i+3], MON_DATA_POKEBALL, &ball);
}
if (partyData[i].nickname != NULL)
{
SetMonData(&gPlayerParty[i+3], MON_DATA_NICKNAME, partyData[i].nickname);
}
CalculateMonStats(&gPlayerParty[i+3]);
} }
SetMonData(&gPlayerParty[i+3], MON_DATA_IVS, &(partyData[i].iv));
if (partyData[i].ev != NULL)
{
SetMonData(&gPlayerParty[i+3], MON_DATA_HP_EV, &(partyData[i].ev[0]));
SetMonData(&gPlayerParty[i+3], MON_DATA_ATK_EV, &(partyData[i].ev[1]));
SetMonData(&gPlayerParty[i+3], MON_DATA_DEF_EV, &(partyData[i].ev[2]));
SetMonData(&gPlayerParty[i+3], MON_DATA_SPATK_EV, &(partyData[i].ev[3]));
SetMonData(&gPlayerParty[i+3], MON_DATA_SPDEF_EV, &(partyData[i].ev[4]));
SetMonData(&gPlayerParty[i+3], MON_DATA_SPEED_EV, &(partyData[i].ev[5]));
} }
if (partyData[i].ability != ABILITY_NONE)
{
const struct SpeciesInfo *speciesInfo = &gSpeciesInfo[partyData[i].species];
u32 maxAbilities = ARRAY_COUNT(speciesInfo->abilities);
for (j = 0; j < maxAbilities; ++j)
{
if (speciesInfo->abilities[j] == partyData[i].ability)
break;
}
if (j < maxAbilities)
SetMonData(&gPlayerParty[i+3], MON_DATA_ABILITY_NUM, &j);
}
SetMonData(&gPlayerParty[i+3], MON_DATA_FRIENDSHIP, &(partyData[i].friendship));
if (partyData[i].ball != ITEM_NONE)
{
ball = partyData[i].ball;
SetMonData(&gPlayerParty[i+3], MON_DATA_POKEBALL, &ball);
}
if (partyData[i].nickname != NULL)
{
SetMonData(&gPlayerParty[i+3], MON_DATA_NICKNAME, partyData[i].nickname);
}
CalculateMonStats(&gPlayerParty[i+3]);
StringCopy(trainerName, gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].trainerName); StringCopy(trainerName, gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].trainerName);
SetMonData(&gPlayerParty[i + 3], MON_DATA_OT_NAME, trainerName); SetMonData(&gPlayerParty[i + 3], MON_DATA_OT_NAME, trainerName);

View File

@ -1,7 +1,6 @@
const struct Trainer gTrainers[] = { const struct Trainer gTrainers[] = {
[TRAINER_NONE] = [TRAINER_NONE] =
{ {
.partyFlags = 0,
.trainerClass = TRAINER_CLASS_PKMN_TRAINER_1, .trainerClass = TRAINER_CLASS_PKMN_TRAINER_1,
.encounterMusic_gender = TRAINER_ENCOUNTER_MUSIC_MALE, .encounterMusic_gender = TRAINER_ENCOUNTER_MUSIC_MALE,
.trainerPic = TRAINER_PIC_HIKER, .trainerPic = TRAINER_PIC_HIKER,

View File

@ -1796,14 +1796,7 @@ static void PopulateSpeciesFromTrainerParty(int matchCallId, u8 *destStr)
trainerId = GetLastBeatenRematchTrainerId(sMatchCallTrainers[matchCallId].trainerId); trainerId = GetLastBeatenRematchTrainerId(sMatchCallTrainers[matchCallId].trainerId);
party = gTrainers[trainerId].party; party = gTrainers[trainerId].party;
monId = Random() % gTrainers[trainerId].partySize; monId = Random() % gTrainers[trainerId].partySize;
speciesName = gSpeciesNames[party.EverythingCustomized[monId].species];
switch (gTrainers[trainerId].partyFlags)
{
default:
case F_TRAINER_PARTY_EVERYTHING_CUSTOMIZED:
speciesName = gSpeciesNames[party.EverythingCustomized[monId].species];
break;
}
StringCopy(destStr, speciesName); StringCopy(destStr, speciesName);
} }