Skip to content
This repository has been archived by the owner on Feb 4, 2024. It is now read-only.

Commit

Permalink
Fix up optimised player battle controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ShinyDragonHunter committed Sep 7, 2020
1 parent 04842e7 commit 49874d4
Showing 1 changed file with 39 additions and 40 deletions.
79 changes: 39 additions & 40 deletions src/battle_controller_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ static void PlayerHandleStatusXor(void);
static void PlayerDoNothing(void);
static void PlayerHandleDMA3Transfer(void);
static void PlayerHandlePlayBGM(void);
static void PlayerDoNothing(void);
static void PlayerHandleTwoReturnValues(void);
static void PlayerHandleChosenMonReturnValue(void);
static void PlayerHandleOneReturnValue(void);
Expand Down Expand Up @@ -231,12 +230,12 @@ static void HandleInputChooseAction(void)
DoBounceEffect(gActiveBattler, BOUNCE_HEALTHBOX, 7, 1);
DoBounceEffect(gActiveBattler, BOUNCE_MON, 7, 1);

if (gMain.newAndRepeatedKeys & DPAD_ANY && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A)
if (JOY_REPEAT(DPAD_ANY) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A)
gPlayerDpadHoldFrames++;
else
gPlayerDpadHoldFrames = 0;

if (gMain.newKeys & A_BUTTON)
if (JOY_NEW(A_BUTTON))
{
PlaySE(SE_SELECT);

Expand All @@ -257,7 +256,7 @@ static void HandleInputChooseAction(void)
}
PlayerBufferExecCompleted();
}
else if (gMain.newKeys & DPAD_LEFT)
else if (JOY_NEW(DPAD_LEFT))
{
if (gActionSelectionCursor[gActiveBattler] & 1) // if is B_ACTION_USE_ITEM or B_ACTION_RUN
{
Expand All @@ -267,7 +266,7 @@ static void HandleInputChooseAction(void)
ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0);
}
}
else if (gMain.newKeys & DPAD_RIGHT)
else if (JOY_NEW(DPAD_RIGHT))
{
if (!(gActionSelectionCursor[gActiveBattler] & 1)) // if is B_ACTION_USE_MOVE or B_ACTION_SWITCH
{
Expand All @@ -277,7 +276,7 @@ static void HandleInputChooseAction(void)
ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0);
}
}
else if (gMain.newKeys & DPAD_UP)
else if (JOY_NEW(DPAD_UP))
{
if (gActionSelectionCursor[gActiveBattler] & 2) // if is B_ACTION_SWITCH or B_ACTION_RUN
{
Expand All @@ -287,7 +286,7 @@ static void HandleInputChooseAction(void)
ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0);
}
}
else if (gMain.newKeys & DPAD_DOWN)
else if (JOY_NEW(DPAD_DOWN))
{
if (!(gActionSelectionCursor[gActiveBattler] & 2)) // if is B_ACTION_USE_MOVE or B_ACTION_USE_ITEM
{
Expand All @@ -297,7 +296,7 @@ static void HandleInputChooseAction(void)
ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0);
}
}
else if (gMain.newKeys & B_BUTTON || gPlayerDpadHoldFrames > 59)
else if (JOY_NEW(B_BUTTON) || gPlayerDpadHoldFrames > 59)
{
if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
&& GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_RIGHT
Expand All @@ -317,7 +316,7 @@ static void HandleInputChooseAction(void)
PlayerBufferExecCompleted();
}
}
else if (gMain.newKeys & START_BUTTON)
else if (JOY_NEW(START_BUTTON))
{
SwapHpBarsWithHpText();
}
Expand All @@ -343,20 +342,20 @@ static void HandleInputChooseTarget(void)
} while (i < gBattlersCount);
}

if (gMain.heldKeys & DPAD_ANY && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A)
if (JOY_HELD(DPAD_ANY) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A)
gPlayerDpadHoldFrames++;
else
gPlayerDpadHoldFrames = 0;

if (gMain.newKeys & A_BUTTON)
if (JOY_NEW(A_BUTTON))
{
PlaySE(SE_SELECT);
gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_HideAsMoveTarget;
BtlController_EmitTwoReturnValues(1, 10, gMoveSelectionCursor[gActiveBattler] | (gMultiUsePlayerCursor << 8));
EndBounceEffect(gMultiUsePlayerCursor, BOUNCE_HEALTHBOX);
PlayerBufferExecCompleted();
}
else if (gMain.newKeys & B_BUTTON || gPlayerDpadHoldFrames > 59)
else if (JOY_NEW(B_BUTTON) || gPlayerDpadHoldFrames > 59)
{
PlaySE(SE_SELECT);
gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_HideAsMoveTarget;
Expand All @@ -365,7 +364,7 @@ static void HandleInputChooseTarget(void)
DoBounceEffect(gActiveBattler, BOUNCE_MON, 7, 1);
EndBounceEffect(gMultiUsePlayerCursor, BOUNCE_HEALTHBOX);
}
else if (gMain.newKeys & (DPAD_LEFT | DPAD_UP))
else if (JOY_NEW(DPAD_LEFT | DPAD_UP))
{
PlaySE(SE_SELECT);
gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_HideAsMoveTarget;
Expand Down Expand Up @@ -407,7 +406,7 @@ static void HandleInputChooseTarget(void)
} while (i == 0);
gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_ShowAsMoveTarget;
}
else if (gMain.newKeys & (DPAD_RIGHT | DPAD_DOWN))
else if (JOY_NEW(DPAD_RIGHT | DPAD_DOWN))
{
PlaySE(SE_SELECT);
gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_HideAsMoveTarget;
Expand Down Expand Up @@ -456,12 +455,12 @@ static void HandleInputChooseMove(void)
bool32 canSelectTarget = FALSE;
struct ChooseMoveStruct *moveInfo = (struct ChooseMoveStruct*)(&gBattleBufferA[gActiveBattler][4]);

if (gMain.heldKeys & DPAD_ANY && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A)
if (JOY_HELD(DPAD_ANY) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A)
gPlayerDpadHoldFrames++;
else
gPlayerDpadHoldFrames = 0;

if (gMain.newKeys & A_BUTTON)
if (JOY_NEW(A_BUTTON))
{
u8 moveTarget;

Expand Down Expand Up @@ -523,13 +522,13 @@ static void HandleInputChooseMove(void)
gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_ShowAsMoveTarget;
}
}
else if (gMain.newKeys & B_BUTTON || gPlayerDpadHoldFrames > 59)
else if (JOY_NEW(B_BUTTON) || gPlayerDpadHoldFrames > 59)
{
PlaySE(SE_SELECT);
BtlController_EmitTwoReturnValues(1, 10, 0xFFFF);
PlayerBufferExecCompleted();
}
else if (gMain.newKeys & DPAD_LEFT)
else if (JOY_NEW(DPAD_LEFT))
{
if (gMoveSelectionCursor[gActiveBattler] & 1)
{
Expand All @@ -541,7 +540,7 @@ static void HandleInputChooseMove(void)
MoveSelectionDisplayMoveType();
}
}
else if (gMain.newKeys & DPAD_RIGHT)
else if (JOY_NEW(DPAD_RIGHT))
{
if (!(gMoveSelectionCursor[gActiveBattler] & 1)
&& (gMoveSelectionCursor[gActiveBattler] ^ 1) < gNumberOfMovesToChoose)
Expand All @@ -554,7 +553,7 @@ static void HandleInputChooseMove(void)
MoveSelectionDisplayMoveType();
}
}
else if (gMain.newKeys & DPAD_UP)
else if (JOY_NEW(DPAD_UP))
{
if (gMoveSelectionCursor[gActiveBattler] & 2)
{
Expand All @@ -566,7 +565,7 @@ static void HandleInputChooseMove(void)
MoveSelectionDisplayMoveType();
}
}
else if (gMain.newKeys & DPAD_DOWN)
else if (JOY_NEW(DPAD_DOWN))
{
if (!(gMoveSelectionCursor[gActiveBattler] & 2)
&& (gMoveSelectionCursor[gActiveBattler] ^ 2) < gNumberOfMovesToChoose)
Expand All @@ -579,7 +578,7 @@ static void HandleInputChooseMove(void)
MoveSelectionDisplayMoveType();
}
}
else if (gMain.newKeys & SELECT_BUTTON)
else if (JOY_NEW(SELECT_BUTTON))
{
if (gNumberOfMovesToChoose > 1 && !(gBattleTypeFlags & BATTLE_TYPE_LINK))
{
Expand All @@ -603,7 +602,7 @@ static void HandleMoveSwitching(void)
struct ChooseMoveStruct moveStruct;
u8 totalPPBonuses;

if (gMain.newKeys & (A_BUTTON | SELECT_BUTTON))
if (JOY_NEW(A_BUTTON | SELECT_BUTTON))
{
PlaySE(SE_SELECT);

Expand Down Expand Up @@ -697,7 +696,7 @@ static void HandleMoveSwitching(void)
MoveSelectionDisplayPpNumber();
MoveSelectionDisplayMoveType();
}
else if (gMain.newKeys & (B_BUTTON | SELECT_BUTTON))
else if (JOY_NEW(B_BUTTON | SELECT_BUTTON))
{
PlaySE(SE_SELECT);
MoveSelectionDestroyCursorAt(gMultiUsePlayerCursor);
Expand All @@ -707,7 +706,7 @@ static void HandleMoveSwitching(void)
MoveSelectionDisplayPpNumber();
MoveSelectionDisplayMoveType();
}
else if (gMain.newKeys & DPAD_LEFT)
else if (JOY_NEW(DPAD_LEFT))
{
if (gMultiUsePlayerCursor & 1)
{
Expand All @@ -725,7 +724,7 @@ static void HandleMoveSwitching(void)
MoveSelectionCreateCursorAt(gMultiUsePlayerCursor, 27);
}
}
else if (gMain.newKeys & DPAD_RIGHT)
else if (JOY_NEW(DPAD_RIGHT))
{
if (!(gMultiUsePlayerCursor & 1) && (gMultiUsePlayerCursor ^ 1) < gNumberOfMovesToChoose)
{
Expand All @@ -743,7 +742,7 @@ static void HandleMoveSwitching(void)
MoveSelectionCreateCursorAt(gMultiUsePlayerCursor, 27);
}
}
else if (gMain.newKeys & DPAD_UP)
else if (JOY_NEW(DPAD_UP))
{
if (gMultiUsePlayerCursor & 2)
{
Expand All @@ -761,7 +760,7 @@ static void HandleMoveSwitching(void)
MoveSelectionCreateCursorAt(gMultiUsePlayerCursor, 27);
}
}
else if (gMain.newKeys & DPAD_DOWN)
else if (JOY_NEW(DPAD_DOWN))
{
if (!(gMultiUsePlayerCursor & 2) && (gMultiUsePlayerCursor ^ 2) < gNumberOfMovesToChoose)
{
Expand Down Expand Up @@ -882,10 +881,10 @@ static void sub_805896C(void)
if (var && gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim
&& gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].finishedShinyMonAnim)
{
gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].triedShinyMonAnim = 0;
gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim = 0;
gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].triedShinyMonAnim = 0;
gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].finishedShinyMonAnim = 0;
gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].triedShinyMonAnim = FALSE;
gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim = FALSE;
gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].triedShinyMonAnim = FALSE;
gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].finishedShinyMonAnim = FALSE;
FreeSpriteTilesByTag(0x27F9);
FreeSpritePaletteByTag(0x27F9);

