Document wonder news

This commit is contained in:
GriffinR 2022-11-22 02:17:03 -05:00
parent 601bb0b578
commit 483c3d5c13
11 changed files with 103 additions and 99 deletions

View File

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

View File

@ -44,4 +44,12 @@
#define WONDER_CARD_FLAG_OFFSET 1000
#define NEWS_REWARD_NONE 0
#define NEWS_REWARD_RECV_SMALL 1
#define NEWS_REWARD_RECV_BIG 2
#define NEWS_REWARD_WAITING 3
#define NEWS_REWARD_SENT_SMALL 4
#define NEWS_REWARD_SENT_BIG 5
#define NEWS_REWARD_AT_MAX 6
#endif //GUARD_CONSTANTS_MYSTERY_GIFT_H

View File

@ -60,7 +60,7 @@
#define VAR_POISON_STEP_COUNTER 0x402B
#define VAR_RESET_RTC_ENABLE 0x402C
#define VAR_ENIGMA_BERRY_AVAILABLE 0x402D
#define VAR_WONDER_NEWS_COUNTER 0x402E
#define VAR_WONDER_NEWS_STEP_COUNTER 0x402E
#define VAR_FRONTIER_MANIAC_FACILITY 0x402F
#define VAR_FRONTIER_GAMBLER_CHALLENGE 0x4030

View File

@ -829,9 +829,9 @@ struct TrainerHillSave
struct WonderNewsMetadata
{
u8 newsType:2;
u8 sentCounter:3;
u8 getCounter:3;
u8 rand;
u8 sentRewardCounter:3;
u8 rewardCounter:3;
u8 berry;
};
struct WonderNews

View File

@ -100,8 +100,8 @@
#define LINKTYPE_BERRY_BLENDER_SETUP 0x4411
#define LINKTYPE_BERRY_BLENDER 0x4422
#define LINKTYPE_MYSTERY_EVENT 0x5501
#define LINKTYPE_UNUSED_EREADER 0x5502 // Unused, inferred from gap
#define LINKTYPE_EREADER 0x5503
#define LINKTYPE_EREADER_FRLG 0x5502
#define LINKTYPE_EREADER_EM 0x5503
#define LINKTYPE_CONTEST_GMODE 0x6601
#define LINKTYPE_CONTEST_EMODE 0x6602

View File

@ -8,8 +8,7 @@ enum {
WONDER_NEWS_SENT,
};
void InitSavedWonderNews(void);
void GenerateRandomWonderNews(u32 newsType);
void WonderNews_Reset(void);
void WonderNews_SetReward(u32 newsType);
#endif //GUARD_WONDER_NEWS_H

View File

@ -5,6 +5,7 @@
#include "link.h"
#include "main.h"
#include "mystery_gift_menu.h"
#include "mystery_gift_client.h"
#include "save.h"
#include "sound.h"
#include "sprite.h"
@ -98,7 +99,7 @@ static u8 EReader_Transfer(struct EReaderData *eReader)
static void OpenEReaderLink(void)
{
memset(gDecompressionBuffer, 0, 0x2000);
gLinkType = LINKTYPE_EREADER;
gLinkType = LINKTYPE_EREADER_EM;
OpenLink();
SetSuppressLinkErrorMessage(TRUE);
}
@ -259,7 +260,7 @@ void CreateEReaderTask(void)
data->unused2 = 0;
data->unused3 = 0;
data->status = 0;
data->unusedBuffer = AllocZeroed(0x40);
data->unusedBuffer = AllocZeroed(CLIENT_MAX_MSG_SIZE);
}
static void ResetTimer(u16 *timer)

View File

@ -27,7 +27,7 @@ static void IncrementCardStatForNewTrainer(u32, u32, u32 *, int);
void ClearMysteryGift(void)
{
CpuFill32(0, &gSaveBlock1Ptr->mysteryGift, sizeof(gSaveBlock1Ptr->mysteryGift));
ClearSavedWonderNewsMetadata(); // Clear is redundant, InitSavedWonderNews would be sufficient
ClearSavedWonderNewsMetadata(); // Clear is redundant, WonderNews_Reset would be sufficient
InitQuestionnaireWords();
}
@ -109,7 +109,7 @@ static void ClearSavedWonderNews(void)
static void ClearSavedWonderNewsMetadata(void)
{
CpuFill32(0, GetSavedWonderNewsMetadata(), sizeof(gSaveBlock1Ptr->mysteryGift.newsMetadata));
InitSavedWonderNews();
WonderNews_Reset();
}
bool32 IsWonderNewsSameAsSaved(const u8 *news)

View File

