diff --git a/data/specials.inc b/data/specials.inc index 85c9251c6..b8d7f232c 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -430,7 +430,7 @@ gSpecials:: def_special ShowWirelessCommunicationScreen def_special InitUnionRoom def_special BufferUnionRoomPlayerName - def_special sub_801DC20 + def_special RetrieveWonderNewsVal def_special ChooseMonForWirelessMinigame def_special Script_ResetUnionRoomTrade def_special IsBadEggInParty diff --git a/include/constants/vars.h b/include/constants/vars.h index e57b02185..8128b6f32 100644 --- a/include/constants/vars.h +++ b/include/constants/vars.h @@ -60,7 +60,7 @@ #define VAR_POISON_STEP_COUNTER 0x402B #define VAR_RESET_RTC_ENABLE 0x402C #define VAR_ENIGMA_BERRY_AVAILABLE 0x402D -#define VAR_0x402E 0x402E +#define VAR_WONDER_NEWS_COUNTER 0x402E #define VAR_FRONTIER_MANIAC_FACILITY 0x402F #define VAR_FRONTIER_GAMBLER_CHALLENGE 0x4030 diff --git a/include/global.h b/include/global.h index 8681f7289..d82ea875e 100644 --- a/include/global.h +++ b/include/global.h @@ -839,10 +839,10 @@ struct SaveTrainerHill struct WonderNewsMetadata { - u8 unk_0_0:2; - u8 unk_0_2:3; - u8 unk_0_5:3; - u8 unk_1; + u8 newsType:2; + u8 sentCounter:3; + u8 getCounter:3; + u8 rand; }; struct WonderNews diff --git a/include/mevent_news.h b/include/mevent_news.h index 7b4657e14..b0a0b8f07 100755 --- a/include/mevent_news.h +++ b/include/mevent_news.h @@ -1,7 +1,15 @@ #ifndef GUARD_MEVENT_NEWS_H #define GUARD_MEVENT_NEWS_H +enum { + WONDER_NEWS_NONE, + WONDER_NEWS_RECV_FRIEND, + WONDER_NEWS_RECV_WIRELESS, + WONDER_NEWS_SENT, +}; + + void InitSavedWonderNews(void); -void GenerateRandomWonderNews(u32 a0); +void GenerateRandomWonderNews(u32 newsType); #endif //GUARD_MEVENT_NEWS_H diff --git a/src/mevent_news.c b/src/mevent_news.c index 0fbb9452d..27b22566d 100644 --- a/src/mevent_news.c +++ b/src/mevent_news.c @@ -4,27 +4,43 @@ #include "event_data.h" #include "mevent_news.h" -static u32 sub_801DCAC(struct WonderNewsMetadata *); -static void sub_801DD10(struct WonderNewsMetadata *); -static u32 sub_801DD44(struct WonderNewsMetadata *); -static void sub_801DCD8(struct WonderNewsMetadata *); -static void sub_801DCCC(struct WonderNewsMetadata *); +/* + Wonder News related functions. + Because this feature is largely unused, the names in here are + mostly nebulous and without a real indication of purpose. +*/ -void GenerateRandomWonderNews(u32 a0) +enum { + NEWS_VAL_INVALID, + NEWS_VAL_RECV_FRIEND, + NEWS_VAL_RECV_WIRELESS, + NEWS_VAL_NONE, + NEWS_VAL_SENT, + NEWS_VAL_SENT_MAX, + NEWS_VAL_GET_MAX, +}; + +static u32 GetNewsId(struct WonderNewsMetadata *); +static void IncrementGetNewsCounter(struct WonderNewsMetadata *); +static u32 GetNewsValByNewsType(struct WonderNewsMetadata *); +static void IncrementSentNewsCounter(struct WonderNewsMetadata *); +static void ResetSentNewsCounter(struct WonderNewsMetadata *); + +void GenerateRandomWonderNews(u32 newsType) { struct WonderNewsMetadata *data = GetSavedWonderNewsMetadata(); - data->unk_0_0 = a0; - switch (a0) + data->newsType = newsType; + switch (newsType) { - case 0: + case WONDER_NEWS_NONE: break; - case 1: - case 2: - data->unk_1 = (Random() % 15) + 16; + case WONDER_NEWS_RECV_FRIEND: + case WONDER_NEWS_RECV_WIRELESS: + data->rand = (Random() % 15) + 16; break; - case 3: - data->unk_1 = (Random() % 15) + 1; + case WONDER_NEWS_SENT: + data->rand = (Random() % 15) + 1; break; } } @@ -33,116 +49,112 @@ void InitSavedWonderNews(void) { struct WonderNewsMetadata *data = GetSavedWonderNewsMetadata(); - data->unk_0_0 = 0; - data->unk_0_2 = 0; - data->unk_0_5 = 0; - data->unk_1 = 0; - VarSet(VAR_0x402E, 0); + data->newsType = WONDER_NEWS_NONE; + data->sentCounter = 0; + data->getCounter = 0; + data->rand = 0; + VarSet(VAR_WONDER_NEWS_COUNTER, 0); } -void sub_801DBDC(void) +// Unused +static void TryIncrementWonderNewsVar(void) { - u16 *r4 = GetVarPointer(VAR_0x402E); + u16 *var = GetVarPointer(VAR_WONDER_NEWS_COUNTER); struct WonderNewsMetadata *data = GetSavedWonderNewsMetadata(); - struct WonderNewsMetadata r0 = *data; - if ((u8)r0.unk_0_5 > 4 && ++(*r4) > 0x1f3) + if (data->getCounter > 4 && ++(*var) >= 500) { - data->unk_0_5 = 0; - *r4 = 0; + data->getCounter = 0; + *var = 0; } } // Unused -u16 sub_801DC20(void) +u16 RetrieveWonderNewsVal(void) { - u16 *r6 = &gSpecialVar_Result; + u16 *result = &gSpecialVar_Result; struct WonderNewsMetadata *data = GetSavedWonderNewsMetadata(); - u16 r5; + u16 newsVal; + // Checks if Mystery Event is enabled, not Mystery Gift? if (!IsMysteryEventEnabled() || !ValidateSavedWonderNews()) return 0; - r5 = sub_801DD44(data); + newsVal = GetNewsValByNewsType(data); - switch (r5) + switch (newsVal) { - case 0: + case NEWS_VAL_RECV_FRIEND: + *result = GetNewsId(data); break; - case 1: - *r6 = sub_801DCAC(data); + case NEWS_VAL_RECV_WIRELESS: + *result = GetNewsId(data); break; - case 2: - *r6 = sub_801DCAC(data); + case NEWS_VAL_SENT: + *result = GetNewsId(data); + IncrementSentNewsCounter(data); break; - case 3: + case NEWS_VAL_SENT_MAX: + *result = GetNewsId(data); + ResetSentNewsCounter(data); break; - case 4: - *r6 = sub_801DCAC(data); - sub_801DCD8(data); - break; - case 5: - *r6 = sub_801DCAC(data); - sub_801DCCC(data); - break; - case 6: + case NEWS_VAL_INVALID: + case NEWS_VAL_NONE: + case NEWS_VAL_GET_MAX: break; } - return r5; + return newsVal; } -static u32 sub_801DCAC(struct WonderNewsMetadata *data) +static u32 GetNewsId(struct WonderNewsMetadata *data) { - u32 r4; - - data->unk_0_0 = 0; - r4 = data->unk_1 + 0x84; - data->unk_1 = 0; - sub_801DD10(data); - return r4; + u32 id; + data->newsType = WONDER_NEWS_NONE; + id = data->rand + 132; + data->rand = 0; + IncrementGetNewsCounter(data); + return id; } -static void sub_801DCCC(struct WonderNewsMetadata *data) +static void ResetSentNewsCounter(struct WonderNewsMetadata *data) { - data->unk_0_2 = 0; + data->sentCounter = 0; } -static void sub_801DCD8(struct WonderNewsMetadata *data) +static void IncrementSentNewsCounter(struct WonderNewsMetadata *data) { - data->unk_0_2++; - if ((u8)data->unk_0_2 > 4) - data->unk_0_2 = 4; + data->sentCounter++; + if (data->sentCounter > 4) + data->sentCounter = 4; } -static void sub_801DD10(struct WonderNewsMetadata *data) +static void IncrementGetNewsCounter(struct WonderNewsMetadata *data) { - data->unk_0_5++; - if ((u8)data->unk_0_5 > 5) - data->unk_0_5 = 5; + data->getCounter++; + if (data->getCounter > 5) + data->getCounter = 5; } -static u32 sub_801DD44(struct WonderNewsMetadata *data) +static u32 GetNewsValByNewsType(struct WonderNewsMetadata *data) { - struct WonderNewsMetadata r0; - if ((u8)data->unk_0_5 == 5) - return 6; + if (data->getCounter == 5) + return NEWS_VAL_GET_MAX; - r0 = *data; - switch (r0.unk_0_0) + switch (data->newsType) { - case 0: - return 3; - case 1: - return 1; - case 2: - return 2; - case 3: - if ((u8)r0.unk_0_2 < 3) - return 4; - return 5; + case WONDER_NEWS_NONE: + return NEWS_VAL_NONE; + case WONDER_NEWS_RECV_FRIEND: + return NEWS_VAL_RECV_FRIEND; + case WONDER_NEWS_RECV_WIRELESS: + return NEWS_VAL_RECV_WIRELESS; + case WONDER_NEWS_SENT: + if (data->sentCounter < 3) + return NEWS_VAL_SENT; + return NEWS_VAL_SENT_MAX; default: AGB_ASSERT(0); - return 0; + return NEWS_VAL_INVALID; } } diff --git a/src/mystery_gift.c b/src/mystery_gift.c index 35bf8e9ed..864ea9838 100644 --- a/src/mystery_gift.c +++ b/src/mystery_gift.c @@ -1371,9 +1371,9 @@ static void Task_MysteryGift(u8 taskId) if (data->msgId == CLI_MSG_NEWS_RECEIVED) { if (data->sourceIsFriend == TRUE) - GenerateRandomWonderNews(1); + GenerateRandomWonderNews(WONDER_NEWS_RECV_FRIEND); else - GenerateRandomWonderNews(2); + GenerateRandomWonderNews(WONDER_NEWS_RECV_WIRELESS); } if (!successMsg) { @@ -1580,7 +1580,7 @@ static void Task_MysteryGift(u8 taskId) { if (data->sourceIsFriend == TRUE && data->msgId == SVR_MSG_NEWS_SENT) { - GenerateRandomWonderNews(3); + GenerateRandomWonderNews(WONDER_NEWS_SENT); data->state = MG_STATE_SAVE_LOAD_GIFT; } else