Bag refactor (groundwork for expansion) (#7018)

This commit is contained in:
Nephrite 2025-06-18 11:59:24 +03:00 committed by GitHub
parent 97137aed2d
commit a18709fb47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 348 additions and 350 deletions

View File

@ -63,11 +63,6 @@
#define SECRET_BASES_COUNT 20
#define POKE_NEWS_COUNT 16
#define PC_ITEMS_COUNT 50
#define BAG_ITEMS_COUNT 30
#define BAG_KEYITEMS_COUNT 30
#define BAG_POKEBALLS_COUNT 16
#define BAG_TMHM_COUNT 64
#define BAG_BERRIES_COUNT 46
#define OBJECT_EVENT_TEMPLATES_COUNT 64
#define DECOR_MAX_SECRET_BASE 16
#define DECOR_MAX_PLAYERS_HOUSE 12
@ -81,6 +76,13 @@
#define PYRAMID_BAG_ITEMS_COUNT 10
#define ROAMER_COUNT 1 // Number of maximum concurrent active roamers
// Bag constants
#define BAG_ITEMS_COUNT 30
#define BAG_KEYITEMS_COUNT 30
#define BAG_POKEBALLS_COUNT 16
#define BAG_TMHM_COUNT 64
#define BAG_BERRIES_COUNT 46
// Number of facilities for Ranking Hall.
// 7 facilities for single mode + tower double mode + tower multi mode.
// Excludes link modes. See RANKING_HALL_* in include/constants/battle_frontier.h

View File

@ -1,20 +1,17 @@
#ifndef GUARD_ITEM_CONSTANTS_H
#define GUARD_ITEM_CONSTANTS_H
// These constants are used in gItemsInfo
#define POCKET_NONE 0
#define POCKET_ITEMS 1
#define POCKET_POKE_BALLS 2
#define POCKET_TM_HM 3
#define POCKET_BERRIES 4
#define POCKET_KEY_ITEMS 5
enum Pocket
{
POCKET_ITEMS,
POCKET_POKE_BALLS,
POCKET_TM_HM,
POCKET_BERRIES,
POCKET_KEY_ITEMS,
POCKETS_COUNT,
};
#define ITEMS_POCKET 0
#define BALLS_POCKET 1
#define TMHM_POCKET 2
#define BERRIES_POCKET 3
#define KEYITEMS_POCKET 4
#define POCKETS_COUNT 5
#define POCKET_NONE POCKETS_COUNT
#define REPEL_LURE_MASK (1 << 15)
#define IS_LAST_USED_LURE(var) (var & REPEL_LURE_MASK)

View File

@ -1043,6 +1043,15 @@ struct ExternalEventFlags
} __attribute__((packed));/*size = 0x15*/
struct Bag
{
struct ItemSlot items[BAG_ITEMS_COUNT];
struct ItemSlot keyItems[BAG_KEYITEMS_COUNT];
struct ItemSlot pokeBalls[BAG_POKEBALLS_COUNT];
struct ItemSlot TMsHMs[BAG_TMHM_COUNT];
struct ItemSlot berries[BAG_BERRIES_COUNT];
};
struct SaveBlock1
{
/*0x00*/ struct Coords16 pos;
@ -1065,11 +1074,8 @@ struct SaveBlock1
/*0x494*/ u16 coins;
/*0x496*/ u16 registeredItem; // registered for use with SELECT button
/*0x498*/ struct ItemSlot pcItems[PC_ITEMS_COUNT];
/*0x560*/ struct ItemSlot bagPocket_Items[BAG_ITEMS_COUNT];
/*0x5D8*/ struct ItemSlot bagPocket_KeyItems[BAG_KEYITEMS_COUNT];
/*0x650*/ struct ItemSlot bagPocket_PokeBalls[BAG_POKEBALLS_COUNT];
/*0x690*/ struct ItemSlot bagPocket_TMHM[BAG_TMHM_COUNT];
/*0x790*/ struct ItemSlot bagPocket_Berries[BAG_BERRIES_COUNT];
/*0x560 -> 0x848 is bag storage*/
/*0x560*/ struct Bag bag;
/*0x848*/ struct Pokeblock pokeblocks[POKEBLOCKS_COUNT];
#if FREE_EXTRA_SEEN_FLAGS_SAVEBLOCK1 == FALSE
/*0x988*/ u8 filler1[0x34]; // Previously Dex Flags, feel free to remove.

View File

@ -21,7 +21,7 @@ struct Item
u8 importance:2;
u8 notConsumed:1;
u8 padding:5;
u8 pocket;
enum Pocket pocket:8;
u8 type;
u8 battleUsage;
u8 flingPower;
@ -29,21 +29,23 @@ struct Item
const u16 *iconPalette;
};
struct BagPocket
struct __attribute__((packed, aligned(2))) BagPocket
{
struct ItemSlot *itemSlots;
u8 capacity;
u16 capacity;
};
extern const struct Item gItemsInfo[];
extern struct BagPocket gBagPockets[];
u16 GetBagItemId(enum Pocket pocketId, u32 pocketPos);
u16 GetBagItemQuantity(enum Pocket pocketId, u32 pocketPos);
void SetBagItemQuantity(enum Pocket pocketId, u32 pocketPos, u16 newValue);
void ApplyNewEncryptionKeyToBagItems(u32 newKey);
void ApplyNewEncryptionKeyToBagItems_(u32 newKey);
void SetBagItemsPointers(void);
u8 *CopyItemName(u16 itemId, u8 *dst);
u8 *CopyItemNameHandlePlural(u16 itemId, u8 *dst, u32 quantity);
bool8 IsBagPocketNonEmpty(u8 pocket);
bool8 IsBagPocketNonEmpty(enum Pocket pocketId);
bool8 CheckBagHasItem(u16 itemId, u16 count);
bool8 HasAtLeastOneBerry(void);
bool8 HasAtLeastOnePokeBall(void);
@ -51,19 +53,16 @@ bool8 CheckBagHasSpace(u16 itemId, u16 count);
u32 GetFreeSpaceForItemInBag(u16 itemId);
bool8 AddBagItem(u16 itemId, u16 count);
bool8 RemoveBagItem(u16 itemId, u16 count);
u8 GetPocketByItemId(u16 itemId);
void ClearItemSlots(struct ItemSlot *itemSlots, u8 itemCount);
u8 CountUsedPCItemSlots(void);
bool8 CheckPCHasItem(u16 itemId, u16 count);
bool8 AddPCItem(u16 itemId, u16 count);
void RemovePCItem(u8 index, u16 count);
void CompactPCItems(void);
void SwapRegisteredBike(void);
u16 BagGetItemIdByPocketPosition(u8 pocketId, u16 pocketPos);
u16 BagGetQuantityByPocketPosition(u8 pocketId, u16 pocketPos);
void CompactItemsInBagPocket(struct BagPocket *bagPocket);
void SortBerriesOrTMHMs(struct BagPocket *bagPocket);
void MoveItemSlotInList(struct ItemSlot *itemSlots_, u32 from, u32 to_);
void CompactItemsInBagPocket(enum Pocket pocketId);
void SortBerriesOrTMHMs(enum Pocket pocketId);
void MoveItemSlotInPocket(enum Pocket pocketId, u32 from, u32 to);
void MoveItemSlotInPC(struct ItemSlot *itemSlots, u32 from, u32 to);
void ClearBag(void);
u16 CountTotalItemQuantityInBag(u16 itemId);
bool8 AddPyramidBagItem(u16 itemId, u16 count);
@ -76,7 +75,7 @@ u32 GetItemHoldEffectParam(u32 itemId);
const u8 *GetItemDescription(u16 itemId);
u8 GetItemImportance(u16 itemId);
u8 GetItemConsumability(u16 itemId);
u8 GetItemPocket(u16 itemId);
enum Pocket GetItemPocket(u16 itemId);
u8 GetItemType(u16 itemId);
ItemUseFunc GetItemFieldFunc(u16 itemId);
u8 GetItemBattleUsage(u16 itemId);

View File

@ -876,5 +876,8 @@ uq4_12_t GetDynamaxLevelHPMultiplier(u32 dynamaxLevel, bool32 inverseMultiplier)
u32 GetRegionalFormByRegion(u32 species, u32 region);
bool32 IsSpeciesForeignRegionalForm(u32 species, u32 currentRegion);
u32 GetTeraTypeFromPersonality(struct Pokemon *mon);
struct Pokemon *GetSavedPlayerPartyMon(u32 index);
u8 *GetSavedPlayerPartyCount(void);
void SavePlayerPartyMon(u32 index, struct Pokemon *mon);
#endif // GUARD_POKEMON_H

View File

@ -2539,7 +2539,7 @@ static s32 AI_CheckBadMove(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)
}
break;
case EFFECT_NATURAL_GIFT:
if (!IsBattlerItemEnabled(battlerAtk) || GetPocketByItemId(gBattleMons[battlerAtk].item) != POCKET_BERRIES)
if (!IsBattlerItemEnabled(battlerAtk) || GetItemPocket(gBattleMons[battlerAtk].item) != POCKET_BERRIES)
ADJUST_SCORE(-10);
break;
case EFFECT_GRASSY_TERRAIN:

View File

