1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
#include "global.h"
#include "gflib.h"
#include "pokemon_storage_system_internal.h"
#include "constants/species.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 CreateBoxMonAt(u8 boxId, u8 boxPosition, u16 species, u8 level, u8 fixedIV, u8 hasFixedPersonality, u32 personality, u8 otIDType, u32 otID)
{
if (boxId < TOTAL_BOXES_COUNT && boxPosition < IN_BOX_COUNT)
{
CreateBoxMon(&gPokemonStoragePtr->boxes[boxId][boxPosition],
species,
level,
fixedIV,
hasFixedPersonality, personality,
otIDType, otID);
}
}
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 currIndex, 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 = currIndex + adder; i >= 0 && i <= maxIndex; i += adder)
{
if (GetBoxMonData(&boxMons[i], MON_DATA_SPECIES) != SPECIES_NONE)
return i;
}
}
else
{
for (i = currIndex + 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;
}
|