mirror of
https://github.com/pret/pokefirered.git
synced 2026-05-15 16:50:01 -05:00
159 lines
4.3 KiB
C
159 lines
4.3 KiB
C
#include "global.h"
|
|
#include "gflib.h"
|
|
#include "pokemon_storage_system_internal.h"
|
|
|
|
void BackupPokemonStorage(struct PokemonStorage * dest)
|
|
{
|
|
*dest = *gPokemonStoragePtr;
|
|
}
|
|
|
|
void RestorePokemonStorage(struct PokemonStorage * src)
|
|
{
|
|
*gPokemonStoragePtr = *src;
|
|
}
|
|
|
|
// Functions here are general utility functions.
|
|
u8 StorageGetCurrentBox(void)
|
|
{
|
|
return gPokemonStoragePtr->currentBox;
|
|
}
|
|
|
|
void SetCurrentBox(u8 boxId)
|
|
{
|
|
if (boxId < TOTAL_BOXES_COUNT)
|
|
gPokemonStoragePtr->currentBox = boxId;
|
|
}
|
|
|
|
u32 GetBoxMonDataAt(u8 boxId, u8 boxPosition, s32 request)
|
|
{
|
|
if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
|
|
return GetBoxMonData(&gPokemonStoragePtr->boxes[boxId][boxPosition], request);
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
void SetBoxMonDataAt(u8 boxId, u8 boxPosition, s32 request, const void *value)
|
|
{
|
|
if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
|
|
SetBoxMonData(&gPokemonStoragePtr->boxes[boxId][boxPosition], request, value);
|
|
}
|
|
|
|
u32 GetCurrentBoxMonData(u8 boxPosition, s32 request)
|
|
{
|
|
return GetBoxMonDataAt(gPokemonStoragePtr->currentBox, boxPosition, request);
|
|
}
|
|
|
|
void SetCurrentBoxMonData(u8 boxPosition, s32 request, const void *value)
|
|
{
|
|
SetBoxMonDataAt(gPokemonStoragePtr->currentBox, boxPosition, request, value);
|
|
}
|
|
|
|
void GetBoxMonNickAt(u8 boxId, u8 boxPosition, u8 *dst)
|
|
{
|
|
if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
|
|
GetBoxMonData(&gPokemonStoragePtr->boxes[boxId][boxPosition], MON_DATA_NICKNAME, dst);
|
|
else
|
|
*dst = EOS;
|
|
}
|
|
|
|
void SetBoxMonNickAt(u8 boxId, u8 boxPosition, const u8 *nick)
|
|
{
|
|
if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
|
|
SetBoxMonData(&gPokemonStoragePtr->boxes[boxId][boxPosition], MON_DATA_NICKNAME, nick);
|
|
}
|
|
|
|
u32 GetAndCopyBoxMonDataAt(u8 boxId, u8 boxPosition, s32 request, void *dst)
|
|
{
|
|
if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
|
|
return GetBoxMonData(&gPokemonStoragePtr->boxes[boxId][boxPosition], request, dst);
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
void SetBoxMonAt(u8 boxId, u8 boxPosition, struct BoxPokemon * src)
|
|
{
|
|
if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
|
|
gPokemonStoragePtr->boxes[boxId][boxPosition] = *src;
|
|
}
|
|
|
|
void CopyBoxMonAt(u8 boxId, u8 boxPosition, struct BoxPokemon * dst)
|
|
{
|
|
if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
|
|
*dst = gPokemonStoragePtr->boxes[boxId][boxPosition];
|
|
}
|
|
|
|
void ZeroBoxMonAt(u8 boxId, u8 boxPosition)
|
|
{
|
|
if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
|
|
ZeroBoxMonData(&gPokemonStoragePtr->boxes[boxId][boxPosition]);
|
|
}
|
|
|
|
void BoxMonAtToMon(u8 boxId, u8 boxPosition, struct Pokemon * dst)
|
|
{
|
|
if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
|
|
BoxMonToMon(&gPokemonStoragePtr->boxes[boxId][boxPosition], dst);
|
|
}
|
|
|
|
struct BoxPokemon * GetBoxedMonPtr(u8 boxId, u8 boxPosition)
|
|
{
|
|
if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
|
|
return &gPokemonStoragePtr->boxes[boxId][boxPosition];
|
|
else
|
|
return NULL;
|
|
}
|
|
|
|
u8 *GetBoxNamePtr(u8 boxId)
|
|
{
|
|
if (boxId < TOTAL_BOXES_COUNT)
|
|
return gPokemonStoragePtr->boxNames[boxId];
|
|
else
|
|
return NULL;
|
|
}
|
|
|
|
u8 GetBoxWallpaper(u8 boxId)
|
|
{
|
|
if (boxId < TOTAL_BOXES_COUNT)
|
|
return gPokemonStoragePtr->boxWallpapers[boxId];
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
void SetBoxWallpaper(u8 boxId, u8 wallpaperId)
|
|
{
|
|
if (boxId < TOTAL_BOXES_COUNT && wallpaperId < WALLPAPER_COUNT)
|
|
gPokemonStoragePtr->boxWallpapers[boxId] = wallpaperId;
|
|
}
|
|
|
|
s16 SeekToNextMonInBox(struct BoxPokemon * boxMons, s8 curIndex, u8 maxIndex, u8 flags)
|
|
{
|
|
// flags:
|
|
// bit 0: Allow eggs
|
|
// bit 1: Search backwards
|
|
s16 i;
|
|
s16 adder;
|
|
if (flags == 0 || flags == 1)
|
|
adder = 1;
|
|
else
|
|
adder = -1;
|
|
|
|
if (flags == 1 || flags == 3)
|
|
{
|
|
for (i = curIndex + adder; i >= 0 && i <= maxIndex; i += adder)
|
|
{
|
|
if (GetBoxMonData(&boxMons[i], MON_DATA_SPECIES) != SPECIES_NONE)
|
|
return i;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (i = curIndex + adder; i >= 0 && i <= maxIndex; i += adder)
|
|
{
|
|
if (GetBoxMonData(&boxMons[i], MON_DATA_SPECIES) != SPECIES_NONE
|
|
&& !GetBoxMonData(&boxMons[i], MON_DATA_IS_EGG))
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|