Clean up mevent2

This commit is contained in:
GriffinR 2021-10-17 01:35:26 -04:00
parent c7d550e96c
commit 5f9069628d
8 changed files with 44 additions and 33 deletions

View file

@ -92,6 +92,8 @@
#define WONDER_CARD_BODY_TEXT_LINES 4
#define WONDER_NEWS_BODY_TEXT_LINES 10
#define MAX_STAMP_CARD_STAMPS 7
#define MALE 0
#define FEMALE 1
#define GENDER_COUNT 2

View file

@ -13,11 +13,13 @@
#define CARD_STAT_NUM_STAMPS 3
#define CARD_STAT_MAX_STAMPS 4
// Values for the type field of Wonder Card
#define CARD_TYPE_GIFT 0 // Normal "Wonder Card"
#define CARD_TYPE_STAMP 1 // "Stamp Card"
#define CARD_TYPE_LINK_STAT 2 // Referred to as the "Battle Card", shows battle and trade stats
#define CARD_TYPE_COUNT 3
// Values for the sendType field of Wonder Card/News
#define SEND_TYPE_DISALLOWED 0
#define SEND_TYPE_ALLOWED 1
#define SEND_TYPE_ALLOWED_ALWAYS 2
@ -27,10 +29,9 @@
#define HAS_SAME_CARD 1
#define HAS_DIFF_CARD 2
// The number of battles needed to be recorded on a Battle Card to win a prize
#define REQUIRED_CARD_BATTLES 3
#define MAX_CARD_STAMPS 7
// Stamps are 32 bits. The first 16 bits are the species
// and the second 16 bits are a number (presumably an ID of some kind)
#define STAMP_SPECIES 0

View file

@ -847,7 +847,7 @@ struct WonderNewsMetadata
struct WonderNews
{
u16 unk_00;
u16 id;
u8 sendType; // SEND_TYPE_*
u8 bgType;
u8 titleText[WONDER_NEWS_TEXT_LENGTH];
@ -876,7 +876,7 @@ struct WonderCardMetadata
u16 battlesLost;
u16 numTrades;
u16 iconSpecies;
u16 stampData[2][7];
u16 stampData[2][MAX_STAMP_CARD_STAMPS]; // First element is STAMP_SPECIES, second is STAMP_ID
};
struct MysteryGiftSave

View file

