Document wonder news

This commit is contained in:
GriffinR 2021-10-17 02:09:31 -04:00
parent 5f9069628d
commit 3cd27acbea
6 changed files with 111 additions and 91 deletions

View File

@ -430,7 +430,7 @@ gSpecials::
def_special ShowWirelessCommunicationScreen def_special ShowWirelessCommunicationScreen
def_special InitUnionRoom def_special InitUnionRoom
def_special BufferUnionRoomPlayerName def_special BufferUnionRoomPlayerName
def_special sub_801DC20 def_special RetrieveWonderNewsVal
def_special ChooseMonForWirelessMinigame def_special ChooseMonForWirelessMinigame
def_special Script_ResetUnionRoomTrade def_special Script_ResetUnionRoomTrade
def_special IsBadEggInParty def_special IsBadEggInParty

View File

@ -60,7 +60,7 @@
#define VAR_POISON_STEP_COUNTER 0x402B #define VAR_POISON_STEP_COUNTER 0x402B
#define VAR_RESET_RTC_ENABLE 0x402C #define VAR_RESET_RTC_ENABLE 0x402C
#define VAR_ENIGMA_BERRY_AVAILABLE 0x402D #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_MANIAC_FACILITY 0x402F
#define VAR_FRONTIER_GAMBLER_CHALLENGE 0x4030 #define VAR_FRONTIER_GAMBLER_CHALLENGE 0x4030

View File

@ -839,10 +839,10 @@ struct SaveTrainerHill
struct WonderNewsMetadata struct WonderNewsMetadata
{ {
u8 unk_0_0:2; u8 newsType:2;
u8 unk_0_2:3; u8 sentCounter:3;
u8 unk_0_5:3; u8 getCounter:3;
u8 unk_1; u8 rand;
}; };
struct WonderNews struct WonderNews

View File

@ -1,7 +1,15 @@
#ifndef GUARD_MEVENT_NEWS_H #ifndef GUARD_MEVENT_NEWS_H
#define 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 InitSavedWonderNews(void);
void GenerateRandomWonderNews(u32 a0); void GenerateRandomWonderNews(u32 newsType);
#endif //GUARD_MEVENT_NEWS_H #endif //GUARD_MEVENT_NEWS_H

View File

