sovereignx/src/event_data.c

250 lines
5.8 KiB
C
Raw Normal View History

2017-09-02 20:43:53 +01:00
#include "global.h"
#include "event_data.h"
#include "pokedex.h"
2017-09-02 20:43:53 +01:00
#define SPECIAL_FLAGS_SIZE (NUM_SPECIAL_FLAGS / 8) // 8 flags per byte
#define TEMP_FLAGS_SIZE (NUM_TEMP_FLAGS / 8)
#define DAILY_FLAGS_SIZE (NUM_DAILY_FLAGS / 8)
#define TEMP_VARS_SIZE (NUM_TEMP_VARS * 2) // 1/2 var per byte
2017-09-02 21:31:37 +01:00
EWRAM_DATA u16 gSpecialVar_0x8000 = 0;
EWRAM_DATA u16 gSpecialVar_0x8001 = 0;
EWRAM_DATA u16 gSpecialVar_0x8002 = 0;
EWRAM_DATA u16 gSpecialVar_0x8003 = 0;
EWRAM_DATA u16 gSpecialVar_0x8004 = 0;
EWRAM_DATA u16 gSpecialVar_0x8005 = 0;
EWRAM_DATA u16 gSpecialVar_0x8006 = 0;
EWRAM_DATA u16 gSpecialVar_0x8007 = 0;
EWRAM_DATA u16 gSpecialVar_0x8008 = 0;
EWRAM_DATA u16 gSpecialVar_0x8009 = 0;
EWRAM_DATA u16 gSpecialVar_0x800A = 0;
EWRAM_DATA u16 gSpecialVar_0x800B = 0;
2017-11-11 00:12:18 +00:00
EWRAM_DATA u16 gSpecialVar_Result = 0;
EWRAM_DATA u16 gSpecialVar_LastTalked = 0;
EWRAM_DATA u16 gSpecialVar_Facing = 0;
2017-11-08 21:20:10 +00:00
EWRAM_DATA u16 gSpecialVar_MonBoxId = 0;
EWRAM_DATA u16 gSpecialVar_MonBoxPos = 0;
2019-02-28 04:54:51 +00:00
EWRAM_DATA u16 gSpecialVar_Unused_0x8014 = 0;
2022-05-17 18:51:54 +01:00
EWRAM_DATA static u8 sSpecialFlags[SPECIAL_FLAGS_SIZE] = {0};
2017-09-02 21:31:37 +01:00
2018-08-12 21:04:49 +01:00
extern u16 *const gSpecialVars[];
2017-09-02 21:31:37 +01:00
2017-09-02 20:43:53 +01:00
void InitEventData(void)
{
memset(gSaveBlock1Ptr->flags, 0, sizeof(gSaveBlock1Ptr->flags));
memset(gSaveBlock1Ptr->vars, 0, sizeof(gSaveBlock1Ptr->vars));
2022-05-17 18:51:54 +01:00
memset(sSpecialFlags, 0, sizeof(sSpecialFlags));
2017-09-02 20:43:53 +01:00
}
2017-09-02 21:31:37 +01:00
void ClearTempFieldEventData(void)
{
2023-08-04 19:17:28 +01:00
memset(&gSaveBlock1Ptr->flags[TEMP_FLAGS_START / 8], 0, TEMP_FLAGS_SIZE);
memset(&gSaveBlock1Ptr->vars[TEMP_VARS_START - VARS_START], 0, TEMP_VARS_SIZE);
2017-11-08 21:20:10 +00:00
FlagClear(FLAG_SYS_ENC_UP_ITEM);
FlagClear(FLAG_SYS_ENC_DOWN_ITEM);
FlagClear(FLAG_SYS_USE_STRENGTH);
FlagClear(FLAG_SYS_CTRL_OBJ_DELETE);
2019-01-02 21:12:43 +00:00
FlagClear(FLAG_NURSE_UNION_ROOM_REMINDER);
2017-09-02 21:31:37 +01:00
}
void ClearDailyFlags(void)
2017-09-02 21:31:37 +01:00
{
2023-08-04 19:17:28 +01:00
memset(&gSaveBlock1Ptr->flags[DAILY_FLAGS_START / 8], 0, DAILY_FLAGS_SIZE);
2017-09-02 21:31:37 +01:00
}
void DisableNationalPokedex(void)
{
u16 *nationalDexVar = GetVarPointer(VAR_NATIONAL_DEX);
gSaveBlock2Ptr->pokedex.nationalMagic = 0;
*nationalDexVar = 0;
2017-11-08 21:20:10 +00:00
FlagClear(FLAG_SYS_NATIONAL_DEX);
2017-09-02 21:31:37 +01:00
}
void EnableNationalPokedex(void)
{
u16 *nationalDexVar = GetVarPointer(VAR_NATIONAL_DEX);
gSaveBlock2Ptr->pokedex.nationalMagic = 0xDA;
*nationalDexVar = 0x302;
2017-11-08 21:20:10 +00:00
FlagSet(FLAG_SYS_NATIONAL_DEX);
gSaveBlock2Ptr->pokedex.mode = DEX_MODE_NATIONAL;
2017-09-02 21:31:37 +01:00
gSaveBlock2Ptr->pokedex.order = 0;
ResetPokedexScrollPositions();
2017-09-02 21:31:37 +01:00
}
bool32 IsNationalPokedexEnabled(void)
{
2017-11-08 21:20:10 +00:00
if (gSaveBlock2Ptr->pokedex.nationalMagic == 0xDA && VarGet(VAR_NATIONAL_DEX) == 0x302 && FlagGet(FLAG_SYS_NATIONAL_DEX))
2017-09-02 21:31:37 +01:00
return TRUE;
else
return FALSE;
}
void DisableMysteryEvent(void)
{
2017-11-08 21:20:10 +00:00
FlagClear(FLAG_SYS_MYSTERY_EVENT_ENABLE);
2017-09-02 21:31:37 +01:00
}
void EnableMysteryEvent(void)
{
2017-11-08 21:20:10 +00:00
FlagSet(FLAG_SYS_MYSTERY_EVENT_ENABLE);
2017-09-02 21:31:37 +01:00
}
bool32 IsMysteryEventEnabled(void)
{
2017-11-08 21:20:10 +00:00
return FlagGet(FLAG_SYS_MYSTERY_EVENT_ENABLE);
2017-09-02 21:31:37 +01:00
}
void DisableMysteryGift(void)
{
2017-11-08 21:20:10 +00:00
FlagClear(FLAG_SYS_MYSTERY_GIFT_ENABLE);
2017-09-02 21:31:37 +01:00
}
void EnableMysteryGift(void)
{
2017-11-08 21:20:10 +00:00
FlagSet(FLAG_SYS_MYSTERY_GIFT_ENABLE);
2017-09-02 21:31:37 +01:00
}
bool32 IsMysteryGiftEnabled(void)
{
2017-11-08 21:20:10 +00:00
return FlagGet(FLAG_SYS_MYSTERY_GIFT_ENABLE);
2017-09-02 21:31:37 +01:00
}
void ClearMysteryGiftFlags(void)
{
FlagClear(FLAG_MYSTERY_GIFT_DONE);
FlagClear(FLAG_MYSTERY_GIFT_1);
FlagClear(FLAG_MYSTERY_GIFT_2);
FlagClear(FLAG_MYSTERY_GIFT_3);
FlagClear(FLAG_MYSTERY_GIFT_4);
FlagClear(FLAG_MYSTERY_GIFT_5);
FlagClear(FLAG_MYSTERY_GIFT_6);
FlagClear(FLAG_MYSTERY_GIFT_7);
FlagClear(FLAG_MYSTERY_GIFT_8);
FlagClear(FLAG_MYSTERY_GIFT_9);
FlagClear(FLAG_MYSTERY_GIFT_10);
FlagClear(FLAG_MYSTERY_GIFT_11);
FlagClear(FLAG_MYSTERY_GIFT_12);
FlagClear(FLAG_MYSTERY_GIFT_13);
FlagClear(FLAG_MYSTERY_GIFT_14);
FlagClear(FLAG_MYSTERY_GIFT_15);
}
void ClearMysteryGiftVars(void)
{
VarSet(VAR_GIFT_PICHU_SLOT, 0);
VarSet(VAR_GIFT_UNUSED_1, 0);
VarSet(VAR_GIFT_UNUSED_2, 0);
VarSet(VAR_GIFT_UNUSED_3, 0);
VarSet(VAR_GIFT_UNUSED_4, 0);
VarSet(VAR_GIFT_UNUSED_5, 0);
VarSet(VAR_GIFT_UNUSED_6, 0);
VarSet(VAR_GIFT_UNUSED_7, 0);
2017-09-02 21:31:37 +01:00
}
void DisableResetRTC(void)
{
VarSet(VAR_RESET_RTC_ENABLE, 0);
2017-11-08 21:20:10 +00:00
FlagClear(FLAG_SYS_RESET_RTC_ENABLE);
2017-09-02 21:31:37 +01:00
}
void EnableResetRTC(void)
{
VarSet(VAR_RESET_RTC_ENABLE, 0x920);
2017-11-08 21:20:10 +00:00
FlagSet(FLAG_SYS_RESET_RTC_ENABLE);
2017-09-02 21:31:37 +01:00
}
bool32 CanResetRTC(void)
{
2017-11-08 21:20:10 +00:00
if (FlagGet(FLAG_SYS_RESET_RTC_ENABLE) && VarGet(VAR_RESET_RTC_ENABLE) == 0x920)
2017-09-02 21:31:37 +01:00
return TRUE;
else
return FALSE;
}
u16 *GetVarPointer(u16 id)
{
2018-08-11 21:54:34 +01:00
if (id < VARS_START)
2017-09-02 21:31:37 +01:00
return NULL;
2018-08-12 21:04:49 +01:00
else if (id < SPECIAL_VARS_START)
2018-08-11 21:54:34 +01:00
return &gSaveBlock1Ptr->vars[id - VARS_START];
2018-08-12 21:33:41 +01:00
else
return gSpecialVars[id - SPECIAL_VARS_START];
2017-09-02 21:31:37 +01:00
}
u16 VarGet(u16 id)
{
u16 *ptr = GetVarPointer(id);
if (!ptr)
return id;
return *ptr;
}
u16 VarGetIfExist(u16 id)
{
u16 *ptr = GetVarPointer(id);
if (!ptr)
return 65535;
return *ptr;
}
2017-09-02 21:31:37 +01:00
bool8 VarSet(u16 id, u16 value)
{
u16 *ptr = GetVarPointer(id);
if (!ptr)
return FALSE;
*ptr = value;
return TRUE;
}
u16 VarGetObjectEventGraphicsId(u8 id)
2017-09-02 21:31:37 +01:00
{
2018-08-11 21:54:34 +01:00
return VarGet(VAR_OBJ_GFX_ID_0 + id);
2017-09-02 21:31:37 +01:00
}
u8 *GetFlagPointer(u16 id)
{
if (id == 0)
2018-08-11 21:54:34 +01:00
return NULL;
2018-08-12 21:04:49 +01:00
else if (id < SPECIAL_FLAGS_START)
2017-09-02 21:31:37 +01:00
return &gSaveBlock1Ptr->flags[id / 8];
2018-08-12 21:33:41 +01:00
else
2022-05-17 18:51:54 +01:00
return &sSpecialFlags[(id - SPECIAL_FLAGS_START) / 8];
2017-09-02 21:31:37 +01:00
}
u8 FlagSet(u16 id)
{
u8 *ptr = GetFlagPointer(id);
if (ptr)
*ptr |= 1 << (id & 7);
return 0;
}
u8 FlagToggle(u16 id)
{
u8 *ptr = GetFlagPointer(id);
if (ptr)
*ptr ^= 1 << (id & 7);
return 0;
}
2017-10-12 08:06:19 +01:00
u8 FlagClear(u16 id)
2017-09-02 21:31:37 +01:00
{
u8 *ptr = GetFlagPointer(id);
if (ptr)
*ptr &= ~(1 << (id & 7));
return 0;
}
bool8 FlagGet(u16 id)
{
u8 *ptr = GetFlagPointer(id);
if (!ptr)
return FALSE;
if (!(((*ptr) >> (id & 7)) & 1))
return FALSE;
return TRUE;
}