Expand All @@ -905,11 +904,11 @@ static void sub_8058B40(void)
bool32 r8 = FALSE;

if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].triedShinyMonAnim
&& !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].ballAnimActive)
&& !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].ballAnimActive)
TryShinyAnimation(gActiveBattler, &gPlayerParty[gBattlerPartyIndexes[gActiveBattler]]);

if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].triedShinyMonAnim
&& !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].ballAnimActive)
&& !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].ballAnimActive)
TryShinyAnimation(gActiveBattler ^ BIT_FLANK, &gPlayerParty[gBattlerPartyIndexes[gActiveBattler ^ BIT_FLANK]]);

if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].ballAnimActive && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler ^ BIT_FLANK].ballAnimActive)
Expand Down Expand Up @@ -985,8 +984,8 @@ static void sub_8058EDC(void)
&& gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy)
{
CopyBattleSpriteInvisibility(gActiveBattler);
gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].triedShinyMonAnim = 0;
gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim = 0;
gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].triedShinyMonAnim = FALSE;
gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim = FALSE;
FreeSpriteTilesByTag(0x27F9);
FreeSpritePaletteByTag(0x27F9);

Expand Down Expand Up @@ -1327,21 +1326,21 @@ static void DoHitAnimBlinkSpriteEffect(void)

static void PlayerHandleUnknownYesNoInput(void)
{
if (gMain.newKeys & DPAD_UP && gMultiUsePlayerCursor != 0)
if (JOY_NEW(DPAD_UP) && gMultiUsePlayerCursor != 0)
{
PlaySE(SE_SELECT);
BattleDestroyYesNoCursorAt(gMultiUsePlayerCursor);
gMultiUsePlayerCursor = 0;
BattleCreateYesNoCursorAt(0);
}
if (gMain.newKeys & DPAD_DOWN && gMultiUsePlayerCursor == 0)
if (JOY_NEW(DPAD_DOWN) && gMultiUsePlayerCursor == 0)
{
PlaySE(SE_SELECT);
BattleDestroyYesNoCursorAt(gMultiUsePlayerCursor);
gMultiUsePlayerCursor = 1;
BattleCreateYesNoCursorAt(1);
}
if (gMain.newKeys & A_BUTTON)
if (JOY_NEW(A_BUTTON))
{
HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR);
PlaySE(SE_SELECT);
Expand All @@ -1353,7 +1352,7 @@ static void PlayerHandleUnknownYesNoInput(void)

PlayerBufferExecCompleted();
}
if (gMain.newKeys & B_BUTTON)
if (JOY_NEW(B_BUTTON))
{
HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR);
PlaySE(SE_SELECT);
Expand Down

0 comments on commit 49874d4

Please sign in to comment.