@ -4,27 +4,43 @@
#include "event_data.h" #include "event_data.h"
#include "mevent_news.h" #include "mevent_news.h"
static u32 sub_801DCAC(struct WonderNewsMetadata *); /*
static void sub_801DD10(struct WonderNewsMetadata *); Wonder News related functions.
static u32 sub_801DD44(struct WonderNewsMetadata *); Because this feature is largely unused, the names in here are
static void sub_801DCD8(struct WonderNewsMetadata *); mostly nebulous and without a real indication of purpose.
static void sub_801DCCC(struct WonderNewsMetadata *); */
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(); struct WonderNewsMetadata *data = GetSavedWonderNewsMetadata();
data->unk_0_0 = a0; data->newsType = newsType;
switch (a0) switch (newsType)
{ {
case 0: case WONDER_NEWS_NONE:
break; break;
case 1: case WONDER_NEWS_RECV_FRIEND:
case 2: case WONDER_NEWS_RECV_WIRELESS:
data->unk_1 = (Random() % 15) + 16; data->rand = (Random() % 15) + 16;
break; break;
case 3: case WONDER_NEWS_SENT:
data->unk_1 = (Random() % 15) + 1; data->rand = (Random() % 15) + 1;
break; break;
} }
} }
@ -33,116 +49,112 @@ void InitSavedWonderNews(void)
{ {
struct WonderNewsMetadata *data = GetSavedWonderNewsMetadata(); struct WonderNewsMetadata *data = GetSavedWonderNewsMetadata();
data->unk_0_0 = 0; data->newsType = WONDER_NEWS_NONE;
data->unk_0_2 = 0; data->sentCounter = 0;
data->unk_0_5 = 0; data->getCounter = 0;
data->unk_1 = 0; data->rand = 0;
VarSet(VAR_0x402E, 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 *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; data->getCounter = 0;
*r4 = 0; *var = 0;
} }
} }
// Unused // Unused
u16 sub_801DC20(void) u16 RetrieveWonderNewsVal(void)
{ {
u16 *r6 = &gSpecialVar_Result; u16 *result = &gSpecialVar_Result;
struct WonderNewsMetadata *data = GetSavedWonderNewsMetadata(); struct WonderNewsMetadata *data = GetSavedWonderNewsMetadata();
u16 r5; u16 newsVal;
// Checks if Mystery Event is enabled, not Mystery Gift?
if (!IsMysteryEventEnabled() || !ValidateSavedWonderNews()) if (!IsMysteryEventEnabled() || !ValidateSavedWonderNews())
return 0; return 0;
r5 = sub_801DD44(data); newsVal = GetNewsValByNewsType(data);
switch (r5) switch (newsVal)
{ {
case 0: case NEWS_VAL_RECV_FRIEND:
*result = GetNewsId(data);
break; break;
case 1: case NEWS_VAL_RECV_WIRELESS:
*r6 = sub_801DCAC(data); *result = GetNewsId(data);
break; break;
case 2: case NEWS_VAL_SENT:
*r6 = sub_801DCAC(data); *result = GetNewsId(data);
IncrementSentNewsCounter(data);
break; break;
case 3: case NEWS_VAL_SENT_MAX:
*result = GetNewsId(data);
ResetSentNewsCounter(data);
break; break;
case 4: case NEWS_VAL_INVALID:
*r6 = sub_801DCAC(data); case NEWS_VAL_NONE:
sub_801DCD8(data); case NEWS_VAL_GET_MAX:
break;
case 5:
*r6 = sub_801DCAC(data);
sub_801DCCC(data);
break;
case 6:
break; break;
} }
return r5; return newsVal;
} }
static u32 sub_801DCAC(struct WonderNewsMetadata *data) static u32 GetNewsId(struct WonderNewsMetadata *data)
{ {
u32 r4; u32 id;
data->newsType = WONDER_NEWS_NONE;
data->unk_0_0 = 0; id = data->rand + 132;
r4 = data->unk_1 + 0x84; data->rand = 0;
data->unk_1 = 0; IncrementGetNewsCounter(data);
sub_801DD10(data); return id;
return r4;
} }
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++; data->sentCounter++;
if ((u8)data->unk_0_2 > 4) if (data->sentCounter > 4)
data->unk_0_2 = 4; data->sentCounter = 4;
} }
static void sub_801DD10(struct WonderNewsMetadata *data) static void IncrementGetNewsCounter(struct WonderNewsMetadata *data)
{ {
data->unk_0_5++; data->getCounter++;
if ((u8)data->unk_0_5 > 5) if (data->getCounter > 5)
data->unk_0_5 = 5; data->getCounter = 5;
} }
static u32 sub_801DD44(struct WonderNewsMetadata *data) static u32 GetNewsValByNewsType(struct WonderNewsMetadata *data)
{ {
struct WonderNewsMetadata r0; if (data->getCounter == 5)
if ((u8)data->unk_0_5 == 5) return NEWS_VAL_GET_MAX;
return 6;
r0 = *data; switch (data->newsType)
switch (r0.unk_0_0)
{ {
case 0: case WONDER_NEWS_NONE:
return 3; return NEWS_VAL_NONE;
case 1: case WONDER_NEWS_RECV_FRIEND:
return 1; return NEWS_VAL_RECV_FRIEND;
case 2: case WONDER_NEWS_RECV_WIRELESS:
return 2; return NEWS_VAL_RECV_WIRELESS;
case 3: case WONDER_NEWS_SENT:
if ((u8)r0.unk_0_2 < 3) if (data->sentCounter < 3)
return 4; return NEWS_VAL_SENT;
return 5; return NEWS_VAL_SENT_MAX;
default: default:
AGB_ASSERT(0); AGB_ASSERT(0);
return 0; return NEWS_VAL_INVALID;
} }
} }

View File

@ -1371,9 +1371,9 @@ static void Task_MysteryGift(u8 taskId)
if (data->msgId == CLI_MSG_NEWS_RECEIVED) if (data->msgId == CLI_MSG_NEWS_RECEIVED)
{ {
if (data->sourceIsFriend == TRUE) if (data->sourceIsFriend == TRUE)
GenerateRandomWonderNews(1); GenerateRandomWonderNews(WONDER_NEWS_RECV_FRIEND);
else else
GenerateRandomWonderNews(2); GenerateRandomWonderNews(WONDER_NEWS_RECV_WIRELESS);
} }
if (!successMsg) if (!successMsg)
{ {
@ -1580,7 +1580,7 @@ static void Task_MysteryGift(u8 taskId)
{ {
if (data->sourceIsFriend == TRUE && data->msgId == SVR_MSG_NEWS_SENT) if (data->sourceIsFriend == TRUE && data->msgId == SVR_MSG_NEWS_SENT)
{ {
GenerateRandomWonderNews(3); GenerateRandomWonderNews(WONDER_NEWS_SENT);
data->state = MG_STATE_SAVE_LOAD_GIFT; data->state = MG_STATE_SAVE_LOAD_GIFT;
} }
else else