@ -1258,7 +1258,7 @@ static void Task_MysteryGift(u8 taskId)
data->state = MG_STATE_CLIENT_LINK_END;
break;
case CLI_RET_COPY_MSG:
memcpy(data->clientMsg, MysteryGiftClient_GetMsg(), 0x40);
memcpy(data->clientMsg, MysteryGiftClient_GetMsg(), CLIENT_MAX_MSG_SIZE);
MysteryGiftClient_AdvanceState();
break;
case CLI_RET_PRINT_MSG:
@ -1371,9 +1371,9 @@ static void Task_MysteryGift(u8 taskId)
if (data->msgId == CLI_MSG_NEWS_RECEIVED)
{
if (data->sourceIsFriend == TRUE)
GenerateRandomWonderNews(WONDER_NEWS_RECV_FRIEND);
WonderNews_SetReward(WONDER_NEWS_RECV_FRIEND);
else
GenerateRandomWonderNews(WONDER_NEWS_RECV_WIRELESS);
WonderNews_SetReward(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(WONDER_NEWS_SENT);
WonderNews_SetReward(WONDER_NEWS_SENT);
data->state = MG_STATE_SAVE_LOAD_GIFT;
}
else

View File

@ -172,7 +172,7 @@ static const struct MysteryGiftServerCmd sServerScript_TossPrompt[] = {
{SVR_SEND},
{SVR_RECV, MG_LINKID_RESPONSE},
{SVR_READ_RESPONSE},
{SVR_GOTO_IF_EQ, FALSE, sServerScript_SendCard}, // Tossed old card, send new one
{SVR_GOTO_IF_EQ, FALSE, sServerScript_SendCard}, // Tossed old card, send new one
{SVR_GOTO, .ptr = sServerScript_ClientCanceledCard} // Kept old card, cancel new one
};

View File

@ -3,30 +3,22 @@
#include "random.h"
#include "event_data.h"
#include "wonder_news.h"
#include "constants/items.h"
/*
Wonder News related functions.
Because this feature is largely unused, the names in here are
mostly nebulous and without a real indication of purpose.
*/
// Every 4th reward for sending Wonder News to a link partner is a "big" reward.
#define MAX_SENT_REWARD 4
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,
};
// Only up to 5 rewards can be received in a short period. After this the player
// must take 500 steps before any more rewards can be received.
#define MAX_REWARD 5
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 *);
static u32 GetRewardItem(struct WonderNewsMetadata *);
static u32 GetRewardType(struct WonderNewsMetadata *);
static void IncrementRewardCounter(struct WonderNewsMetadata *);
static void IncrementSentRewardCounter(struct WonderNewsMetadata *);
static void ResetSentRewardCounter(struct WonderNewsMetadata *);
void GenerateRandomWonderNews(u32 newsType)
void WonderNews_SetReward(u32 newsType)
{
struct WonderNewsMetadata *data = GetSavedWonderNewsMetadata();
@ -37,124 +29,128 @@ void GenerateRandomWonderNews(u32 newsType)
break;
case WONDER_NEWS_RECV_FRIEND:
case WONDER_NEWS_RECV_WIRELESS:
data->rand = (Random() % 15) + 16;
// Random berry between ITEM_RAZZ_BERRY and ITEM_NOMEL_BERRY
data->berry = (Random() % 15) + ITEM_TO_BERRY(ITEM_RAZZ_BERRY);
break;
case WONDER_NEWS_SENT:
data->rand = (Random() % 15) + 1;
// Random berry between ITEM_CHERI_BERRY and ITEM_IAPAPA_BERRY
data->berry = (Random() % 15) + ITEM_TO_BERRY(ITEM_CHERI_BERRY);
break;
}
}
void InitSavedWonderNews(void)
void WonderNews_Reset(void)
{
struct WonderNewsMetadata *data = GetSavedWonderNewsMetadata();
data->newsType = WONDER_NEWS_NONE;
data->sentCounter = 0;
data->getCounter = 0;
data->rand = 0;
VarSet(VAR_WONDER_NEWS_COUNTER, 0);
data->sentRewardCounter = 0;
data->rewardCounter = 0;
data->berry = 0;
VarSet(VAR_WONDER_NEWS_STEP_COUNTER, 0);
}
// Unused
static void TryIncrementWonderNewsVar(void)
// Only used in FRLG
void WonderNews_IncrementStepCounter(void)
{
u16 *var = GetVarPointer(VAR_WONDER_NEWS_COUNTER);
u16 *stepCounter = GetVarPointer(VAR_WONDER_NEWS_STEP_COUNTER);
struct WonderNewsMetadata *data = GetSavedWonderNewsMetadata();
if (data->getCounter > 4 && ++(*var) >= 500)
// If the player has reached the reward limit, start counting steps.
// When they reach 500 steps reset the reward counter to allow them to
// receive rewards again.
if (data->rewardCounter >= MAX_REWARD && ++(*stepCounter) >= 500)
{
data->getCounter = 0;
*var = 0;
data->rewardCounter = 0;
*stepCounter = 0;
}
}
// Unused
u16 RetrieveWonderNewsVal(void)
// Only used in FRLG
u16 WonderNews_GetRewardInfo(void)
{
u16 *result = &gSpecialVar_Result;
struct WonderNewsMetadata *data = GetSavedWonderNewsMetadata();
u16 newsVal;
u16 rewardType;
// Checks if Mystery Event is enabled, not Mystery Gift?
if (!IsMysteryEventEnabled() || !ValidateSavedWonderNews())
return 0;
return NEWS_REWARD_NONE;
newsVal = GetNewsValByNewsType(data);
rewardType = GetRewardType(data);
switch (newsVal)
switch (rewardType)
{
case NEWS_VAL_RECV_FRIEND:
*result = GetNewsId(data);
case NEWS_REWARD_RECV_SMALL:
case NEWS_REWARD_RECV_BIG:
*result = GetRewardItem(data);
break;
case NEWS_VAL_RECV_WIRELESS:
*result = GetNewsId(data);
case NEWS_REWARD_SENT_SMALL:
*result = GetRewardItem(data);
IncrementSentRewardCounter(data);
break;
case NEWS_VAL_SENT:
*result = GetNewsId(data);
IncrementSentNewsCounter(data);
case NEWS_REWARD_SENT_BIG:
*result = GetRewardItem(data);
ResetSentRewardCounter(data);
break;
case NEWS_VAL_SENT_MAX:
*result = GetNewsId(data);
ResetSentNewsCounter(data);
break;
case NEWS_VAL_INVALID:
case NEWS_VAL_NONE:
case NEWS_VAL_GET_MAX:
case NEWS_REWARD_NONE:
case NEWS_REWARD_WAITING:
case NEWS_REWARD_AT_MAX:
break;
}
return newsVal;
return rewardType;
}
static u32 GetNewsId(struct WonderNewsMetadata *data)
static u32 GetRewardItem(struct WonderNewsMetadata *data)
{
u32 id;
u32 itemId;
data->newsType = WONDER_NEWS_NONE;
id = data->rand + 132;
data->rand = 0;
IncrementGetNewsCounter(data);
return id;
itemId = data->berry + FIRST_BERRY_INDEX - 1;
data->berry = 0;
IncrementRewardCounter(data);
return itemId;
}
static void ResetSentNewsCounter(struct WonderNewsMetadata *data)
static void ResetSentRewardCounter(struct WonderNewsMetadata *data)
{
data->sentCounter = 0;
data->sentRewardCounter = 0;
}
static void IncrementSentNewsCounter(struct WonderNewsMetadata *data)
// Track number of times a reward was received (or attmepted to receive) for sending Wonder News to a link partner.
static void IncrementSentRewardCounter(struct WonderNewsMetadata *data)
{
data->sentCounter++;
if (data->sentCounter > 4)
data->sentCounter = 4;
data->sentRewardCounter++;
if (data->sentRewardCounter > MAX_SENT_REWARD)
data->sentRewardCounter = MAX_SENT_REWARD;
}
static void IncrementGetNewsCounter(struct WonderNewsMetadata *data)
static void IncrementRewardCounter(struct WonderNewsMetadata *data)
{
data->getCounter++;
if (data->getCounter > 5)
data->getCounter = 5;
data->rewardCounter++;
if (data->rewardCounter > MAX_REWARD)
data->rewardCounter = MAX_REWARD;
}
static u32 GetNewsValByNewsType(struct WonderNewsMetadata *data)
static u32 GetRewardType(struct WonderNewsMetadata *data)
{
if (data->getCounter == 5)
return NEWS_VAL_GET_MAX;
if (data->rewardCounter == MAX_REWARD)
return NEWS_REWARD_AT_MAX;
switch (data->newsType)
{
case WONDER_NEWS_NONE:
return NEWS_VAL_NONE;
return NEWS_REWARD_WAITING;
case WONDER_NEWS_RECV_FRIEND:
return NEWS_VAL_RECV_FRIEND;
return NEWS_REWARD_RECV_SMALL;
case WONDER_NEWS_RECV_WIRELESS:
return NEWS_VAL_RECV_WIRELESS;
return NEWS_REWARD_RECV_BIG;
case WONDER_NEWS_SENT:
if (data->sentCounter < 3)
return NEWS_VAL_SENT;
return NEWS_VAL_SENT_MAX;
if (data->sentRewardCounter < MAX_SENT_REWARD - 1)
return NEWS_REWARD_SENT_SMALL;
return NEWS_REWARD_SENT_BIG;
default:
AGB_ASSERT(0);
return NEWS_VAL_INVALID;
return NEWS_REWARD_NONE;
}
}