@ -1827,7 +1827,7 @@ static u32 GetSwitchinHitsToKO(s32 damageTaken, u32 battler)
// Check if we're at a single use healing item threshold
if (gAiLogicData->switchinCandidate.battleMon.ability != ABILITY_KLUTZ && usedSingleUseHealingItem == FALSE
&& !(opposingAbility == ABILITY_UNNERVE && GetPocketByItemId(item) == POCKET_BERRIES))
&& !(opposingAbility == ABILITY_UNNERVE && GetItemPocket(item) == POCKET_BERRIES))
{
switch (heldItemEffect)
{

View File

@ -207,16 +207,16 @@ static u16 GetPrevBall(u16 ballId)
{
u16 ballPrev;
s32 i, j;
CompactItemsInBagPocket(&gBagPockets[BALLS_POCKET]);
for (i = 0; i < gBagPockets[BALLS_POCKET].capacity; i++)
CompactItemsInBagPocket(POCKET_POKE_BALLS);
for (i = 0; i < gBagPockets[POCKET_POKE_BALLS].capacity; i++)
{
if (ballId == gBagPockets[BALLS_POCKET].itemSlots[i].itemId)
if (ballId == GetBagItemId(POCKET_POKE_BALLS, i))
{
if (i <= 0)
{
for (j = gBagPockets[BALLS_POCKET].capacity - 1; j >= 0; j--)
for (j = gBagPockets[POCKET_POKE_BALLS].capacity - 1; j >= 0; j--)
{
ballPrev = gBagPockets[BALLS_POCKET].itemSlots[j].itemId;
ballPrev = GetBagItemId(POCKET_POKE_BALLS, j);
if (ballPrev != ITEM_NONE)
return ballPrev;
}
@ -225,24 +225,24 @@ static u16 GetPrevBall(u16 ballId)
break;
}
}
return gBagPockets[BALLS_POCKET].itemSlots[i].itemId;
return GetBagItemId(POCKET_POKE_BALLS, i);
}
static u32 GetNextBall(u32 ballId)
{
u32 ballNext = ITEM_NONE;
s32 i;
CompactItemsInBagPocket(&gBagPockets[BALLS_POCKET]);
for (i = 1; i < gBagPockets[BALLS_POCKET].capacity; i++)
CompactItemsInBagPocket(POCKET_POKE_BALLS);
for (i = 1; i < gBagPockets[POCKET_POKE_BALLS].capacity; i++)
{
if (ballId == gBagPockets[BALLS_POCKET].itemSlots[i-1].itemId)
if (ballId == GetBagItemId(POCKET_POKE_BALLS, i-1))
{
ballNext = gBagPockets[BALLS_POCKET].itemSlots[i].itemId;
ballNext = GetBagItemId(POCKET_POKE_BALLS, i);
break;
}
}
if (ballNext == ITEM_NONE)
return gBagPockets[BALLS_POCKET].itemSlots[0].itemId; // Zeroth slot
return GetBagItemId(POCKET_POKE_BALLS, 0); // Zeroth slot
else
return ballNext;
}

View File

@ -5680,7 +5680,7 @@ static void ResetSketchedMoves(void)
count = 0;
while (count < MAX_MON_MOVES)
{
if (GetMonData(&gSaveBlock1Ptr->playerParty[playerMonId], MON_DATA_MOVE1 + count, NULL) == GetMonData(&gPlayerParty[i], MON_DATA_MOVE1 + moveSlot, NULL))
if (GetMonData(GetSavedPlayerPartyMon(playerMonId), MON_DATA_MOVE1 + count, NULL) == GetMonData(&gPlayerParty[i], MON_DATA_MOVE1 + moveSlot, NULL))
break;
count++;
}
@ -5688,7 +5688,7 @@ static void ResetSketchedMoves(void)
SetMonMoveSlot(&gPlayerParty[i], MOVE_SKETCH, moveSlot);
}
gSaveBlock1Ptr->playerParty[playerMonId] = gPlayerParty[i];
SavePlayerPartyMon(playerMonId, &gPlayerParty[i]);
}
}
@ -5699,7 +5699,7 @@ static void RestoreDomePlayerPartyHeldItems(void)
for (i = 0; i < DOME_BATTLE_PARTY_SIZE; i++)
{
int playerMonId = gSaveBlock2Ptr->frontier.selectedPartyMons[gSelectedOrderFromParty[i] - 1] - 1;
u16 item = GetMonData(&gSaveBlock1Ptr->playerParty[playerMonId], MON_DATA_HELD_ITEM, NULL);
u16 item = GetMonData(GetSavedPlayerPartyMon(playerMonId), MON_DATA_HELD_ITEM, NULL);
SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &item);
}
}

View File

@ -2997,9 +2997,9 @@ void TryAddLastUsedBallItemSprites(void)
u16 firstBall;
// we have to compact the bag first bc it is typically only compacted when you open it
CompactItemsInBagPocket(&gBagPockets[BALLS_POCKET]);
CompactItemsInBagPocket(POCKET_POKE_BALLS);
firstBall = gBagPockets[BALLS_POCKET].itemSlots[0].itemId;
firstBall = GetBagItemId(POCKET_POKE_BALLS, 0);
if (firstBall > ITEM_NONE)
gBallToDisplay = firstBall;
}

View File

@ -1587,7 +1587,7 @@ static void SaveMonHeldItems(void)
for (i = 0; i < FRONTIER_PARTY_SIZE; i++)
{
int heldItem = GetMonData(&gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1],
int heldItem = GetMonData(GetSavedPlayerPartyMon(gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1),
MON_DATA_HELD_ITEM);
gSaveBlock2Ptr->frontier.pikeHeldItemsBackup[i] = heldItem;
}

View File

@ -1221,19 +1221,19 @@ static void RestorePyramidPlayerParty(void)
int partyIndex = gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1;
for (j = 0; j < FRONTIER_PARTY_SIZE; j++)
{
if (GetMonData(&gSaveBlock1Ptr->playerParty[partyIndex], MON_DATA_SPECIES, NULL) == GetMonData(&gPlayerParty[j], MON_DATA_SPECIES, NULL))
if (GetMonData(GetSavedPlayerPartyMon(partyIndex), MON_DATA_SPECIES, NULL) == GetMonData(&gPlayerParty[j], MON_DATA_SPECIES, NULL))
{
for (k = 0; k < MAX_MON_MOVES; k++)
{
for (l = 0; l < MAX_MON_MOVES; l++)
{
if (GetMonData(&gSaveBlock1Ptr->playerParty[partyIndex], MON_DATA_MOVE1 + l, NULL) == GetMonData(&gPlayerParty[j], MON_DATA_MOVE1 + k, NULL))
if (GetMonData(GetSavedPlayerPartyMon(partyIndex), MON_DATA_MOVE1 + l, NULL) == GetMonData(&gPlayerParty[j], MON_DATA_MOVE1 + k, NULL))
break;
}
if (l == MAX_MON_MOVES)
SetMonMoveSlot(&gPlayerParty[j], MOVE_SKETCH, k);
}
gSaveBlock1Ptr->playerParty[partyIndex] = gPlayerParty[j];
SavePlayerPartyMon(partyIndex, &gPlayerParty[j]);
gSelectedOrderFromParty[j] = partyIndex + 1;
break;
}

View File

@ -5260,9 +5260,9 @@ bool32 NoAliveMonsForPlayer(void)
{
for (i = 0; i < PARTY_SIZE; i++)
{
if (!GetMonData(&gSaveBlock1Ptr->playerParty[i], MON_DATA_SPECIES)
|| !GetMonData(&gSaveBlock1Ptr->playerParty[i], MON_DATA_HP)
|| GetMonData(&gSaveBlock1Ptr->playerParty[i], MON_DATA_IS_EGG))
if (!GetMonData(GetSavedPlayerPartyMon(i), MON_DATA_SPECIES)
|| !GetMonData(GetSavedPlayerPartyMon(i), MON_DATA_HP)
|| GetMonData(GetSavedPlayerPartyMon(i), MON_DATA_IS_EGG))
ineligibleMonsCount++;
}

View File

@ -1269,7 +1269,7 @@ static void SaveChangesToPlayerParty(void)
{
if ((participatedPokemon >> i & 1) == 1)
{
gSaveBlock1Ptr->playerParty[i] = gPlayerParty[j];
SavePlayerPartyMon(i, &gPlayerParty[j]);
j++;
}
}

View File

@ -1932,7 +1932,7 @@ static void HandleSpecialTrainerBattleEnd(void)
case SPECIAL_BATTLE_SECRET_BASE:
for (i = 0; i < PARTY_SIZE; i++)
{
u16 itemBefore = GetMonData(&gSaveBlock1Ptr->playerParty[i], MON_DATA_HELD_ITEM);
u16 itemBefore = GetMonData(GetSavedPlayerPartyMon(i), MON_DATA_HELD_ITEM);
SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &itemBefore);
}
break;
@ -1943,7 +1943,7 @@ static void HandleSpecialTrainerBattleEnd(void)
for (i = 0; i < 3; i++)
{
if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES))
gSaveBlock1Ptr->playerParty[i] = gPlayerParty[i];
SavePlayerPartyMon(i, &gPlayerParty[i]);
}
break;
}
@ -1998,7 +1998,7 @@ void DoSpecialTrainerBattle(void)
for (i = 0; i < PARTY_SIZE; i++)
{
u16 itemBefore = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM);
SetMonData(&gSaveBlock1Ptr->playerParty[i], MON_DATA_HELD_ITEM, &itemBefore);
SetMonData(GetSavedPlayerPartyMon(i), MON_DATA_HELD_ITEM, &itemBefore);
}
CreateTask(Task_StartBattleAfterTransition, 1);
PlayMapChosenOrBattleBGM(0);
@ -2769,11 +2769,11 @@ static void AwardBattleTowerRibbons(void)
partyIndex = gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1;
ribbons[i].partyIndex = partyIndex;
ribbons[i].count = 0;
if (!GetMonData(&gSaveBlock1Ptr->playerParty[partyIndex], ribbonType))
if (!GetMonData(GetSavedPlayerPartyMon(partyIndex), ribbonType))
{
gSpecialVar_Result = TRUE;
SetMonData(&gSaveBlock1Ptr->playerParty[partyIndex], ribbonType, &gSpecialVar_Result);
ribbons[i].count = GetRibbonCount(&gSaveBlock1Ptr->playerParty[partyIndex]);
SetMonData(GetSavedPlayerPartyMon(partyIndex), ribbonType, &gSpecialVar_Result);
ribbons[i].count = GetRibbonCount(GetSavedPlayerPartyMon(partyIndex));
}
}
}
@ -2792,7 +2792,7 @@ static void AwardBattleTowerRibbons(void)
}
if (ribbons[0].count > NUM_CUTIES_RIBBONS)
{
TryPutSpotTheCutiesOnAir(&gSaveBlock1Ptr->playerParty[ribbons[0].partyIndex], ribbonType);
TryPutSpotTheCutiesOnAir(GetSavedPlayerPartyMon(ribbons[0].partyIndex), ribbonType);
}
}
}

