Fix some trainer card link access

This commit is contained in:
GriffinR 2021-10-15 12:05:19 -04:00
parent c02001c46d
commit e3bb257bcf
4 changed files with 50 additions and 42 deletions

View File

@ -44,8 +44,11 @@ struct TrainerCard
/*0x28*/ u16 easyChatProfile[TRAINER_CARD_PROFILE_LENGTH];
/*0x30*/ u8 playerName[PLAYER_NAME_LENGTH + 1];
/*0x38*/ u8 version;
/*0x3A*/ bool16 hasAllFrontierSymbols;
/*0x3C*/ u32 berryCrushPoints;
/*0x3A*/ bool16 linkHasAllFrontierSymbols;
/*0x3C*/ union {
u32 berryCrush;
u32 frontier;
} linkPoints; // This field is used differently by FRLG vs Emerald
/*0x40*/ u32 unionRoomNum;
/*0x44*/ u8 filler[8];
/*0x4C*/ bool8 shouldDrawStickers; // FRLG only
@ -54,7 +57,9 @@ struct TrainerCard
/*0x4F*/ u8 facilityClass;
/*0x50*/ u8 stickers[TRAINER_CARD_STICKER_TYPES]; // FRLG only
/*0x54*/ u16 monSpecies[PARTY_SIZE]; // FRLG only
/*0x60*/ bool16 hasAllSymbols;
// Note: Link players use linkHasAllFrontierSymbols, not the field below,
// which they use for a Wonder Card flag id instead (see CreateTrainerCardInBuffer)
/*0x60*/ bool16 hasAllFrontierSymbols;
/*0x62*/ u16 frontierBP;
};
@ -62,9 +67,9 @@ extern struct TrainerCard gTrainerCards[4];
u32 CountPlayerTrainerStars(void);
u8 GetTrainerCardStars(u8 cardId);
void CopyTrainerCardData(struct TrainerCard *dst, u16 *src, u8 gameVersion);
void CopyTrainerCardData(struct TrainerCard *dst, struct TrainerCard *src, u8 gameVersion);
void ShowPlayerTrainerCard(void (*callback)(void));
void ShowTrainerCardInLink(u8 arg0, void (*callback)(void));
void TrainerCard_GenerateCardForPlayer(struct TrainerCard *);
void TrainerCard_GenerateCardForLinkPlayer(struct TrainerCard *);
#endif // GUARD_TRAINER_CARD_H

View File

@ -372,7 +372,7 @@ static void Task_LinkupExchangeDataWithLeader(u8 taskId)
gLocalLinkPlayerId = GetMultiplayerId();
SaveLinkPlayers(gFieldLinkPlayerCount);
card = (struct TrainerCard *)gBlockSendBuffer;
TrainerCard_GenerateCardForPlayer(card);
TrainerCard_GenerateCardForLinkPlayer(card);
card->monSpecies[0] = GetMonData(&gPlayerParty[gSelectedOrderFromParty[0] - 1], MON_DATA_SPECIES, NULL);
card->monSpecies[1] = GetMonData(&gPlayerParty[gSelectedOrderFromParty[1] - 1], MON_DATA_SPECIES, NULL);
gTasks[taskId].func = Task_LinkupAwaitTrainerCardData;
@ -420,7 +420,7 @@ static void Task_LinkupCheckStatusAfterConfirm(u8 taskId)
gLocalLinkPlayerId = GetMultiplayerId();
SaveLinkPlayers(gFieldLinkPlayerCount);
card = (struct TrainerCard *)gBlockSendBuffer;
TrainerCard_GenerateCardForPlayer(card);
TrainerCard_GenerateCardForLinkPlayer(card);
card->monSpecies[0] = GetMonData(&gPlayerParty[gSelectedOrderFromParty[0] - 1], MON_DATA_SPECIES, NULL);
card->monSpecies[1] = GetMonData(&gPlayerParty[gSelectedOrderFromParty[1] - 1], MON_DATA_SPECIES, NULL);
gTasks[taskId].func = Task_LinkupAwaitTrainerCardData;
@ -518,7 +518,7 @@ static void Task_LinkupAwaitTrainerCardData(u8 taskId)
for (index = 0; index < GetLinkPlayerCount(); index++)
{
CopyTrainerCardData(&gTrainerCards[index], gBlockRecvBuffer[index], gLinkPlayers[index].version);
CopyTrainerCardData(&gTrainerCards[index], (struct TrainerCard *)gBlockRecvBuffer[index], gLinkPlayers[index].version);
}
SetSuppressLinkErrorMessage(FALSE);

View File

@ -110,7 +110,7 @@ static bool8 HasAllFrontierSymbols(void);
static u8 GetRubyTrainerStars(struct TrainerCard*);
static u16 GetCaughtMonsCount(void);
static void SetPlayerCardData(struct TrainerCard*, u8);
static void TrainerCard_GenerateCardForLinkPlayer(struct TrainerCard*);
static void TrainerCard_GenerateCardForPlayer(struct TrainerCard*);
static u8 VersionToCardType(u8);
static void SetDataFromTrainerCard(void);
static void InitGpuRegs(void);
@ -750,29 +750,13 @@ static void SetPlayerCardData(struct TrainerCard *trainerCard, u8 cardType)
}
}
static void TrainerCard_GenerateCardForLinkPlayer(struct TrainerCard *trainerCard)
static void TrainerCard_GenerateCardForPlayer(struct TrainerCard *trainerCard)
{
memset(trainerCard, 0, sizeof(struct TrainerCard));
trainerCard->version = GAME_VERSION;
SetPlayerCardData(trainerCard, CARD_TYPE_EMERALD);
trainerCard->hasAllSymbols = HasAllFrontierSymbols();
trainerCard->frontierBP = gSaveBlock2Ptr->frontier.cardBattlePoints;
if (trainerCard->hasAllSymbols)
trainerCard->stars++;
if (trainerCard->gender == FEMALE)
trainerCard->facilityClass = gLinkPlayerFacilityClasses[(trainerCard->trainerId % NUM_FEMALE_LINK_FACILITY_CLASSES) + NUM_MALE_LINK_FACILITY_CLASSES];
else
trainerCard->facilityClass = gLinkPlayerFacilityClasses[trainerCard->trainerId % NUM_MALE_LINK_FACILITY_CLASSES];
}
void TrainerCard_GenerateCardForPlayer(struct TrainerCard *trainerCard)
{
memset(trainerCard, 0, 0x60);
trainerCard->version = GAME_VERSION;
SetPlayerCardData(trainerCard, CARD_TYPE_EMERALD);
trainerCard->hasAllFrontierSymbols = HasAllFrontierSymbols();
*((u16*)&trainerCard->berryCrushPoints) = gSaveBlock2Ptr->frontier.cardBattlePoints;
trainerCard->frontierBP = gSaveBlock2Ptr->frontier.cardBattlePoints;
if (trainerCard->hasAllFrontierSymbols)
trainerCard->stars++;
@ -782,7 +766,23 @@ void TrainerCard_GenerateCardForPlayer(struct TrainerCard *trainerCard)
trainerCard->facilityClass = gLinkPlayerFacilityClasses[trainerCard->trainerId % NUM_MALE_LINK_FACILITY_CLASSES];
}
void CopyTrainerCardData(struct TrainerCard *dst, u16 *src, u8 gameVersion)
void TrainerCard_GenerateCardForLinkPlayer(struct TrainerCard *trainerCard)
{
memset(trainerCard, 0, 0x60);
trainerCard->version = GAME_VERSION;
SetPlayerCardData(trainerCard, CARD_TYPE_EMERALD);
trainerCard->linkHasAllFrontierSymbols = HasAllFrontierSymbols();
*((u16*)&trainerCard->linkPoints.frontier) = gSaveBlock2Ptr->frontier.cardBattlePoints;
if (trainerCard->linkHasAllFrontierSymbols)
trainerCard->stars++;
if (trainerCard->gender == FEMALE)
trainerCard->facilityClass = gLinkPlayerFacilityClasses[(trainerCard->trainerId % NUM_FEMALE_LINK_FACILITY_CLASSES) + NUM_MALE_LINK_FACILITY_CLASSES];
else
trainerCard->facilityClass = gLinkPlayerFacilityClasses[trainerCard->trainerId % NUM_MALE_LINK_FACILITY_CLASSES];
}
void CopyTrainerCardData(struct TrainerCard *dst, struct TrainerCard *src, u8 gameVersion)
{
memset(dst, 0, sizeof(struct TrainerCard));
dst->version = gameVersion;
@ -797,9 +797,9 @@ void CopyTrainerCardData(struct TrainerCard *dst, u16 *src, u8 gameVersion)
break;
case CARD_TYPE_EMERALD:
memcpy(dst, src, 0x60);
dst->berryCrushPoints = 0;
dst->hasAllSymbols = src[29];
dst->frontierBP = src[30];
dst->linkPoints.frontier = 0;
dst->hasAllFrontierSymbols = src->linkHasAllFrontierSymbols;
dst->frontierBP = *((u16*)&src->linkPoints.frontier);
break;
}
}
@ -1243,13 +1243,13 @@ static void PrintTradesStringOnCard(void)
static void BufferBerryCrushPoints(void)
{
if (sData->cardType == CARD_TYPE_FRLG && sData->trainerCard.berryCrushPoints)
ConvertIntToDecimalStringN(sData->textBerryCrushPts, sData->trainerCard.berryCrushPoints, STR_CONV_MODE_RIGHT_ALIGN, 5);
if (sData->cardType == CARD_TYPE_FRLG && sData->trainerCard.linkPoints.berryCrush)
ConvertIntToDecimalStringN(sData->textBerryCrushPts, sData->trainerCard.linkPoints.berryCrush, STR_CONV_MODE_RIGHT_ALIGN, 5);
}
static void PrintBerryCrushStringOnCard(void)
{
if (sData->cardType == CARD_TYPE_FRLG && sData->trainerCard.berryCrushPoints)
if (sData->cardType == CARD_TYPE_FRLG && sData->trainerCard.linkPoints.berryCrush)
PrintStatOnBackOfCard(4, gText_BerryCrush, sData->textBerryCrushPts, sTrainerCardStatColors);
}
@ -1524,7 +1524,7 @@ static void DrawCardBackStats(void)
FillBgTilemapBufferRect(3, 141, 27, 9, 1, 1, 1);
FillBgTilemapBufferRect(3, 157, 27, 10, 1, 1, 1);
}
if (sData->trainerCard.berryCrushPoints)
if (sData->trainerCard.linkPoints.berryCrush)
{
FillBgTilemapBufferRect(3, 141, 21, 13, 1, 1, 1);
FillBgTilemapBufferRect(3, 157, 21, 14, 1, 1, 1);
@ -1803,7 +1803,7 @@ void ShowPlayerTrainerCard(void (*callback)(void))
sData->isLink = FALSE;
sData->language = GAME_LANGUAGE;
TrainerCard_GenerateCardForLinkPlayer(&sData->trainerCard);
TrainerCard_GenerateCardForPlayer(&sData->trainerCard);
SetMainCallback2(CB2_InitTrainerCard);
}

View File

@ -1532,13 +1532,15 @@ static void Task_ExchangeCards(u8 taskId)
for (i = 0; i < GetLinkPlayerCount(); i++)
{
recvBuff = gBlockRecvBuffer[i];
CopyTrainerCardData(&gTrainerCards[i], recvBuff, gLinkPlayers[i].version);
CopyTrainerCardData(&gTrainerCards[i], (struct TrainerCard *)recvBuff, gLinkPlayers[i].version);
}
if (GetLinkPlayerCount() == 2)
{
// Note: hasAllFrontierSymbols is a re-used field.
// Here it is set by CreateTrainerCardInBuffer.
recvBuff = gBlockRecvBuffer[GetMultiplayerId() ^ 1];
MEventHandleReceivedWonderCard(recvBuff[48]);
MEventHandleReceivedWonderCard(((struct TrainerCard *)recvBuff)->hasAllFrontierSymbols);
}
else
{
@ -1626,13 +1628,14 @@ static void CB2_TransitionToCableClub(void)
static void CreateTrainerCardInBuffer(void *dest, bool32 setWonderCard)
{
u16 *argAsU16Ptr = dest;
struct TrainerCard * card = (struct TrainerCard *)dest;
TrainerCard_GenerateCardForLinkPlayer(card);
TrainerCard_GenerateCardForPlayer((struct TrainerCard *)argAsU16Ptr);
// Below field is re-used, to be read by Task_ExchangeCards
if (setWonderCard)
argAsU16Ptr[48] = GetWonderCardFlagID();
card->hasAllFrontierSymbols = GetWonderCardFlagID();
else
argAsU16Ptr[48] = 0;
card->hasAllFrontierSymbols = 0;
}
static void Task_StartActivity(u8 taskId)