@ -6,11 +6,13 @@
struct MysteryGiftLinkGameData
{
u32 unk_00;
u16 unk_04;
u32 unk_08;
u16 unk_0C;
u32 unk_10;
// It's possible these first 5 fields had some other meaningful purpose,
// but they are only ever set when creating this data and read to validate it.
u32 validationVar;
u16 validationFlag1;
u32 validationFlag2;
u16 validationGiftType1;
u32 validationGiftType2;
u16 flagId;
u16 questionnaireWords[NUM_QUESTIONNAIRE_WORDS];
struct WonderCardMetadata cardMetadata;
@ -50,6 +52,6 @@ u16 MysteryGift_GetCardStatFromLinkData(const struct MysteryGiftLinkGameData *da
u16 MysteryGift_GetCardStat(u32 stat);
void MysteryGift_DisableStats(void);
bool32 MysteryGift_TryEnableStatsByFlagId(u16 flagId);
void TryIncrementMysteryGiftStat(u32 stat, u32 trainerId);
void MysteryGift_TryIncrementStat(u32 stat, u32 trainerId);
#endif //GUARD_MEVENT_H

View file

@ -1004,10 +1004,10 @@ void CB2_ReturnFromCableClubBattle(void)
switch (gBattleOutcome)
{
case B_OUTCOME_WON:
TryIncrementMysteryGiftStat(CARD_STAT_BATTLES_WON, gLinkPlayers[GetMultiplayerId() ^ 1].trainerId);
MysteryGift_TryIncrementStat(CARD_STAT_BATTLES_WON, gLinkPlayers[GetMultiplayerId() ^ 1].trainerId);
break;
case B_OUTCOME_LOST:
TryIncrementMysteryGiftStat(CARD_STAT_BATTLES_LOST, gLinkPlayers[GetMultiplayerId() ^ 1].trainerId);
MysteryGift_TryIncrementStat(CARD_STAT_BATTLES_LOST, gLinkPlayers[GetMultiplayerId() ^ 1].trainerId);
break;
}
}

View file

@ -83,9 +83,9 @@ bool32 ValidateSavedWonderNews(void)
return TRUE;
}
static bool32 ValidateWonderNews(const struct WonderNews *data)
static bool32 ValidateWonderNews(const struct WonderNews *news)
{
if (data->unk_00 == 0)
if (news->id == 0)
return FALSE;
return TRUE;
@ -93,8 +93,8 @@ static bool32 ValidateWonderNews(const struct WonderNews *data)
bool32 IsSendingSavedWonderNewsAllowed(void)
{
const struct WonderNews *data = &gSaveBlock1Ptr->mysteryGift.news;
if (data->sendType == SEND_TYPE_DISALLOWED)
const struct WonderNews *news = &gSaveBlock1Ptr->mysteryGift.news;
if (news->sendType == SEND_TYPE_DISALLOWED)
return FALSE;
return TRUE;
@ -177,7 +177,7 @@ static bool32 ValidateWonderCard(const struct WonderCard *card)
return FALSE;
if (card->bgType >= NUM_WONDER_BGS)
return FALSE;
if (card->maxStamps > MAX_CARD_STAMPS)
if (card->maxStamps > MAX_STAMP_CARD_STAMPS)
return FALSE;
return TRUE;
@ -339,23 +339,29 @@ bool32 MysteryGift_TrySaveStamp(const u16 *stamp)
return FALSE;
}
#define GAME_DATA_VALID_VAR 0x101
#define GAME_DATA_VALID_GIFT_TYPE_1 (1 << 2)
#define GAME_DATA_VALID_GIFT_TYPE_2 (1 << 9)
void MysteryGift_LoadLinkGameData(struct MysteryGiftLinkGameData *data, bool32 isWonderNews)
{
int i;
CpuFill32(0, data, sizeof(*data));
data->unk_00 = 0x101;
data->unk_04 = 1;
data->unk_08 = 1;
data->validationVar = GAME_DATA_VALID_VAR;
data->validationFlag1 = 1;
data->validationFlag2 = 1;
if (isWonderNews)
{
data->unk_0C = 5;
data->unk_10 = 0x0201;
// Despite setting these for News, they are
// only ever checked for Cards
data->validationGiftType1 = GAME_DATA_VALID_GIFT_TYPE_1 | 1;
data->validationGiftType2 = GAME_DATA_VALID_GIFT_TYPE_2 | 1;
}
else // Wonder Card
{
data->unk_0C = 4;
data->unk_10 = 0x0200;
data->validationGiftType1 = GAME_DATA_VALID_GIFT_TYPE_1;
data->validationGiftType2 = GAME_DATA_VALID_GIFT_TYPE_2;
}
if (ValidateSavedWonderCard())
@ -383,21 +389,21 @@ void MysteryGift_LoadLinkGameData(struct MysteryGiftLinkGameData *data, bool32 i
bool32 MysteryGift_ValidateLinkGameData(const struct MysteryGiftLinkGameData *data, bool32 forNews)
{
if (data->unk_00 != 0x101)
if (data->validationVar != GAME_DATA_VALID_VAR)
return FALSE;
if (!(data->unk_04 & 1))
if (!(data->validationFlag1 & 1))
return FALSE;
if (!(data->unk_08 & 1))
if (!(data->validationFlag2 & 1))
return FALSE;
if (!forNews)
{
if (!(data->unk_0C & 4))
if (!(data->validationGiftType1 & GAME_DATA_VALID_GIFT_TYPE_1))
return FALSE;
if (!(data->unk_10 & 0x380))
if (!(data->validationGiftType2 & (GAME_DATA_VALID_GIFT_TYPE_2 | 0x180)))
return FALSE;
}
@ -581,7 +587,7 @@ bool32 MysteryGift_TryEnableStatsByFlagId(u16 flagId)
return TRUE;
}
void TryIncrementMysteryGiftStat(u32 stat, u32 trainerId)
void MysteryGift_TryIncrementStat(u32 stat, u32 trainerId)
{
if (sStatsEnabled)
{

View file

@ -4655,7 +4655,7 @@ static void CB2_SaveAndEndTrade(void)
if (!InUnionRoom())
IncrementGameStat(GAME_STAT_POKEMON_TRADES);
if (gWirelessCommType)
TryIncrementMysteryGiftStat(CARD_STAT_NUM_TRADES, gLinkPlayers[GetMultiplayerId() ^ 1].trainerId);
MysteryGift_TryIncrementStat(CARD_STAT_NUM_TRADES, gLinkPlayers[GetMultiplayerId() ^ 1].trainerId);
SetContinueGameWarpStatusToDynamicWarp();
sub_8153380();

View file

@ -57,7 +57,7 @@ struct WonderCardData
/*0175*/ u8 statFooterWidth;
/*0176*/ u16 windowIds[CARD_WIN_COUNT];
/*017C*/ u8 monIconSpriteId;
/*017D*/ u8 stampSpriteIds[MAX_CARD_STAMPS][2]; // 2 sprites each, 1 for the shadw and 1 for the Pokémon
/*017D*/ u8 stampSpriteIds[MAX_STAMP_CARD_STAMPS][2]; // 2 sprites each, 1 for the shadw and 1 for the Pokémon
/*018B*/ u8 titleText[WONDER_CARD_TEXT_LENGTH + 1];
/*01B4*/ u8 subtitleText[WONDER_CARD_TEXT_LENGTH + 1];
/*01DD*/ u8 idNumberText[7];
@ -196,7 +196,7 @@ bool32 WonderCard_Init(struct WonderCard * card, struct WonderCardMetadata * met
sWonderCardData->card.bgType = 0;
if (sWonderCardData->card.type >= CARD_TYPE_COUNT)
sWonderCardData->card.type = 0;
if (sWonderCardData->card.maxStamps > MAX_CARD_STAMPS)
if (sWonderCardData->card.maxStamps > MAX_STAMP_CARD_STAMPS)
sWonderCardData->card.maxStamps = 0;
sWonderCardData->gfx = &sCardGraphics[sWonderCardData->card.bgType];
return TRUE;