View File

@ -563,9 +563,9 @@ static void Task_HandleInput(u8 taskId)
static void TryChangeDisplayedBerry(u8 taskId, s8 toMove)
{
s16 *data = gTasks[taskId].data;
s16 currPocketPosition = gBagPosition.scrollPosition[BERRIES_POCKET] + gBagPosition.cursorPosition[BERRIES_POCKET];
s16 currPocketPosition = gBagPosition.scrollPosition[POCKET_BERRIES] + gBagPosition.cursorPosition[POCKET_BERRIES];
u32 newPocketPosition = currPocketPosition + toMove;
if (newPocketPosition < ITEM_TO_BERRY(LAST_BERRY_INDEX) && BagGetItemIdByPocketPosition(POCKET_BERRIES, newPocketPosition) != ITEM_NONE)
if (newPocketPosition < ITEM_TO_BERRY(LAST_BERRY_INDEX) && GetBagItemId(POCKET_BERRIES, newPocketPosition) != ITEM_NONE)
{
if (toMove < 0)
tBgOp = BG_COORD_SUB;
@ -581,11 +581,11 @@ static void TryChangeDisplayedBerry(u8 taskId, s8 toMove)
static void HandleBagCursorPositionChange(s8 toMove)
{
u16 *scrollPos = &gBagPosition.scrollPosition[BERRIES_POCKET];
u16 *cursorPos = &gBagPosition.cursorPosition[BERRIES_POCKET];
u16 *scrollPos = &gBagPosition.scrollPosition[POCKET_BERRIES];
u16 *cursorPos = &gBagPosition.cursorPosition[POCKET_BERRIES];
if (toMove > 0)
{
if (*cursorPos < 4 || BagGetItemIdByPocketPosition(POCKET_BERRIES, *scrollPos + 8) == 0)
if (*cursorPos < 4 || GetBagItemId(POCKET_BERRIES, *scrollPos + 8) == 0)
*cursorPos += toMove;
else
*scrollPos += toMove;
@ -598,7 +598,7 @@ static void HandleBagCursorPositionChange(s8 toMove)
*scrollPos += toMove;
}
sBerryTag->berryId = ItemIdToBerryType(BagGetItemIdByPocketPosition(POCKET_BERRIES, *scrollPos + *cursorPos));
sBerryTag->berryId = ItemIdToBerryType(GetBagItemId(POCKET_BERRIES, *scrollPos + *cursorPos));
}
#define DISPLAY_SPEED 16

View File

@ -913,7 +913,7 @@ static void SaveSelectedParty(void)
{
u16 monId = gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1;
if (monId < PARTY_SIZE)
gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1] = gPlayerParty[i];
SavePlayerPartyMon(gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1, &gPlayerParty[i]);
}
}
@ -2165,7 +2165,7 @@ static void RestoreHeldItems(void)
{
if (gSaveBlock2Ptr->frontier.selectedPartyMons[i] != 0)
{
u16 item = GetMonData(&gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1], MON_DATA_HELD_ITEM, NULL);
u16 item = GetMonData(GetSavedPlayerPartyMon(gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1), MON_DATA_HELD_ITEM, NULL);
SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &item);
}
}
@ -2203,14 +2203,14 @@ static void ResetSketchedMoves(void)
{
for (k = 0; k < MAX_MON_MOVES; k++)
{
if (GetMonData(&gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1], MON_DATA_MOVE1 + k, NULL)
if (GetMonData(GetSavedPlayerPartyMon(gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1), MON_DATA_MOVE1 + k, NULL)
== GetMonData(&gPlayerParty[i], MON_DATA_MOVE1 + j, NULL))
break;
}
if (k == MAX_MON_MOVES)
SetMonMoveSlot(&gPlayerParty[i], MOVE_SKETCH, j);
}
gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1] = gPlayerParty[i];
SavePlayerPartyMon(gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1, &gPlayerParty[i]);
}
}
}

View File

@ -31,14 +31,44 @@ EWRAM_DATA struct BagPocket gBagPockets[POCKETS_COUNT] = {0};
#include "data/pokemon/item_effects.h"
#include "data/items.h"
static u16 GetBagItemQuantity(u16 *quantity)
static inline u16 GetBagItemIdPocket(struct BagPocket *pocket, u32 pocketPos)
{
return gSaveBlock2Ptr->encryptionKey ^ *quantity;
return pocket->itemSlots[pocketPos].itemId;
}
static void SetBagItemQuantity(u16 *quantity, u16 newValue)
static inline u16 GetBagItemQuantityPocket(struct BagPocket *pocket, u32 pocketPos)
{
*quantity = newValue ^ gSaveBlock2Ptr->encryptionKey;
return gSaveBlock2Ptr->encryptionKey ^ pocket->itemSlots[pocketPos].quantity;
}
static inline void SetBagItemIdPocket(struct BagPocket *pocket, u32 pocketPos, u16 itemId)
{
pocket->itemSlots[pocketPos].itemId = itemId;
}
static inline void SetBagItemQuantityPocket(struct BagPocket *pocket, u32 pocketPos, u16 newValue)
{
pocket->itemSlots[pocketPos].quantity = newValue ^ gSaveBlock2Ptr->encryptionKey;
}
u16 GetBagItemId(enum Pocket pocketId, u32 pocketPos)
{
return GetBagItemIdPocket(&gBagPockets[pocketId], pocketPos);
}
u16 GetBagItemQuantity(enum Pocket pocketId, u32 pocketPos)
{
return GetBagItemQuantityPocket(&gBagPockets[pocketId], pocketPos);
}
static void SetBagItemId(enum Pocket pocketId, u32 pocketPos, u16 itemId)
{
SetBagItemIdPocket(&gBagPockets[pocketId], pocketPos, itemId);
}
void SetBagItemQuantity(enum Pocket pocketId, u32 pocketPos, u16 newValue)
{
SetBagItemQuantityPocket(&gBagPockets[pocketId], pocketPos, newValue);
}
static u16 GetPCItemQuantity(u16 *quantity)
@ -53,35 +83,31 @@ static void SetPCItemQuantity(u16 *quantity, u16 newValue)
void ApplyNewEncryptionKeyToBagItems(u32 newKey)
{
u32 pocket, item;
for (pocket = 0; pocket < POCKETS_COUNT; pocket++)
enum Pocket pocketId;
u32 item;
for (pocketId = 0; pocketId < POCKETS_COUNT; pocketId++)
{
for (item = 0; item < gBagPockets[pocket].capacity; item++)
ApplyNewEncryptionKeyToHword(&(gBagPockets[pocket].itemSlots[item].quantity), newKey);
for (item = 0; item < gBagPockets[pocketId].capacity; item++)
ApplyNewEncryptionKeyToHword(&(gBagPockets[pocketId].itemSlots[item].quantity), newKey);
}
}
void ApplyNewEncryptionKeyToBagItems_(u32 newKey) // really GF?
{
ApplyNewEncryptionKeyToBagItems(newKey);
}
void SetBagItemsPointers(void)
{
gBagPockets[ITEMS_POCKET].itemSlots = gSaveBlock1Ptr->bagPocket_Items;
gBagPockets[ITEMS_POCKET].capacity = BAG_ITEMS_COUNT;
gBagPockets[POCKET_ITEMS].itemSlots = gSaveBlock1Ptr->bag.items;
gBagPockets[POCKET_ITEMS].capacity = BAG_ITEMS_COUNT;
gBagPockets[KEYITEMS_POCKET].itemSlots = gSaveBlock1Ptr->bagPocket_KeyItems;
gBagPockets[KEYITEMS_POCKET].capacity = BAG_KEYITEMS_COUNT;
gBagPockets[POCKET_KEY_ITEMS].itemSlots = gSaveBlock1Ptr->bag.keyItems;
gBagPockets[POCKET_KEY_ITEMS].capacity = BAG_KEYITEMS_COUNT;
gBagPockets[BALLS_POCKET].itemSlots = gSaveBlock1Ptr->bagPocket_PokeBalls;
gBagPockets[BALLS_POCKET].capacity = BAG_POKEBALLS_COUNT;
gBagPockets[POCKET_POKE_BALLS].itemSlots = gSaveBlock1Ptr->bag.pokeBalls;
gBagPockets[POCKET_POKE_BALLS].capacity = BAG_POKEBALLS_COUNT;
gBagPockets[TMHM_POCKET].itemSlots = gSaveBlock1Ptr->bagPocket_TMHM;
gBagPockets[TMHM_POCKET].capacity = BAG_TMHM_COUNT;
gBagPockets[POCKET_TM_HM].itemSlots = gSaveBlock1Ptr->bag.TMsHMs;
gBagPockets[POCKET_TM_HM].capacity = BAG_TMHM_COUNT;
gBagPockets[BERRIES_POCKET].itemSlots = gSaveBlock1Ptr->bagPocket_Berries;
gBagPockets[BERRIES_POCKET].capacity = BAG_BERRIES_COUNT;
gBagPockets[POCKET_BERRIES].itemSlots = gSaveBlock1Ptr->bag.berries;
gBagPockets[POCKET_BERRIES].capacity = BAG_BERRIES_COUNT;
}
u8 *CopyItemName(u16 itemId, u8 *dst)
@ -108,13 +134,13 @@ u8 *CopyItemNameHandlePlural(u16 itemId, u8 *dst, u32 quantity)
}
}
bool8 IsBagPocketNonEmpty(u8 pocket)
bool8 IsBagPocketNonEmpty(enum Pocket pocketId)
{
u8 i;
for (i = 0; i < gBagPockets[pocket - 1].capacity; i++)
for (i = 0; i < gBagPockets[pocketId].capacity; i++)
{
if (gBagPockets[pocket - 1].itemSlots[i].itemId != 0)
if (GetBagItemId(pocketId, i) != 0)
return TRUE;
}
return FALSE;
@ -123,21 +149,21 @@ bool8 IsBagPocketNonEmpty(u8 pocket)
bool8 CheckBagHasItem(u16 itemId, u16 count)
{
u8 i;
u8 pocket;
enum Pocket pocketId;
if (GetItemPocket(itemId) == 0)
if (GetItemPocket(itemId) >= POCKETS_COUNT)
return FALSE;
if (InBattlePyramid() || FlagGet(FLAG_STORING_ITEMS_IN_PYRAMID_BAG) == TRUE)
return CheckPyramidBagHasItem(itemId, count);
pocket = GetItemPocket(itemId) - 1;
pocketId = GetItemPocket(itemId);
// Check for item slots that contain the item
for (i = 0; i < gBagPockets[pocket].capacity; i++)
for (i = 0; i < gBagPockets[pocketId].capacity; i++)
{
if (gBagPockets[pocket].itemSlots[i].itemId == itemId)
if (GetBagItemId(pocketId, i) == itemId)
{
u16 quantity;
// Does this item slot contain enough of the item?
quantity = GetBagItemQuantity(&gBagPockets[pocket].itemSlots[i].quantity);
quantity = GetBagItemQuantity(pocketId, i);
if (quantity >= count)
return TRUE;
count -= quantity;
@ -179,7 +205,7 @@ bool8 HasAtLeastOnePokeBall(void)
bool8 CheckBagHasSpace(u16 itemId, u16 count)
{
if (GetItemPocket(itemId) == POCKET_NONE)
if (GetItemPocket(itemId) >= POCKETS_COUNT)
return FALSE;
if (InBattlePyramid() || FlagGet(FLAG_STORING_ITEMS_IN_PYRAMID_BAG) == TRUE)
@ -191,22 +217,23 @@ bool8 CheckBagHasSpace(u16 itemId, u16 count)
u32 GetFreeSpaceForItemInBag(u16 itemId)
{
u8 i;
u8 pocket = GetItemPocket(itemId) - 1;
enum Pocket pocketId = GetItemPocket(itemId);
u16 ownedCount;
u32 spaceForItem = 0;
if (GetItemPocket(itemId) == POCKET_NONE)
if (GetItemPocket(itemId) >= POCKETS_COUNT)
return 0;
// Check space in any existing item slots that already contain this item
for (i = 0; i < gBagPockets[pocket].capacity; i++)
for (i = 0; i < gBagPockets[pocketId].capacity; i++)
{
if (gBagPockets[pocket].itemSlots[i].itemId == itemId)
if (GetBagItemId(pocketId, i) == itemId)
{
ownedCount = GetBagItemQuantity(&gBagPockets[pocket].itemSlots[i].quantity);
ownedCount = GetBagItemQuantity(pocketId, i);
spaceForItem += max(0, MAX_BAG_ITEM_CAPACITY - ownedCount);
}
else if (gBagPockets[pocket].itemSlots[i].itemId == ITEM_NONE)
else if (GetBagItemId(pocketId, i) == ITEM_NONE)
{
spaceForItem += MAX_BAG_ITEM_CAPACITY;
}
@ -214,11 +241,33 @@ u32 GetFreeSpaceForItemInBag(u16 itemId)
return spaceForItem;
}
static inline u32 PrepareTempPocket(struct BagPocket *tempPocket, enum Pocket pocketId)
{
u32 size = gBagPockets[pocketId].capacity * sizeof(struct ItemSlot);
tempPocket->itemSlots = AllocZeroed(size);
tempPocket->capacity = gBagPockets[pocketId].capacity;
memcpy(tempPocket->itemSlots, gBagPockets[pocketId].itemSlots, size);
return size;
}
static inline void ClearTempPocket(struct BagPocket *pocket)
{
Free(pocket->itemSlots);
Free(pocket);
}
static inline void RestorePocketAndClearTempPocket(struct BagPocket *tempPocket, enum Pocket pocketId, u32 pocketSize)
{
memcpy(gBagPockets[pocketId].itemSlots, tempPocket->itemSlots, pocketSize);
ClearTempPocket(tempPocket);
}
bool8 AddBagItem(u16 itemId, u16 count)
{
u8 i;
if (GetItemPocket(itemId) == POCKET_NONE)
if (GetItemPocket(itemId) >= POCKETS_COUNT)
return FALSE;
// check Battle Pyramid Bag
@ -228,41 +277,36 @@ bool8 AddBagItem(u16 itemId, u16 count)
}
else
{
struct BagPocket *itemPocket;
struct ItemSlot *newItems;
u16 ownedCount;
u8 pocket = GetItemPocket(itemId) - 1;
enum Pocket pocketId = GetItemPocket(itemId);
struct BagPocket *tempPocket = AllocZeroed(sizeof(struct BagPocket));
u32 pocketSize = PrepareTempPocket(tempPocket, pocketId);
itemPocket = &gBagPockets[pocket];
newItems = AllocZeroed(itemPocket->capacity * sizeof(struct ItemSlot));
memcpy(newItems, itemPocket->itemSlots, itemPocket->capacity * sizeof(struct ItemSlot));
for (i = 0; i < itemPocket->capacity; i++)
for (i = 0; i < gBagPockets[pocketId].capacity; i++)
{
if (newItems[i].itemId == itemId)
if (GetBagItemIdPocket(tempPocket, i) == itemId)
{
ownedCount = GetBagItemQuantity(&newItems[i].quantity);
ownedCount = GetBagItemQuantityPocket(tempPocket, i);
// check if won't exceed max slot capacity
if (ownedCount + count <= MAX_BAG_ITEM_CAPACITY)
{
// successfully added to already existing item's count
SetBagItemQuantity(&newItems[i].quantity, ownedCount + count);
memcpy(itemPocket->itemSlots, newItems, itemPocket->capacity * sizeof(struct ItemSlot));
Free(newItems);
SetBagItemQuantityPocket(tempPocket, i, ownedCount + count);
RestorePocketAndClearTempPocket(tempPocket, pocketId, pocketSize);
return TRUE;
}
else
{
// try creating another instance of the item if possible
if (pocket == TMHM_POCKET || pocket == BERRIES_POCKET)
if (pocketId == POCKET_TM_HM || pocketId == POCKET_BERRIES)
{
Free(newItems);
ClearTempPocket(tempPocket);
return FALSE;
}
else
{
count -= MAX_BAG_ITEM_CAPACITY - ownedCount;
SetBagItemQuantity(&newItems[i].quantity, MAX_BAG_ITEM_CAPACITY);
SetBagItemQuantityPocket(tempPocket, i, MAX_BAG_ITEM_CAPACITY);
// don't create another instance of the item if it's at max slot capacity and count is equal to 0
if (count == 0)
{
@ -277,26 +321,26 @@ bool8 AddBagItem(u16 itemId, u16 count)
if (count > 0)
{
// either no existing item was found or we have to create another instance, because the capacity was exceeded
for (i = 0; i < itemPocket->capacity; i++)
for (i = 0; i < gBagPockets[pocketId].capacity; i++)
{
if (newItems[i].itemId == ITEM_NONE)
if (GetBagItemIdPocket(tempPocket, i) == ITEM_NONE)
{
newItems[i].itemId = itemId;
SetBagItemIdPocket(tempPocket, i, itemId);
if (count > MAX_BAG_ITEM_CAPACITY)
{
// try creating a new slot with max capacity if duplicates are possible
if (pocket == TMHM_POCKET || pocket == BERRIES_POCKET)
if (pocketId == POCKET_TM_HM || pocketId == POCKET_BERRIES)
{
Free(newItems);
ClearTempPocket(tempPocket);
return FALSE;
}
count -= MAX_BAG_ITEM_CAPACITY;
SetBagItemQuantity(&newItems[i].quantity, MAX_BAG_ITEM_CAPACITY);
SetBagItemQuantityPocket(tempPocket, i, MAX_BAG_ITEM_CAPACITY);
}
else
{
// created a new slot and added quantity
SetBagItemQuantity(&newItems[i].quantity, count);
SetBagItemQuantityPocket(tempPocket, i, count);
count = 0;
break;
}
@ -305,12 +349,11 @@ bool8 AddBagItem(u16 itemId, u16 count)
if (count > 0)
{
Free(newItems);
ClearTempPocket(tempPocket);
return FALSE;
}
}
memcpy(itemPocket->itemSlots, newItems, itemPocket->capacity * sizeof(struct ItemSlot));
Free(newItems);
RestorePocketAndClearTempPocket(tempPocket, pocketId, pocketSize);
return TRUE;
}
}
@ -320,7 +363,7 @@ bool8 RemoveBagItem(u16 itemId, u16 count)
u8 i;
u16 totalQuantity = 0;
if (GetItemPocket(itemId) == POCKET_NONE || itemId == ITEM_NONE)
if (GetItemPocket(itemId) >= POCKETS_COUNT || itemId == ITEM_NONE)
return FALSE;
// check Battle Pyramid Bag
@ -330,18 +373,17 @@ bool8 RemoveBagItem(u16 itemId, u16 count)
}
else
{
u8 pocket;
u8 var;
u16 ownedCount;
struct BagPocket *itemPocket;
u16 ownedCount, firstStackIndex = 0;
enum Pocket pocketId = GetItemPocket(itemId);
pocket = GetItemPocket(itemId) - 1;
itemPocket = &gBagPockets[pocket];
for (i = 0; i < itemPocket->capacity; i++)
for (i = 0; i < gBagPockets[pocketId].capacity; i++)
{
if (itemPocket->itemSlots[i].itemId == itemId)
totalQuantity += GetBagItemQuantity(&itemPocket->itemSlots[i].quantity);
if (GetBagItemId(pocketId, i) == itemId)
{
if (totalQuantity == 0)
firstStackIndex = i;
totalQuantity += GetBagItemQuantity(pocketId, i);
}
}
if (totalQuantity < count)
@ -353,47 +395,24 @@ bool8 RemoveBagItem(u16 itemId, u16 count)
VarSet(VAR_SECRET_BASE_LAST_ITEM_USED, itemId);
}
var = GetItemListPosition(pocket);
if (itemPocket->capacity > var
&& itemPocket->itemSlots[var].itemId == itemId)
for (i = firstStackIndex; i < gBagPockets[pocketId].capacity; i++)
{
ownedCount = GetBagItemQuantity(&itemPocket->itemSlots[var].quantity);
if (ownedCount >= count)
if (GetBagItemId(pocketId, i) == itemId)
{
SetBagItemQuantity(&itemPocket->itemSlots[var].quantity, ownedCount - count);
count = 0;
}
else
{
count -= ownedCount;
SetBagItemQuantity(&itemPocket->itemSlots[var].quantity, 0);
}
if (GetBagItemQuantity(&itemPocket->itemSlots[var].quantity) == 0)
itemPocket->itemSlots[var].itemId = ITEM_NONE;
if (count == 0)
return TRUE;
}
for (i = 0; i < itemPocket->capacity; i++)
{
if (itemPocket->itemSlots[i].itemId == itemId)
{
ownedCount = GetBagItemQuantity(&itemPocket->itemSlots[i].quantity);
ownedCount = GetBagItemQuantity(pocketId, i);
if (ownedCount >= count)
{
SetBagItemQuantity(&itemPocket->itemSlots[i].quantity, ownedCount - count);
SetBagItemQuantity(pocketId, i, ownedCount - count);
count = 0;
}
else
{
count -= ownedCount;
SetBagItemQuantity(&itemPocket->itemSlots[i].quantity, 0);
SetBagItemQuantity(pocketId, i, 0);
}
if (GetBagItemQuantity(&itemPocket->itemSlots[i].quantity) == 0)
itemPocket->itemSlots[i].itemId = ITEM_NONE;
if (GetBagItemQuantity(pocketId, i) == 0)
SetBagItemId(pocketId, i, ITEM_NONE);
if (count == 0)
return TRUE;
@ -403,22 +422,6 @@ bool8 RemoveBagItem(u16 itemId, u16 count)
}
}
u8 GetPocketByItemId(u16 itemId)
{
return GetItemPocket(itemId);
}
void ClearItemSlots(struct ItemSlot *itemSlots, u8 itemCount)
{
u16 i;
for (i = 0; i < itemCount; i++)
{
itemSlots[i].itemId = ITEM_NONE;
SetBagItemQuantity(&itemSlots[i].quantity, 0);
}
}
static s32 FindFreePCItemSlot(void)
{
s8 i;
@ -555,62 +558,81 @@ void SwapRegisteredBike(void)
}
}
u16 BagGetItemIdByPocketPosition(u8 pocketId, u16 pocketPos)
static void SwapItemSlots(enum Pocket pocketId, u32 pocketPosA, u16 pocketPosB)
{
return gBagPockets[pocketId - 1].itemSlots[pocketPos].itemId;
struct ItemSlot *itemA = &gBagPockets[pocketId].itemSlots[pocketPosA],
*itemB = &gBagPockets[pocketId].itemSlots[pocketPosB],
temp;
SWAP(*itemA, *itemB, temp);
}
u16 BagGetQuantityByPocketPosition(u8 pocketId, u16 pocketPos)
{
return GetBagItemQuantity(&gBagPockets[pocketId - 1].itemSlots[pocketPos].quantity);
}
static void SwapItemSlots(struct ItemSlot *a, struct ItemSlot *b)
{
struct ItemSlot temp;
SWAP(*a, *b, temp);
}
void CompactItemsInBagPocket(struct BagPocket *bagPocket)
void CompactItemsInBagPocket(enum Pocket pocketId)
{
u16 i, j;
for (i = 0; i < bagPocket->capacity - 1; i++)
for (i = 0; i < gBagPockets[pocketId].capacity - 1; i++)
{
for (j = i + 1; j < bagPocket->capacity; j++)
for (j = i + 1; j < gBagPockets[pocketId].capacity; j++)
{
if (GetBagItemQuantity(&bagPocket->itemSlots[i].quantity) == 0)
SwapItemSlots(&bagPocket->itemSlots[i], &bagPocket->itemSlots[j]);
if (GetBagItemQuantity(pocketId, i) == 0)
SwapItemSlots(pocketId, i, j);
}
}
}
void SortBerriesOrTMHMs(struct BagPocket *bagPocket)
void SortBerriesOrTMHMs(enum Pocket pocketId)
{
u16 i, j;
for (i = 0; i < bagPocket->capacity - 1; i++)
for (i = 0; i < gBagPockets[pocketId].capacity - 1; i++)
{
for (j = i + 1; j < bagPocket->capacity; j++)
for (j = i + 1; j < gBagPockets[pocketId].capacity; j++)
{
if (GetBagItemQuantity(&bagPocket->itemSlots[i].quantity) != 0)
if (GetBagItemQuantity(pocketId, i) != 0)
{
if (GetBagItemQuantity(&bagPocket->itemSlots[j].quantity) == 0)
if (GetBagItemQuantity(pocketId, j) == 0)
continue;
if (bagPocket->itemSlots[i].itemId <= bagPocket->itemSlots[j].itemId)
if (GetBagItemId(pocketId, i) <= GetBagItemId(pocketId, j))
continue;
}
SwapItemSlots(&bagPocket->itemSlots[i], &bagPocket->itemSlots[j]);
SwapItemSlots(pocketId, i, j);
}
}
}
void MoveItemSlotInList(struct ItemSlot *itemSlots_, u32 from, u32 to_)
void MoveItemSlotInPocket(enum Pocket pocketId, u32 from, u32 to)
{
// dumb assignments needed to match
struct ItemSlot *itemSlots = itemSlots_;
u32 to = to_;
if (from != to)
{
u32 i;
s8 shift = -1;
struct BagPocket *pocket = &gBagPockets[pocketId];
// Record the values at "from"
u16 fromItemId = GetBagItemIdPocket(pocket, from),
fromQuantity = GetBagItemQuantityPocket(pocket, from);
// Shuffle items between "to" and "from"
if (to > from)
{
to--;
shift = 1;
}
for (i = from; i == to - shift; i += shift)
{
SetBagItemIdPocket(pocket, i, GetBagItemIdPocket(pocket, i + shift));
SetBagItemQuantityPocket(pocket, i, GetBagItemQuantityPocket(pocket, i + shift));
}
// Move the saved "from" to "to"
SetBagItemIdPocket(pocket, to, fromItemId);
SetBagItemQuantityPocket(pocket, to, fromQuantity);
}
}
void MoveItemSlotInPC(struct ItemSlot *itemSlots, u32 from, u32 to)
{
if (from != to)
{
s16 i, count;
@ -633,24 +655,19 @@ void MoveItemSlotInList(struct ItemSlot *itemSlots_, u32 from, u32 to_)
void ClearBag(void)
{
u16 i;
for (i = 0; i < POCKETS_COUNT; i++)
{
ClearItemSlots(gBagPockets[i].itemSlots, gBagPockets[i].capacity);
}
CpuFastFill(0, &gSaveBlock1Ptr->bag, sizeof(struct Bag));
}
u16 CountTotalItemQuantityInBag(u16 itemId)
{
u16 i;
u16 ownedCount = 0;
struct BagPocket *bagPocket = &gBagPockets[GetItemPocket(itemId) - 1];
enum Pocket pocketId = GetItemPocket(itemId);
for (i = 0; i < bagPocket->capacity; i++)
for (i = 0; i < gBagPockets[pocketId].capacity; i++)
{
if (bagPocket->itemSlots[i].itemId == itemId)
ownedCount += GetBagItemQuantity(&bagPocket->itemSlots[i].quantity);
if (GetBagItemId(pocketId, i) == itemId)
ownedCount += GetBagItemQuantity(pocketId, i);
}
return ownedCount;
@ -922,7 +939,7 @@ u8 GetItemConsumability(u16 itemId)
return !gItemsInfo[SanitizeItemId(itemId)].notConsumed;
}
u8 GetItemPocket(u16 itemId)
enum Pocket GetItemPocket(u16 itemId)
{
return gItemsInfo[SanitizeItemId(itemId)].pocket;
}

View File

@ -561,7 +561,7 @@ static EWRAM_DATA struct TempWallyBag *sTempWallyBag = 0;
void ResetBagScrollPositions(void)
{
gBagPosition.pocket = ITEMS_POCKET;
gBagPosition.pocket = POCKET_ITEMS;
memset(gBagPosition.cursorPosition, 0, sizeof(gBagPosition.cursorPosition));
memset(gBagPosition.scrollPosition, 0, sizeof(gBagPosition.scrollPosition));
}
@ -582,19 +582,19 @@ void CB2_BagMenuFromBattle(void)
// Choosing berry to plant
void CB2_ChooseBerry(void)
{
GoToBagMenu(ITEMMENULOCATION_BERRY_TREE, BERRIES_POCKET, CB2_ReturnToFieldContinueScript);
GoToBagMenu(ITEMMENULOCATION_BERRY_TREE, POCKET_BERRIES, CB2_ReturnToFieldContinueScript);
}
// Choosing mulch to use
void CB2_ChooseMulch(void)
{
GoToBagMenu(ITEMMENULOCATION_BERRY_TREE_MULCH, ITEMS_POCKET, CB2_ReturnToFieldContinueScript);
GoToBagMenu(ITEMMENULOCATION_BERRY_TREE_MULCH, POCKET_ITEMS, CB2_ReturnToFieldContinueScript);
}
// Choosing berry for Berry Blender or Berry Crush
void ChooseBerryForMachine(void (*exitCallback)(void))
{
GoToBagMenu(ITEMMENULOCATION_BERRY_BLENDER_CRUSH, BERRIES_POCKET, exitCallback);
GoToBagMenu(ITEMMENULOCATION_BERRY_BLENDER_CRUSH, POCKET_BERRIES, exitCallback);
}
void CB2_GoToSellMenu(void)
@ -876,14 +876,13 @@ static void AllocateBagItemListBuffers(void)
static void LoadBagItemListBuffers(u8 pocketId)
{
u16 i;
struct BagPocket *pocket = &gBagPockets[pocketId];
struct ListMenuItem *subBuffer;
if (!gBagMenu->hideCloseBagText)
{
for (i = 0; i < gBagMenu->numItemStacks[pocketId] - 1; i++)
{
GetItemNameFromPocket(sListBuffer2->name[i], pocket->itemSlots[i].itemId);
GetItemNameFromPocket(sListBuffer2->name[i], GetBagItemId(pocketId, i));
subBuffer = sListBuffer1->subBuffers;
subBuffer[i].name = sListBuffer2->name[i];
subBuffer[i].id = i;
@ -897,7 +896,7 @@ static void LoadBagItemListBuffers(u8 pocketId)
{
for (i = 0; i < gBagMenu->numItemStacks[pocketId]; i++)
{
GetItemNameFromPocket(sListBuffer2->name[i], pocket->itemSlots[i].itemId);
GetItemNameFromPocket(sListBuffer2->name[i], GetBagItemId(pocketId, i));
subBuffer = sListBuffer1->subBuffers;
subBuffer[i].name = sListBuffer2->name[i];
subBuffer[i].id = i;
@ -914,7 +913,7 @@ static void GetItemNameFromPocket(u8 *dest, u16 itemId)
u8 *end;
switch (gBagPosition.pocket)
{
case TMHM_POCKET:
case POCKET_TM_HM:
end = StringCopy(gStringVar2, GetMoveName(ItemIdToBattleMoveId(itemId)));
PrependFontIdToFit(gStringVar2, end, FONT_NARROW, 61);
if (itemId >= ITEM_HM01)
@ -930,7 +929,7 @@ static void GetItemNameFromPocket(u8 *dest, u16 itemId)
StringExpandPlaceholders(dest, gText_NumberItem_TMBerry);
}
break;
case BERRIES_POCKET:
case POCKET_BERRIES:
ConvertIntToDecimalStringN(gStringVar1, itemId - FIRST_BERRY_INDEX + 1, STR_CONV_MODE_LEADING_ZEROS, 2);
end = CopyItemName(itemId, gStringVar2);
PrependFontIdToFit(gStringVar2, end, FONT_NARROW, 61);
@ -954,7 +953,7 @@ static void BagMenu_MoveCursorCallback(s32 itemIndex, bool8 onInit, struct ListM
{
RemoveBagItemIconSprite(gBagMenu->itemIconSlot ^ 1);
if (itemIndex != LIST_CANCEL)
AddBagItemIconSprite(BagGetItemIdByPocketPosition(gBagPosition.pocket + 1, itemIndex), gBagMenu->itemIconSlot);
AddBagItemIconSprite(GetBagItemId(gBagPosition.pocket, itemIndex), gBagMenu->itemIconSlot);
else
AddBagItemIconSprite(ITEM_LIST_END, gBagMenu->itemIconSlot);
gBagMenu->itemIconSlot ^= 1;
@ -980,14 +979,14 @@ static void BagMenu_ItemPrintCallback(u8 windowId, u32 itemIndex, u8 y)
BagMenu_PrintCursorAtPos(y, COLORID_NONE);
}
itemId = BagGetItemIdByPocketPosition(gBagPosition.pocket + 1, itemIndex);
itemQuantity = BagGetQuantityByPocketPosition(gBagPosition.pocket + 1, itemIndex);
itemId = GetBagItemId(gBagPosition.pocket, itemIndex);
itemQuantity = GetBagItemQuantity(gBagPosition.pocket, itemIndex);
// Draw HM icon
if (itemId >= ITEM_HM01 && itemId <= ITEM_HM08)
BlitBitmapToWindow(windowId, gBagMenuHMIcon_Gfx, 8, y - 1, 16, 16);
if (gBagPosition.pocket != KEYITEMS_POCKET && GetItemImportance(itemId) == FALSE)
if (gBagPosition.pocket != POCKET_KEY_ITEMS && GetItemImportance(itemId) == FALSE)
{
// Print item quantity
ConvertIntToDecimalStringN(gStringVar1, itemQuantity, STR_CONV_MODE_RIGHT_ALIGN, MAX_ITEM_DIGITS);
@ -1009,7 +1008,7 @@ static void PrintItemDescription(int itemIndex)
const u8 *str;
if (itemIndex != LIST_CANCEL)
{
str = GetItemDescription(BagGetItemIdByPocketPosition(gBagPosition.pocket + 1, itemIndex));
str = GetItemDescription(GetBagItemId(gBagPosition.pocket, itemIndex));
}
else
{
@ -1131,21 +1130,20 @@ static void Task_CloseBagMenu(u8 taskId)
void UpdatePocketItemList(u8 pocketId)
{
u16 i;
struct BagPocket *pocket = &gBagPockets[pocketId];
switch (pocketId)
{
case TMHM_POCKET:
case BERRIES_POCKET:
SortBerriesOrTMHMs(pocket);
case POCKET_TM_HM:
case POCKET_BERRIES:
SortBerriesOrTMHMs(pocketId);
break;
default:
CompactItemsInBagPocket(pocket);
CompactItemsInBagPocket(pocketId);
break;
}
gBagMenu->numItemStacks[pocketId] = 0;
for (i = 0; i < pocket->capacity && pocket->itemSlots[i].itemId; i++)
for (i = 0; i < gBagPockets[pocketId].capacity && GetBagItemId(pocketId, i); i++)
gBagMenu->numItemStacks[pocketId]++;
if (!gBagMenu->hideCloseBagText)
@ -1289,8 +1287,8 @@ static void Task_BagMenu_HandleInput(u8 taskId)
BagDestroyPocketScrollArrowPair();
BagMenu_PrintCursor(tListTaskId, COLORID_GRAY_CURSOR);
tListPosition = listPosition;
tQuantity = BagGetQuantityByPocketPosition(gBagPosition.pocket + 1, listPosition);
gSpecialVar_ItemId = BagGetItemIdByPocketPosition(gBagPosition.pocket + 1, listPosition);
tQuantity = GetBagItemQuantity(gBagPosition.pocket, listPosition);
gSpecialVar_ItemId = GetBagItemId(gBagPosition.pocket, listPosition);
sContextMenuFuncs[gBagPosition.location](taskId);
break;
}
@ -1447,8 +1445,8 @@ static bool8 CanSwapItems(void)
|| gBagPosition.location == ITEMMENULOCATION_BATTLE)
{
// TMHMs and berries are numbered, and so may not be swapped
if (gBagPosition.pocket != TMHM_POCKET
&& gBagPosition.pocket != BERRIES_POCKET)
if (gBagPosition.pocket != POCKET_TM_HM
&& gBagPosition.pocket != POCKET_BERRIES)
return TRUE;
}
return FALSE;
@ -1461,7 +1459,7 @@ static void StartItemSwap(u8 taskId)
ListMenuSetUnkIndicatorsStructField(tListTaskId, 16, 1);
tListPosition = gBagPosition.scrollPosition[gBagPosition.pocket] + gBagPosition.cursorPosition[gBagPosition.pocket];
gBagMenu->toSwapPos = tListPosition;
CopyItemName(BagGetItemIdByPocketPosition(gBagPosition.pocket + 1, tListPosition), gStringVar1);
CopyItemName(GetBagItemId(gBagPosition.pocket, tListPosition), gStringVar1);
StringExpandPlaceholders(gStringVar4, gText_MoveVar1Where);
FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0));
BagMenu_Print(WIN_DESCRIPTION, FONT_NORMAL, gStringVar4, 3, 1, 0, 0, 0, COLORID_NORMAL);
@ -1523,7 +1521,7 @@ static void DoItemSwap(u8 taskId)
}
else
{
MoveItemSlotInList(gBagPockets[gBagPosition.pocket].itemSlots, tListPosition, realPos);
MoveItemSlotInPocket(gBagPosition.pocket, tListPosition, realPos);
gBagMenu->toSwapPos = NOT_SWAPPING;
DestroyListMenuTask(tListTaskId, scrollPos, cursorPos);
if (tListPosition < realPos)
@ -1618,7 +1616,7 @@ static void OpenContextMenu(u8 taskId)
default:
if (MenuHelpers_IsLinkActive() == TRUE || InUnionRoom() == TRUE)
{
if (gBagPosition.pocket == KEYITEMS_POCKET || !IsHoldingItemAllowed(gSpecialVar_ItemId))
if (gBagPosition.pocket == POCKET_KEY_ITEMS || !IsHoldingItemAllowed(gSpecialVar_ItemId))
{
gBagMenu->contextMenuItemsPtr = sContextMenuItems_Cancel;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_Cancel);
@ -1633,14 +1631,14 @@ static void OpenContextMenu(u8 taskId)
{
switch (gBagPosition.pocket)
{
case ITEMS_POCKET:
case POCKET_ITEMS:
gBagMenu->contextMenuItemsPtr = gBagMenu->contextMenuItemsBuffer;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_ItemsPocket);
memcpy(&gBagMenu->contextMenuItemsBuffer, &sContextMenuItems_ItemsPocket, sizeof(sContextMenuItems_ItemsPocket));
if (ItemIsMail(gSpecialVar_ItemId) == TRUE)
gBagMenu->contextMenuItemsBuffer[0] = ACTION_CHECK;
break;
case KEYITEMS_POCKET:
case POCKET_KEY_ITEMS:
gBagMenu->contextMenuItemsPtr = gBagMenu->contextMenuItemsBuffer;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_KeyItemsPocket);
memcpy(&gBagMenu->contextMenuItemsBuffer, &sContextMenuItems_KeyItemsPocket, sizeof(sContextMenuItems_KeyItemsPocket));
@ -1652,22 +1650,22 @@ static void OpenContextMenu(u8 taskId)
gBagMenu->contextMenuItemsBuffer[0] = ACTION_WALK;
}
break;
case BALLS_POCKET:
case POCKET_POKE_BALLS:
gBagMenu->contextMenuItemsPtr = sContextMenuItems_BallsPocket;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_BallsPocket);
break;
case TMHM_POCKET:
case POCKET_TM_HM:
gBagMenu->contextMenuItemsPtr = sContextMenuItems_TmHmPocket;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_TmHmPocket);
break;
case BERRIES_POCKET:
case POCKET_BERRIES:
gBagMenu->contextMenuItemsPtr = sContextMenuItems_BerriesPocket;
gBagMenu->contextMenuNumItems = ARRAY_COUNT(sContextMenuItems_BerriesPocket);
break;
}
}
}
if (gBagPosition.pocket == TMHM_POCKET)
if (gBagPosition.pocket == POCKET_TM_HM)
{
ClearWindowTilemap(WIN_DESCRIPTION);
PrintTMHMMoveData(gSpecialVar_ItemId);
@ -1824,7 +1822,7 @@ static void ItemMenu_UseOutOfBattle(u8 taskId)
{
FillWindowPixelBuffer(WIN_DESCRIPTION, PIXEL_FILL(0));
ScheduleBgCopyTilemapToVram(0);
if (gBagPosition.pocket != BERRIES_POCKET)
if (gBagPosition.pocket != POCKET_BERRIES)
GetItemFieldFunc(gSpecialVar_ItemId)(taskId);
else
ItemUseOutOfBattle_Berry(taskId);
@ -2047,7 +2045,7 @@ static void Task_ItemContext_GiveToParty(u8 taskId)
StringExpandPlaceholders(gStringVar4, sText_Var1CantBeHeldHere);
DisplayItemMessage(taskId, FONT_NORMAL, gStringVar4, HandleErrorMessage);
}
else if (gBagPosition.pocket != KEYITEMS_POCKET && !GetItemImportance(gSpecialVar_ItemId))
else if (gBagPosition.pocket != POCKET_KEY_ITEMS && !GetItemImportance(gSpecialVar_ItemId))
{
Task_FadeAndCloseBagMenu(taskId);
}
@ -2062,7 +2060,7 @@ static void Task_ItemContext_GiveToPC(u8 taskId)
{
if (ItemIsMail(gSpecialVar_ItemId) == TRUE)
DisplayItemMessage(taskId, FONT_NORMAL, gText_CantWriteMail, HandleErrorMessage);
else if (gBagPosition.pocket != KEYITEMS_POCKET && !GetItemImportance(gSpecialVar_ItemId))
else if (gBagPosition.pocket != POCKET_KEY_ITEMS && !GetItemImportance(gSpecialVar_ItemId))
gTasks[taskId].func = Task_FadeAndCloseBagMenu;
else
PrintItemCantBeHeld(taskId);
@ -2328,16 +2326,16 @@ static void PrepareBagForWallyTutorial(void)
u32 i;
sTempWallyBag = AllocZeroed(sizeof(*sTempWallyBag));
memcpy(sTempWallyBag->bagPocket_Items, gSaveBlock1Ptr->bagPocket_Items, sizeof(gSaveBlock1Ptr->bagPocket_Items));
memcpy(sTempWallyBag->bagPocket_PokeBalls, gSaveBlock1Ptr->bagPocket_PokeBalls, sizeof(gSaveBlock1Ptr->bagPocket_PokeBalls));
memcpy(sTempWallyBag->bagPocket_Items, gSaveBlock1Ptr->bag.items, sizeof(gSaveBlock1Ptr->bag.items));
memcpy(sTempWallyBag->bagPocket_PokeBalls, gSaveBlock1Ptr->bag.pokeBalls, sizeof(gSaveBlock1Ptr->bag.pokeBalls));
sTempWallyBag->pocket = gBagPosition.pocket;
for (i = 0; i < POCKETS_COUNT; i++)
{
sTempWallyBag->cursorPosition[i] = gBagPosition.cursorPosition[i];
sTempWallyBag->scrollPosition[i] = gBagPosition.scrollPosition[i];
}
ClearItemSlots(gSaveBlock1Ptr->bagPocket_Items, BAG_ITEMS_COUNT);
ClearItemSlots(gSaveBlock1Ptr->bagPocket_PokeBalls, BAG_POKEBALLS_COUNT);
memset(gSaveBlock1Ptr->bag.items, 0, sizeof(gSaveBlock1Ptr->bag.items));
memset(gSaveBlock1Ptr->bag.pokeBalls, 0, sizeof(gSaveBlock1Ptr->bag.pokeBalls));
ResetBagScrollPositions();
}
@ -2345,8 +2343,8 @@ static void RestoreBagAfterWallyTutorial(void)
{
u32 i;
memcpy(gSaveBlock1Ptr->bagPocket_Items, sTempWallyBag->bagPocket_Items, sizeof(sTempWallyBag->bagPocket_Items));
memcpy(gSaveBlock1Ptr->bagPocket_PokeBalls, sTempWallyBag->bagPocket_PokeBalls, sizeof(sTempWallyBag->bagPocket_PokeBalls));
memcpy(gSaveBlock1Ptr->bag.items, sTempWallyBag->bagPocket_Items, sizeof(sTempWallyBag->bagPocket_Items));
memcpy(gSaveBlock1Ptr->bag.pokeBalls, sTempWallyBag->bagPocket_PokeBalls, sizeof(sTempWallyBag->bagPocket_PokeBalls));
gBagPosition.pocket = sTempWallyBag->pocket;
for (i = 0; i < POCKETS_COUNT; i++)
{
@ -2361,7 +2359,7 @@ void DoWallyTutorialBagMenu(void)
PrepareBagForWallyTutorial();
AddBagItem(ITEM_POTION, 1);
AddBagItem(ITEM_POKE_BALL, 1);
GoToBagMenu(ITEMMENULOCATION_WALLY, ITEMS_POCKET, CB2_SetUpReshowBattleScreenAfterMenu2);
GoToBagMenu(ITEMMENULOCATION_WALLY, POCKET_ITEMS, CB2_SetUpReshowBattleScreenAfterMenu2);
}
#define tTimer data[8]

View File

@ -96,12 +96,12 @@ static const union AnimCmd sSpriteAnim_Bag_Berries[] =
static const union AnimCmd *const sBagSpriteAnimTable[] =
{
[POCKET_NONE] = sSpriteAnim_Bag_Closed,
[POCKET_ITEMS] = sSpriteAnim_Bag_Items,
[POCKET_POKE_BALLS] = sSpriteAnim_Bag_Pokeballs,
[POCKET_TM_HM] = sSpriteAnim_Bag_TMsHMs,
[POCKET_BERRIES] = sSpriteAnim_Bag_Berries,
[POCKET_KEY_ITEMS] = sSpriteAnim_Bag_KeyItems,
[POCKET_NONE] = sSpriteAnim_Bag_Closed,
};
static const union AffineAnimCmd sSpriteAffineAnim_BagNormal[] =
@ -473,12 +473,12 @@ void SetBagVisualPocketId(u8 bagPocketId, bool8 isSwitchingPockets)
{
sprite->y2 = -5;
sprite->callback = SpriteCB_BagVisualSwitchingPockets;
sprite->sPocketId = bagPocketId + 1;
sprite->sPocketId = bagPocketId;
StartSpriteAnim(sprite, POCKET_NONE);
}
else
{
StartSpriteAnim(sprite, bagPocketId + 1);
StartSpriteAnim(sprite, bagPocketId);
}
}

View File

@ -25,11 +25,7 @@ static void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey);
struct LoadedSaveData
{
/*0x0000*/ struct ItemSlot items[BAG_ITEMS_COUNT];
/*0x0078*/ struct ItemSlot keyItems[BAG_KEYITEMS_COUNT];
/*0x00F0*/ struct ItemSlot pokeBalls[BAG_POKEBALLS_COUNT];
/*0x0130*/ struct ItemSlot TMsHMs[BAG_TMHM_COUNT];
/*0x0230*/ struct ItemSlot berries[BAG_BERRIES_COUNT];
/*0x0000*/ struct Bag bag;
/*0x02E8*/ struct Mail mail[MAIL_COUNT];
};
@ -173,23 +169,22 @@ void ClearContinueGameWarpStatus2(void)
void SavePlayerParty(void)
{
int i;
gSaveBlock1Ptr->playerPartyCount = gPlayerPartyCount;
*GetSavedPlayerPartyCount() = gPlayerPartyCount;
for (i = 0; i < PARTY_SIZE; i++)
gSaveBlock1Ptr->playerParty[i] = gPlayerParty[i];
SavePlayerPartyMon(i, &gPlayerParty[i]);
}
void LoadPlayerParty(void)
{
int i;
gPlayerPartyCount = gSaveBlock1Ptr->playerPartyCount;
gPlayerPartyCount = *GetSavedPlayerPartyCount();
for (i = 0; i < PARTY_SIZE; i++)
{
u32 data;
gPlayerParty[i] = gSaveBlock1Ptr->playerParty[i];
gPlayerParty[i] = *GetSavedPlayerPartyMon(i);
// TODO: Turn this into a save migration once those are available.
// At which point we can remove hp and status from Pokemon entirely.
@ -260,25 +255,8 @@ void LoadPlayerBag(void)
{
int i;
// load player items.
for (i = 0; i < BAG_ITEMS_COUNT; i++)
gLoadedSaveData.items[i] = gSaveBlock1Ptr->bagPocket_Items[i];
// load player key items.
for (i = 0; i < BAG_KEYITEMS_COUNT; i++)
gLoadedSaveData.keyItems[i] = gSaveBlock1Ptr->bagPocket_KeyItems[i];
// load player pokeballs.
for (i = 0; i < BAG_POKEBALLS_COUNT; i++)
gLoadedSaveData.pokeBalls[i] = gSaveBlock1Ptr->bagPocket_PokeBalls[i];
// load player TMs and HMs.
for (i = 0; i < BAG_TMHM_COUNT; i++)
gLoadedSaveData.TMsHMs[i] = gSaveBlock1Ptr->bagPocket_TMHM[i];
// load player berries.
for (i = 0; i < BAG_BERRIES_COUNT; i++)
gLoadedSaveData.berries[i] = gSaveBlock1Ptr->bagPocket_Berries[i];
// load player bag.
memcpy(&gLoadedSaveData.bag, &gSaveBlock1Ptr->bag, sizeof(struct Bag));
// load mail.
for (i = 0; i < MAIL_COUNT; i++)
@ -292,25 +270,8 @@ void SavePlayerBag(void)
int i;
u32 encryptionKeyBackup;
// save player items.
for (i = 0; i < BAG_ITEMS_COUNT; i++)
gSaveBlock1Ptr->bagPocket_Items[i] = gLoadedSaveData.items[i];
// save player key items.
for (i = 0; i < BAG_KEYITEMS_COUNT; i++)
gSaveBlock1Ptr->bagPocket_KeyItems[i] = gLoadedSaveData.keyItems[i];
// save player pokeballs.
for (i = 0; i < BAG_POKEBALLS_COUNT; i++)
gSaveBlock1Ptr->bagPocket_PokeBalls[i] = gLoadedSaveData.pokeBalls[i];
// save player TMs and HMs.
for (i = 0; i < BAG_TMHM_COUNT; i++)
gSaveBlock1Ptr->bagPocket_TMHM[i] = gLoadedSaveData.TMsHMs[i];
// save player berries.
for (i = 0; i < BAG_BERRIES_COUNT; i++)
gSaveBlock1Ptr->bagPocket_Berries[i] = gLoadedSaveData.berries[i];
// save player bag.
memcpy(&gSaveBlock1Ptr->bag, &gLoadedSaveData.bag, sizeof(struct Bag));
// save mail.
for (i = 0; i < MAIL_COUNT; i++)
@ -337,7 +298,7 @@ void ApplyNewEncryptionKeyToWord(u32 *word, u32 newKey)
static void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey)
{
ApplyNewEncryptionKeyToGameStats(encryptionKey);
ApplyNewEncryptionKeyToBagItems_(encryptionKey);
ApplyNewEncryptionKeyToBagItems(encryptionKey);
ApplyNewEncryptionKeyToBerryPowder(encryptionKey);
ApplyNewEncryptionKeyToWord(&gSaveBlock1Ptr->money, encryptionKey);
ApplyNewEncryptionKeyToHword(&gSaveBlock1Ptr->coins, encryptionKey);

View File

@ -4561,7 +4561,7 @@ void CB2_ShowPartyMenuForItemUse(void)
}
else
{
if (GetPocketByItemId(gSpecialVar_ItemId) == POCKET_TM_HM)
if (GetItemPocket(gSpecialVar_ItemId) == POCKET_TM_HM)
msgId = PARTY_MSG_TEACH_WHICH_MON;
else
msgId = PARTY_MSG_USE_ON_WHICH_MON;

View File

@ -369,7 +369,7 @@ static const u8 sSwapArrowTextColors[] = {TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRA
void NewGameInitPCItems(void)
{
u8 i = 0;
ClearItemSlots(gSaveBlock1Ptr->pcItems, PC_ITEMS_COUNT);
CpuFastFill(0, gSaveBlock1Ptr->pcItems, sizeof(gSaveBlock1Ptr->pcItems));
while (TRUE)
{
@ -1334,7 +1334,7 @@ static void ItemStorage_FinishItemSwap(u8 taskId, bool8 canceled)
if (!canceled && sItemStorageMenu->toSwapPos != newPos && sItemStorageMenu->toSwapPos != newPos - 1)
{
MoveItemSlotInList(gSaveBlock1Ptr->pcItems, sItemStorageMenu->toSwapPos, newPos);
MoveItemSlotInPC(gSaveBlock1Ptr->pcItems, sItemStorageMenu->toSwapPos, newPos);
ItemStorage_RefreshListMenu();
}
if (sItemStorageMenu->toSwapPos < newPos)

View File

@ -6673,7 +6673,7 @@ u32 GetFormChangeTargetSpeciesBoxMon(struct BoxPokemon *boxMon, enum FormChanges
// This is to prevent reverting to base form when giving the item to the corresponding form.
// Eg. Giving a Zap Plate to an Electric Arceus without an item (most likely to happen when using givemon)
bool32 currentItemForm = FALSE;
for (int j = 0; formChanges[j].method != FORM_CHANGE_TERMINATOR; j++)
for (u32 j = 0; formChanges[j].method != FORM_CHANGE_TERMINATOR; j++)
{
if (species == formChanges[j].targetSpecies
&& formChanges[j].param1 == heldItem
@ -7209,3 +7209,18 @@ u32 GetTeraTypeFromPersonality(struct Pokemon *mon)
const u8 *types = gSpeciesInfo[GetMonData(mon, MON_DATA_SPECIES)].types;
return (GetMonData(mon, MON_DATA_PERSONALITY) & 0x1) == 0 ? types[0] : types[1];
}
struct Pokemon *GetSavedPlayerPartyMon(u32 index)
{
return &gSaveBlock1Ptr->playerParty[index];
}
u8 *GetSavedPlayerPartyCount(void)
{
return &gSaveBlock1Ptr->playerPartyCount;
}
void SavePlayerPartyMon(u32 index, struct Pokemon *mon)
{
gSaveBlock1Ptr->playerParty[index] = *mon;
}

View File

@ -961,7 +961,7 @@ static void ReceiveDaycareMailData(struct RecordMixingDaycareMail *records, size
static void ReceiveGiftItem(u16 *item, u8 multiplayerId)
{
if (multiplayerId != 0 && *item != ITEM_NONE && GetPocketByItemId(*item) == POCKET_KEY_ITEMS)
if (multiplayerId != 0 && *item != ITEM_NONE && GetItemPocket(*item) == POCKET_KEY_ITEMS)
{
if (!CheckBagHasItem(*item, 1) && !CheckPCHasItem(*item, 1) && AddBagItem(*item, 1))
{

View File

@ -667,7 +667,7 @@ bool8 ScrCmd_checkitemtype(struct ScriptContext *ctx)
Script_RequestEffects(SCREFF_V1);
gSpecialVar_Result = GetPocketByItemId(itemId);
gSpecialVar_Result = GetItemPocket(itemId);
return FALSE;
}

View File

@ -199,11 +199,11 @@ const u8 gText_ReturnToVar1[] = _("Return to\n{STR_VAR_1}.");
const u8 *const gPocketNamesStringsTable[] =
{
[ITEMS_POCKET] = COMPOUND_STRING("ITEMS"),
[BALLS_POCKET] = COMPOUND_STRING("POKé BALLS"),
[TMHM_POCKET] = COMPOUND_STRING("TMs & HMs"),
[BERRIES_POCKET] = COMPOUND_STRING("BERRIES"),
[KEYITEMS_POCKET] = COMPOUND_STRING("KEY ITEMS")
[POCKET_ITEMS] = COMPOUND_STRING("ITEMS"),
[POCKET_POKE_BALLS] = COMPOUND_STRING("POKé BALLS"),
[POCKET_TM_HM] = COMPOUND_STRING("TMs & HMs"),
[POCKET_BERRIES] = COMPOUND_STRING("BERRIES"),
[POCKET_KEY_ITEMS] = COMPOUND_STRING("KEY ITEMS")
};
const u8 gText_NumberItem_TMBerry[] = _("{NO}{STR_VAR_1}{CLEAR 0x07}{STR_VAR_2}");

View File

@ -2394,8 +2394,8 @@ void TryPutFrontierTVShowOnAir(u16 winStreak, u8 facilityAndMode)
show->frontier.species2 = GetMonData(&gPlayerParty[1], MON_DATA_SPECIES, NULL);
break;
case FRONTIER_SHOW_TOWER_LINK_MULTIS:
show->frontier.species1 = GetMonData(&gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[0] - 1], MON_DATA_SPECIES, NULL);
show->frontier.species2 = GetMonData(&gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[1] - 1], MON_DATA_SPECIES, NULL);
show->frontier.species1 = GetMonData(GetSavedPlayerPartyMon(gSaveBlock2Ptr->frontier.selectedPartyMons[0] - 1), MON_DATA_SPECIES, NULL);
show->frontier.species2 = GetMonData(GetSavedPlayerPartyMon(gSaveBlock2Ptr->frontier.selectedPartyMons[1] - 1), MON_DATA_SPECIES, NULL);
break;
}
StorePlayerIdInRecordMixShow(show);