2019-03-26 20:11:55 +01:00
|
|
|
#include "global.h"
|
2021-10-17 09:00:48 +02:00
|
|
|
#include "mystery_gift.h"
|
2019-03-26 20:11:55 +01:00
|
|
|
#include "random.h"
|
|
|
|
#include "event_data.h"
|
2021-10-17 09:00:48 +02:00
|
|
|
#include "wonder_news.h"
|
2019-03-26 20:11:55 +01:00
|
|
|
|
2021-10-17 08:09:31 +02:00
|
|
|
/*
|
|
|
|
Wonder News related functions.
|
|
|
|
Because this feature is largely unused, the names in here are
|
|
|
|
mostly nebulous and without a real indication of purpose.
|
|
|
|
*/
|
|
|
|
|
|
|
|
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)
|
2019-03-26 20:11:55 +01:00
|
|
|
{
|
2021-10-15 18:56:14 +02:00
|
|
|
struct WonderNewsMetadata *data = GetSavedWonderNewsMetadata();
|
2019-03-26 20:11:55 +01:00
|
|
|
|
2021-10-17 08:09:31 +02:00
|
|
|
data->newsType = newsType;
|
|
|
|
switch (newsType)
|
2019-03-26 20:11:55 +01:00
|
|
|
{
|
2021-10-17 08:09:31 +02:00
|
|
|
case WONDER_NEWS_NONE:
|
2019-03-26 20:11:55 +01:00
|
|
|
break;
|
2021-10-17 08:09:31 +02:00
|
|
|
case WONDER_NEWS_RECV_FRIEND:
|
|
|
|
case WONDER_NEWS_RECV_WIRELESS:
|
|
|
|
data->rand = (Random() % 15) + 16;
|
2019-03-26 20:11:55 +01:00
|
|
|
break;
|
2021-10-17 08:09:31 +02:00
|
|
|
case WONDER_NEWS_SENT:
|
|
|
|
data->rand = (Random() % 15) + 1;
|
2019-03-26 20:11:55 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-15 18:56:14 +02:00
|
|
|
void InitSavedWonderNews(void)
|
2019-03-26 20:11:55 +01:00
|
|
|
{
|
2021-10-15 18:56:14 +02:00
|
|
|
struct WonderNewsMetadata *data = GetSavedWonderNewsMetadata();
|
2019-03-26 20:11:55 +01:00
|
|
|
|
2021-10-17 08:09:31 +02:00
|
|
|
data->newsType = WONDER_NEWS_NONE;
|
|
|
|
data->sentCounter = 0;
|
|
|
|
data->getCounter = 0;
|
|
|
|
data->rand = 0;
|
|
|
|
VarSet(VAR_WONDER_NEWS_COUNTER, 0);
|
2019-03-26 20:11:55 +01:00
|
|
|
}
|
|
|
|
|
2021-10-17 08:09:31 +02:00
|
|
|
// Unused
|
|
|
|
static void TryIncrementWonderNewsVar(void)
|
2019-03-26 20:11:55 +01:00
|
|
|
{
|
2021-10-17 08:09:31 +02:00
|
|
|
u16 *var = GetVarPointer(VAR_WONDER_NEWS_COUNTER);
|
2021-10-15 18:56:14 +02:00
|
|
|
struct WonderNewsMetadata *data = GetSavedWonderNewsMetadata();
|
2019-03-26 20:11:55 +01:00
|
|
|
|
2021-10-17 08:09:31 +02:00
|
|
|
if (data->getCounter > 4 && ++(*var) >= 500)
|
2019-03-26 20:11:55 +01:00
|
|
|
{
|
2021-10-17 08:09:31 +02:00
|
|
|
data->getCounter = 0;
|
|
|
|
*var = 0;
|
2019-03-26 20:11:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-08 10:26:26 +01:00
|
|
|
// Unused
|
2021-10-17 08:09:31 +02:00
|
|
|
u16 RetrieveWonderNewsVal(void)
|
2019-03-26 20:11:55 +01:00
|
|
|
{
|
2021-10-17 08:09:31 +02:00
|
|
|
u16 *result = &gSpecialVar_Result;
|
2021-10-15 18:56:14 +02:00
|
|
|
struct WonderNewsMetadata *data = GetSavedWonderNewsMetadata();
|
2021-10-17 08:09:31 +02:00
|
|
|
u16 newsVal;
|
2019-03-26 20:11:55 +01:00
|
|
|
|
2021-10-17 08:09:31 +02:00
|
|
|
// Checks if Mystery Event is enabled, not Mystery Gift?
|
2021-10-14 21:36:51 +02:00
|
|
|
if (!IsMysteryEventEnabled() || !ValidateSavedWonderNews())
|
2019-03-26 20:11:55 +01:00
|
|
|
return 0;
|
|
|
|
|
2021-10-17 08:09:31 +02:00
|
|
|
newsVal = GetNewsValByNewsType(data);
|
2019-03-26 20:11:55 +01:00
|
|
|
|
2021-10-17 08:09:31 +02:00
|
|
|
switch (newsVal)
|
2019-03-26 20:11:55 +01:00
|
|
|
{
|
2021-10-17 08:09:31 +02:00
|
|
|
case NEWS_VAL_RECV_FRIEND:
|
|
|
|
*result = GetNewsId(data);
|
2019-03-26 20:11:55 +01:00
|
|
|
break;
|
2021-10-17 08:09:31 +02:00
|
|
|
case NEWS_VAL_RECV_WIRELESS:
|
|
|
|
*result = GetNewsId(data);
|
2019-03-26 20:11:55 +01:00
|
|
|
break;
|
2021-10-17 08:09:31 +02:00
|
|
|
case NEWS_VAL_SENT:
|
|
|
|
*result = GetNewsId(data);
|
|
|
|
IncrementSentNewsCounter(data);
|
2019-03-26 20:11:55 +01:00
|
|
|
break;
|
2021-10-17 08:09:31 +02:00
|
|
|
case NEWS_VAL_SENT_MAX:
|
|
|
|
*result = GetNewsId(data);
|
|
|
|
ResetSentNewsCounter(data);
|
2019-03-26 20:11:55 +01:00
|
|
|
break;
|
2021-10-17 08:09:31 +02:00
|
|
|
case NEWS_VAL_INVALID:
|
|
|
|
case NEWS_VAL_NONE:
|
|
|
|
case NEWS_VAL_GET_MAX:
|
2019-03-26 20:11:55 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-10-17 08:09:31 +02:00
|
|
|
return newsVal;
|
2019-03-26 20:11:55 +01:00
|
|
|
}
|
|
|
|
|
2021-10-17 08:09:31 +02:00
|
|
|
static u32 GetNewsId(struct WonderNewsMetadata *data)
|
2019-03-26 20:11:55 +01:00
|
|
|
{
|
2021-10-17 08:09:31 +02:00
|
|
|
u32 id;
|
|
|
|
data->newsType = WONDER_NEWS_NONE;
|
|
|
|
id = data->rand + 132;
|
|
|
|
data->rand = 0;
|
|
|
|
IncrementGetNewsCounter(data);
|
|
|
|
return id;
|
2019-03-26 20:11:55 +01:00
|
|
|
}
|
|
|
|
|
2021-10-17 08:09:31 +02:00
|
|
|
static void ResetSentNewsCounter(struct WonderNewsMetadata *data)
|
2019-03-26 20:11:55 +01:00
|
|
|
{
|
2021-10-17 08:09:31 +02:00
|
|
|
data->sentCounter = 0;
|
2019-03-26 20:11:55 +01:00
|
|
|
}
|
|
|
|
|
2021-10-17 08:09:31 +02:00
|
|
|
static void IncrementSentNewsCounter(struct WonderNewsMetadata *data)
|
2019-03-26 20:11:55 +01:00
|
|
|
{
|
2021-10-17 08:09:31 +02:00
|
|
|
data->sentCounter++;
|
|
|
|
if (data->sentCounter > 4)
|
|
|
|
data->sentCounter = 4;
|
2019-03-26 20:11:55 +01:00
|
|
|
}
|
|
|
|
|
2021-10-17 08:09:31 +02:00
|
|
|
static void IncrementGetNewsCounter(struct WonderNewsMetadata *data)
|
2019-03-26 20:11:55 +01:00
|
|
|
{
|
2021-10-17 08:09:31 +02:00
|
|
|
data->getCounter++;
|
|
|
|
if (data->getCounter > 5)
|
|
|
|
data->getCounter = 5;
|
2019-03-26 20:11:55 +01:00
|
|
|
}
|
|
|
|
|
2021-10-17 08:09:31 +02:00
|
|
|
static u32 GetNewsValByNewsType(struct WonderNewsMetadata *data)
|
2019-03-26 20:11:55 +01:00
|
|
|
{
|
2021-10-17 08:09:31 +02:00
|
|
|
if (data->getCounter == 5)
|
|
|
|
return NEWS_VAL_GET_MAX;
|
2019-03-26 20:11:55 +01:00
|
|
|
|
2021-10-17 08:09:31 +02:00
|
|
|
switch (data->newsType)
|
2019-03-26 20:11:55 +01:00
|
|
|
{
|
2021-10-17 08:09:31 +02:00
|
|
|
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;
|
2019-03-26 20:11:55 +01:00
|
|
|
default:
|
|
|
|
AGB_ASSERT(0);
|
2021-10-17 08:09:31 +02:00
|
|
|
return NEWS_VAL_INVALID;
|
2019-03-26 20:11:55 +01:00
|
|
|
}
|
|
|
|
}
|