change last ball graphic based on config. replace saveblock field with ewram field

This commit is contained in:
ghoulslash 2021-09-23 12:03:01 -04:00
parent 39a254f80d
commit 3f34fec42f
7 changed files with 32 additions and 10 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 B

View File

Before

Width:  |  Height:  |  Size: 223 B

After

Width:  |  Height:  |  Size: 223 B

View File

@ -890,5 +890,6 @@ extern u8 gNumberOfMovesToChoose;
extern u8 gBattleControllerData[MAX_BATTLERS_COUNT];
extern bool8 gHasFetchedBall;
extern u8 gLastUsedBall;
extern u16 gLastThrownBall;
#endif // GUARD_BATTLE_H

View File

@ -30,6 +30,7 @@
#include "item_icon.h"
#include "item_use.h"
#include "item.h"
#include "constants/items.h"
enum
{ // Corresponds to gHealthboxElementsGfxTable (and the tables after it) in graphics.c
@ -3175,7 +3176,11 @@ static const struct SpriteTemplate sSpriteTemplate_LastUsedBallWindow =
.callback = SpriteCB_LastUsedBallWin
};
static const u8 sLastUsedBallWindowGfx[] = INCBIN_U8("graphics/battle_interface/last_used_ball.4bpp");
#if B_LAST_USED_BALL_BUTTON == R_BUTTON
static const u8 sLastUsedBallWindowGfx[] = INCBIN_U8("graphics/battle_interface/last_used_ball_r.4bpp");
#else
static const u8 sLastUsedBallWindowGfx[] = INCBIN_U8("graphics/battle_interface/last_used_ball_r.4bpp");
#endif
static const struct SpriteSheet sSpriteSheet_LastUsedBallWindow =
{
sLastUsedBallWindowGfx, sizeof(sLastUsedBallWindowGfx), LAST_BALL_WINDOW_TAG
@ -3193,31 +3198,39 @@ static const struct SpriteSheet sSpriteSheet_LastUsedBallWindow =
bool32 CanThrowLastUsedBall(void)
{
#if B_LAST_USED_BALL == FALSE
return FALSE;
#else
return (!(CanThrowBall() != 0
|| (gBattleTypeFlags & BATTLE_TYPE_TRAINER)
|| !CheckBagHasItem(gSaveBlock2Ptr->lastUsedBall, 1)));
|| !CheckBagHasItem(gLastThrownBall, 1)));
#endif
}
void TryAddLastUsedBallItemSprites(void)
{
if (gSaveBlock2Ptr->lastUsedBall != 0 && !CheckBagHasItem(gSaveBlock2Ptr->lastUsedBall, 1))
#if B_LAST_USED_BALL == TRUE
if (gLastThrownBall == 0)
gLastThrownBall = ITEM_POKE_BALL;
if (gLastThrownBall != 0 && !CheckBagHasItem(gLastThrownBall, 1))
{
// we're out of the last used ball, so just set it to the first ball in the bag
// we have to compact the bag first bc it is typically only compacted when you open it
CompactItemsInBagPocket(&gBagPockets[BALLS_POCKET]);
gSaveBlock2Ptr->lastUsedBall = gBagPockets[BALLS_POCKET].itemSlots[0].itemId;
gLastThrownBall = gBagPockets[BALLS_POCKET].itemSlots[0].itemId;
}
if (CanThrowBall() != 0
|| (gBattleTypeFlags & BATTLE_TYPE_TRAINER)
|| !CheckBagHasItem(gSaveBlock2Ptr->lastUsedBall, 1))
|| !CheckBagHasItem(gLastThrownBall, 1))
return;
// ball
if (gBattleStruct->ballSpriteIds[0] == MAX_SPRITES)
{
gBattleStruct->ballSpriteIds[0] = AddItemIconSprite(102, 102, gSaveBlock2Ptr->lastUsedBall);
gBattleStruct->ballSpriteIds[0] = AddItemIconSprite(102, 102, gLastThrownBall);
gSprites[gBattleStruct->ballSpriteIds[0]].x = LAST_USED_BALL_X_0;
gSprites[gBattleStruct->ballSpriteIds[0]].y = LAST_USED_BALL_Y;
gSprites[gBattleStruct->ballSpriteIds[0]].sHide = FALSE; // restore
@ -3236,6 +3249,7 @@ void TryAddLastUsedBallItemSprites(void)
LAST_USED_WIN_Y, 5);
gSprites[gBattleStruct->ballSpriteIds[0]].sHide = FALSE; // restore
}
#endif
}
static void DestroyLastUsedBallWinGfx(struct Sprite *sprite)
@ -3290,6 +3304,7 @@ static void SpriteCB_LastUsedBall(struct Sprite *sprite)
static void TryHideOrRestoreLastUsedBall(u8 caseId)
{
#if B_LAST_USED_BALL == TRUE
if (gBattleStruct->ballSpriteIds[0] == MAX_SPRITES)
return;
@ -3308,18 +3323,23 @@ static void TryHideOrRestoreLastUsedBall(u8 caseId)
gSprites[gBattleStruct->ballSpriteIds[1]].sHide = FALSE; // restore
break;
}
#endif
}
void TryHideLastUsedBall(void)
{
#if B_LAST_USED_BALL == TRUE
TryHideOrRestoreLastUsedBall(0);
#endif
}
void TryRestoreLastUsedBall(void)
{
#if B_LAST_USED_BALL == TRUE
if (gBattleStruct->ballSpriteIds[0] != MAX_SPRITES)
TryHideOrRestoreLastUsedBall(1);
else
TryAddLastUsedBallItemSprites();
#endif
}

View File

@ -230,6 +230,7 @@ EWRAM_DATA u16 gPartnerSpriteId = 0;
EWRAM_DATA struct TotemBoost gTotemBoosts[MAX_BATTLERS_COUNT] = {0};
EWRAM_DATA bool8 gHasFetchedBall = FALSE;
EWRAM_DATA u8 gLastUsedBall = 0;
EWRAM_DATA u16 gLastThrownBall = 0;
// IWRAM common vars
void (*gPreBattleCallback1)(void);

View File

@ -12021,7 +12021,7 @@ static void Cmd_handleballthrow(void)
u32 odds;
u8 catchRate;
gSaveBlock2Ptr->lastUsedBall = gLastUsedItem;
gLastThrownBall = gLastUsedItem;
if (gLastUsedItem == ITEM_SAFARI_BALL)
catchRate = gBattleStruct->safariCatchFactor * 1275 / 100;
else

View File

@ -759,7 +759,7 @@ void HandleAction_ThrowBall(void)
gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber];
gBattle_BG0_X = 0;
gBattle_BG0_Y = 0;
gLastUsedItem = gSaveBlock2Ptr->lastUsedBall;
gLastUsedItem = gLastThrownBall;
RemoveBagItem(gLastUsedItem, 1);
gBattlescriptCurrInstr = BattleScript_BallThrow;
gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT;