mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2025-01-27 22:03:53 +01:00
Merge pull request #1983 from sphericalice/last_ball_refactor
Refactor CanThrowLastUsedBall and related functions
This commit is contained in:
commit
a57043b589
@ -33,6 +33,14 @@ void ItemUseInBattle_EnigmaBerry(u8);
|
||||
void Task_UseDigEscapeRopeOnField(u8 taskId);
|
||||
u8 CanUseDigOrEscapeRopeOnCurMap(void);
|
||||
u8 CheckIfItemIsTMHMOrEvolutionStone(u16 itemId);
|
||||
u32 CanThrowBall(void);
|
||||
|
||||
enum {
|
||||
BALL_THROW_UNABLE_TWO_MONS,
|
||||
BALL_THROW_UNABLE_NO_ROOM,
|
||||
BALL_THROW_UNABLE_SEMI_INVULNERABLE,
|
||||
BALL_THROW_ABLE,
|
||||
};
|
||||
|
||||
bool32 CanThrowBall(void);
|
||||
|
||||
#endif // GUARD_ITEM_USE_H
|
||||
|
@ -3281,13 +3281,17 @@ bool32 CanThrowLastUsedBall(void)
|
||||
#if B_LAST_USED_BALL == FALSE
|
||||
return FALSE;
|
||||
#else
|
||||
return (!(CanThrowBall() != 0
|
||||
|| (gBattleTypeFlags & BATTLE_TYPE_TRAINER)
|
||||
|| !CheckBagHasItem(gLastThrownBall, 1)));
|
||||
if (!CanThrowBall())
|
||||
return FALSE;
|
||||
if (gBattleTypeFlags & BATTLE_TYPE_TRAINER)
|
||||
return FALSE;
|
||||
if (!CheckBagHasItem(gLastThrownBall, 1))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void TryAddLastUsedBallItemSprites(void)
|
||||
{
|
||||
#if B_LAST_USED_BALL == TRUE
|
||||
@ -3300,9 +3304,7 @@ void TryAddLastUsedBallItemSprites(void)
|
||||
gLastThrownBall = gBagPockets[BALLS_POCKET].itemSlots[0].itemId;
|
||||
}
|
||||
|
||||
if (CanThrowBall() != 0
|
||||
|| (gBattleTypeFlags & BATTLE_TYPE_TRAINER)
|
||||
|| !CheckBagHasItem(gLastThrownBall, 1))
|
||||
if (!CanThrowLastUsedBall())
|
||||
return;
|
||||
|
||||
// ball
|
||||
@ -3420,4 +3422,3 @@ void TryRestoreLastUsedBall(void)
|
||||
TryAddLastUsedBallItemSprites();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -940,34 +940,33 @@ void ItemUseOutOfBattle_EvolutionStone(u8 taskId)
|
||||
SetUpItemUseCallback(taskId);
|
||||
}
|
||||
|
||||
u32 CanThrowBall(void)
|
||||
static u32 GetBallThrowableState(void)
|
||||
{
|
||||
if (IsBattlerAlive(GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT))
|
||||
&& IsBattlerAlive(GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT)))
|
||||
{
|
||||
return 1; // There are two present pokemon.
|
||||
}
|
||||
return BALL_THROW_UNABLE_TWO_MONS;
|
||||
else if (IsPlayerPartyAndPokemonStorageFull() == TRUE)
|
||||
{
|
||||
return 2; // No room for mon
|
||||
}
|
||||
return BALL_THROW_UNABLE_NO_ROOM;
|
||||
#if B_SEMI_INVULNERABLE_CATCH >= GEN_4
|
||||
else if (gStatuses3[GetCatchingBattler()] & STATUS3_SEMI_INVULNERABLE)
|
||||
{
|
||||
return 3; // in semi-invulnerable state
|
||||
}
|
||||
return BALL_THROW_UNABLE_SEMI_INVULNERABLE;
|
||||
#endif
|
||||
|
||||
return 0; // usable
|
||||
return BALL_THROW_ABLE;
|
||||
}
|
||||
|
||||
bool32 CanThrowBall(void)
|
||||
{
|
||||
return (GetBallThrowableState() == BALL_THROW_ABLE);
|
||||
}
|
||||
|
||||
static const u8 sText_CantThrowPokeBall_TwoMons[] = _("Cannot throw a ball!\nThere are two Pokémon out there!\p");
|
||||
static const u8 sText_CantThrowPokeBall_SemiInvulnerable[] = _("Cannot throw a ball!\nThere's no Pokémon in sight!\p");
|
||||
void ItemUseInBattle_PokeBall(u8 taskId)
|
||||
{
|
||||
switch (CanThrowBall())
|
||||
switch (GetBallThrowableState())
|
||||
{
|
||||
case 0: // usable
|
||||
case BALL_THROW_ABLE:
|
||||
default:
|
||||
RemoveBagItem(gSpecialVar_ItemId, 1);
|
||||
if (!InBattlePyramid())
|
||||
@ -975,20 +974,20 @@ void ItemUseInBattle_PokeBall(u8 taskId)
|
||||
else
|
||||
CloseBattlePyramidBag(taskId);
|
||||
break;
|
||||
case 1: // There are two present pokemon.
|
||||
case BALL_THROW_UNABLE_TWO_MONS:
|
||||
if (!InBattlePyramid())
|
||||
DisplayItemMessage(taskId, FONT_NORMAL, sText_CantThrowPokeBall_TwoMons, CloseItemMessage);
|
||||
else
|
||||
DisplayItemMessageInBattlePyramid(taskId, sText_CantThrowPokeBall_TwoMons, Task_CloseBattlePyramidBagMessage);
|
||||
break;
|
||||
case 2: // No room for mon
|
||||
case BALL_THROW_UNABLE_NO_ROOM:
|
||||
if (!InBattlePyramid())
|
||||
DisplayItemMessage(taskId, FONT_NORMAL, gText_BoxFull, CloseItemMessage);
|
||||
else
|
||||
DisplayItemMessageInBattlePyramid(taskId, gText_BoxFull, Task_CloseBattlePyramidBagMessage);
|
||||
break;
|
||||
#if B_SEMI_INVULNERABLE_CATCH >= GEN_4
|
||||
case 3: // Semi-Invulnerable
|
||||
case BALL_THROW_UNABLE_SEMI_INVULNERABLE:
|
||||
if (!InBattlePyramid())
|
||||
DisplayItemMessage(taskId, FONT_NORMAL, sText_CantThrowPokeBall_SemiInvulnerable, CloseItemMessage);
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user