diff options
author | jiangzhengwenjz <jiangzhengwenjzw@qq.com> | 2019-07-29 06:47:34 +0800 |
---|---|---|
committer | jiangzhengwenjz <jiangzhengwenjzw@qq.com> | 2019-07-31 07:58:08 +0800 |
commit | a4263a6bd8fa3a31d2b1de1279414b403a58e28b (patch) | |
tree | 0e078ce0ceecc2c99bdc89c81171baad0a8ffb02 /src | |
parent | 935f93a0752604f1375c79e6225baa6774b60280 (diff) |
ported battle_controller_safari from pokeem
Diffstat (limited to 'src')
-rw-r--r-- | src/battle_controller_safari.c | 677 |
1 files changed, 677 insertions, 0 deletions
diff --git a/src/battle_controller_safari.c b/src/battle_controller_safari.c new file mode 100644 index 000000000..5a2f20ef4 --- /dev/null +++ b/src/battle_controller_safari.c @@ -0,0 +1,677 @@ +#include "global.h" +#include "battle.h" +#include "battle_anim.h" +#include "battle_controllers.h" +#include "battle_interface.h" +#include "battle_message.h" +#include "bg.h" +#include "data2.h" +#include "item_menu.h" +#include "link.h" +#include "main.h" +#include "m4a.h" +#include "palette.h" +#include "pokeball.h" +#include "pokemon.h" +#include "reshow_battle_screen.h" +#include "sound.h" +#include "task.h" +#include "text.h" +#include "util.h" +#include "window.h" +#include "strings.h" +#include "constants/songs.h" +#include "constants/battle_anim.h" + +static void SafariHandleGetMonData(void); +static void SafariHandleGetRawMonData(void); +static void SafariHandleSetMonData(void); +static void SafariHandleSetRawMonData(void); +static void SafariHandleLoadMonSprite(void); +static void SafariHandleSwitchInAnim(void); +static void SafariHandleReturnMonToBall(void); +static void SafariHandleDrawTrainerPic(void); +static void SafariHandleTrainerSlide(void); +static void SafariHandleTrainerSlideBack(void); +static void SafariHandleFaintAnimation(void); +static void SafariHandlePaletteFade(void); +static void SafariHandleSuccessBallThrowAnim(void); +static void SafariHandleBallThrowAnim(void); +static void SafariHandlePause(void); +static void SafariHandleMoveAnimation(void); +static void SafariHandlePrintString(void); +static void SafariHandlePrintSelectionString(void); +static void SafariHandleChooseAction(void); +static void SafariHandleUnknownYesNoBox(void); +static void SafariHandleChooseMove(void); +static void SafariHandleChooseItem(void); +static void SafariHandleChoosePokemon(void); +static void SafariHandleCmd23(void); +static void SafariHandleHealthBarUpdate(void); +static void SafariHandleExpUpdate(void); +static void SafariHandleStatusIconUpdate(void); +static void SafariHandleStatusAnimation(void); +static void SafariHandleStatusXor(void); +static void SafariHandleDataTransfer(void); +static void SafariHandleDMA3Transfer(void); +static void SafariHandlePlayBGM(void); +static void SafariHandleCmd32(void); +static void SafariHandleTwoReturnValues(void); +static void SafariHandleChosenMonReturnValue(void); +static void SafariHandleOneReturnValue(void); +static void SafariHandleOneReturnValue_Duplicate(void); +static void SafariHandleCmd37(void); +static void SafariHandleCmd38(void); +static void SafariHandleCmd39(void); +static void SafariHandleCmd40(void); +static void SafariHandleHitAnimation(void); +static void SafariHandleCmd42(void); +static void SafariHandlePlaySE(void); +static void SafariHandlePlayFanfareOrBGM(void); +static void SafariHandleFaintingCry(void); +static void SafariHandleIntroSlide(void); +static void SafariHandleIntroTrainerBallThrow(void); +static void SafariHandleDrawPartyStatusSummary(void); +static void SafariHandleHidePartyStatusSummary(void); +static void SafariHandleEndBounceEffect(void); +static void SafariHandleSpriteInvisibility(void); +static void SafariHandleBattleAnimation(void); +static void SafariHandleLinkStandbyMsg(void); +static void SafariHandleResetActionMoveSelection(void); +static void SafariHandleCmd55(void); +static void SafariCmdEnd(void); + +static void SafariBufferRunCommand(void); +static void SafariBufferExecCompleted(void); +static void CompleteWhenChosePokeblock(void); + +static void (*const sSafariBufferCommands[CONTROLLER_CMDS_COUNT])(void) = +{ + SafariHandleGetMonData, + SafariHandleGetRawMonData, + SafariHandleSetMonData, + SafariHandleSetRawMonData, + SafariHandleLoadMonSprite, + SafariHandleSwitchInAnim, + SafariHandleReturnMonToBall, + SafariHandleDrawTrainerPic, + SafariHandleTrainerSlide, + SafariHandleTrainerSlideBack, + SafariHandleFaintAnimation, + SafariHandlePaletteFade, + SafariHandleSuccessBallThrowAnim, + SafariHandleBallThrowAnim, + SafariHandlePause, + SafariHandleMoveAnimation, + SafariHandlePrintString, + SafariHandlePrintSelectionString, + SafariHandleChooseAction, + SafariHandleUnknownYesNoBox, + SafariHandleChooseMove, + SafariHandleChooseItem, + SafariHandleChoosePokemon, + SafariHandleCmd23, + SafariHandleHealthBarUpdate, + SafariHandleExpUpdate, + SafariHandleStatusIconUpdate, + SafariHandleStatusAnimation, + SafariHandleStatusXor, + SafariHandleDataTransfer, + SafariHandleDMA3Transfer, + SafariHandlePlayBGM, + SafariHandleCmd32, + SafariHandleTwoReturnValues, + SafariHandleChosenMonReturnValue, + SafariHandleOneReturnValue, + SafariHandleOneReturnValue_Duplicate, + SafariHandleCmd37, + SafariHandleCmd38, + SafariHandleCmd39, + SafariHandleCmd40, + SafariHandleHitAnimation, + SafariHandleCmd42, + SafariHandlePlaySE, + SafariHandlePlayFanfareOrBGM, + SafariHandleFaintingCry, + SafariHandleIntroSlide, + SafariHandleIntroTrainerBallThrow, + SafariHandleDrawPartyStatusSummary, + SafariHandleHidePartyStatusSummary, + SafariHandleEndBounceEffect, + SafariHandleSpriteInvisibility, + SafariHandleBattleAnimation, + SafariHandleLinkStandbyMsg, + SafariHandleResetActionMoveSelection, + SafariHandleCmd55, + SafariCmdEnd, +}; + +// not used +static void SpriteCB_Null4(struct Sprite *sprite) +{ +} + +void SetControllerToSafari(void) +{ + gBattlerControllerFuncs[gActiveBattler] = SafariBufferRunCommand; +} + +static void SafariBufferRunCommand(void) +{ + if (gBattleControllerExecFlags & gBitTable[gActiveBattler]) + { + if (gBattleBufferA[gActiveBattler][0] < NELEMS(sSafariBufferCommands)) + sSafariBufferCommands[gBattleBufferA[gActiveBattler][0]](); + else + SafariBufferExecCompleted(); + } +} + +static void HandleInputChooseAction(void) +{ + if (JOY_NEW(A_BUTTON)) + { + PlaySE(SE_SELECT); + + switch (gActionSelectionCursor[gActiveBattler]) + { + case 0: + EmitTwoReturnValues(1, B_ACTION_SAFARI_BALL, 0); + break; + case 1: + EmitTwoReturnValues(1, B_ACTION_SAFARI_POKEBLOCK, 0); + break; + case 2: + EmitTwoReturnValues(1, B_ACTION_SAFARI_GO_NEAR, 0); + break; + case 3: + EmitTwoReturnValues(1, B_ACTION_SAFARI_RUN, 0); + break; + } + SafariBufferExecCompleted(); + } + else if (JOY_NEW(DPAD_LEFT)) + { + if (gActionSelectionCursor[gActiveBattler] & 1) + { + PlaySE(SE_SELECT); + ActionSelectionDestroyCursorAt(gActionSelectionCursor[gActiveBattler]); + gActionSelectionCursor[gActiveBattler] ^= 1; + ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); + } + } + else if (JOY_NEW(DPAD_RIGHT)) + { + if (!(gActionSelectionCursor[gActiveBattler] & 1)) + { + PlaySE(SE_SELECT); + ActionSelectionDestroyCursorAt(gActionSelectionCursor[gActiveBattler]); + gActionSelectionCursor[gActiveBattler] ^= 1; + ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); + } + } + else if (JOY_NEW(DPAD_UP)) + { + if (gActionSelectionCursor[gActiveBattler] & 2) + { + PlaySE(SE_SELECT); + ActionSelectionDestroyCursorAt(gActionSelectionCursor[gActiveBattler]); + gActionSelectionCursor[gActiveBattler] ^= 2; + ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); + } + } + else if (JOY_NEW(DPAD_DOWN)) + { + if (!(gActionSelectionCursor[gActiveBattler] & 2)) + { + PlaySE(SE_SELECT); + ActionSelectionDestroyCursorAt(gActionSelectionCursor[gActiveBattler]); + gActionSelectionCursor[gActiveBattler] ^= 2; + ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); + } + } +} + +static void CompleteOnBattlerSpriteCallbackDummy(void) +{ + if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) + SafariBufferExecCompleted(); +} + +static void CompleteOnInactiveTextPrinter(void) +{ + if (!IsTextPrinterActive(0)) + SafariBufferExecCompleted(); +} + +static void CompleteOnHealthboxSpriteCallbackDummy(void) +{ + if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) + SafariBufferExecCompleted(); +} + +static void sub_80DD7B0(void) +{ + if (!gPaletteFade.active) + { + gMain.inBattle = FALSE; + gMain.callback1 = gPreBattleCallback1; + SetMainCallback2(gMain.savedCallback); + } +} + +static void CompleteOnSpecialAnimDone_0(void) +{ + if (!gDoingBattleAnim || !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].specialAnimActive) + SafariBufferExecCompleted(); +} + +static void SafariOpenPokeblockCase(void) +{ + if (!gPaletteFade.active) + gBattlerControllerFuncs[gActiveBattler] = CompleteWhenChosePokeblock; +} + +static void CompleteWhenChosePokeblock(void) +{ + if (gMain.callback2 == BattleMainCB2 && !gPaletteFade.active) + { + EmitOneReturnValue(1, gSpecialVar_ItemId); + SafariBufferExecCompleted(); + } +} + +static void CompleteOnFinishedBattleAnimation_3(void) +{ + if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animFromTableActive) + SafariBufferExecCompleted(); +} + +static void SafariBufferExecCompleted(void) +{ + gBattlerControllerFuncs[gActiveBattler] = SafariBufferRunCommand; + if (gBattleTypeFlags & BATTLE_TYPE_LINK) + { + u8 playerId = GetMultiplayerId(); + + PrepareBufferDataTransferLink(2, 4, &playerId); + gBattleBufferA[gActiveBattler][0] = CONTROLLER_TERMINATOR_NOP; + } + else + { + gBattleControllerExecFlags &= ~gBitTable[gActiveBattler]; + } +} + +// not used +static void CompleteOnFinishedStatusAnimation_3(void) +{ + if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].statusAnimActive) + SafariBufferExecCompleted(); +} + +static void SafariHandleGetMonData(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleGetRawMonData(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleSetMonData(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleSetRawMonData(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleLoadMonSprite(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleSwitchInAnim(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleReturnMonToBall(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleDrawTrainerPic(void) +{ + sub_8034750(gSaveBlock2Ptr->playerGender, gActiveBattler); + SetMultiuseSpriteTemplateToTrainerBack(gSaveBlock2Ptr->playerGender, GetBattlerPosition(gActiveBattler)); + gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, + 80, + (8 - gTrainerBackPicCoords[gSaveBlock2Ptr->playerGender].size) * 4 + 80, + 30); + gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = gActiveBattler; + gSprites[gBattlerSpriteIds[gActiveBattler]].pos2.x = 240; + gSprites[gBattlerSpriteIds[gActiveBattler]].data[0] = -2; + gSprites[gBattlerSpriteIds[gActiveBattler]].callback = sub_8033EEC; + gBattlerControllerFuncs[gActiveBattler] = CompleteOnBattlerSpriteCallbackDummy; +} + +static void SafariHandleTrainerSlide(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleTrainerSlideBack(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleFaintAnimation(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandlePaletteFade(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleSuccessBallThrowAnim(void) +{ + gBattleSpritesDataPtr->animationData->ballThrowCaseId = BALL_3_SHAKES_SUCCESS; + gDoingBattleAnim = TRUE; + InitAndLaunchSpecialAnimation(gActiveBattler, gActiveBattler, GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT), B_ANIM_SAFARI_BALL_THROW); + gBattlerControllerFuncs[gActiveBattler] = CompleteOnSpecialAnimDone_0; +} + +static void SafariHandleBallThrowAnim(void) +{ + u8 ballThrowCaseId = gBattleBufferA[gActiveBattler][1]; + + gBattleSpritesDataPtr->animationData->ballThrowCaseId = ballThrowCaseId; + gDoingBattleAnim = TRUE; + InitAndLaunchSpecialAnimation(gActiveBattler, gActiveBattler, GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT), B_ANIM_SAFARI_BALL_THROW); + gBattlerControllerFuncs[gActiveBattler] = CompleteOnSpecialAnimDone_0; +} + +static void SafariHandlePause(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleMoveAnimation(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandlePrintString(void) +{ + u16 *stringId; + + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + stringId = (u16*)(&gBattleBufferA[gActiveBattler][2]); + BufferStringBattle(*stringId); + if (sub_80D89B0(*stringId)) + BattlePutTextOnWindow(gDisplayedStringBattle, 0x40); + else + BattlePutTextOnWindow(gDisplayedStringBattle, 0); + gBattlerControllerFuncs[gActiveBattler] = CompleteOnInactiveTextPrinter; +} + +static void SafariHandlePrintSelectionString(void) +{ + if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + SafariHandlePrintString(); + else + SafariBufferExecCompleted(); +} + +static void HandleChooseActionAfterDma3(void) +{ + if (!IsDma3ManagerBusyWithBgCopy()) + { + gBattle_BG0_X = 0; + gBattle_BG0_Y = 160; + gBattlerControllerFuncs[gActiveBattler] = HandleInputChooseAction; + } +} + +static void SafariHandleChooseAction(void) +{ + s32 i; + + gBattlerControllerFuncs[gActiveBattler] = HandleChooseActionAfterDma3; + BattlePutTextOnWindow(gUnknown_83FDA4C, 0); + BattlePutTextOnWindow(gUnknown_83FE747, 2); + for (i = 0; i < 4; ++i) + ActionSelectionDestroyCursorAt(i); + ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); + BattleStringExpandPlaceholdersToDisplayedString(gUnknown_83FE6E6); + BattlePutTextOnWindow(gDisplayedStringBattle, 1); +} + +static void SafariHandleUnknownYesNoBox(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleChooseMove(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleChooseItem(void) +{ + s32 i; + + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); + gBattlerControllerFuncs[gActiveBattler] = SafariOpenPokeblockCase; + gBattlerInMenuId = gActiveBattler; +} + +static void SafariHandleChoosePokemon(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleCmd23(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleHealthBarUpdate(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleExpUpdate(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleStatusIconUpdate(void) +{ + UpdateHealthboxAttribute(gHealthboxSpriteIds[gActiveBattler], &gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], HEALTHBOX_SAFARI_BALLS_TEXT); + SafariBufferExecCompleted(); +} + +static void SafariHandleStatusAnimation(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleStatusXor(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleDataTransfer(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleDMA3Transfer(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandlePlayBGM(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleCmd32(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleTwoReturnValues(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleChosenMonReturnValue(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleOneReturnValue(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleOneReturnValue_Duplicate(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleCmd37(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleCmd38(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleCmd39(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleCmd40(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleHitAnimation(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleCmd42(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandlePlaySE(void) +{ + s8 pan; + + if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + pan = SOUND_PAN_ATTACKER; + else + pan = SOUND_PAN_TARGET; + PlaySE12WithPanning(gBattleBufferA[gActiveBattler][1] | (gBattleBufferA[gActiveBattler][2] << 8), pan); + SafariBufferExecCompleted(); +} + +static void SafariHandlePlayFanfareOrBGM(void) +{ + PlayFanfare(gBattleBufferA[gActiveBattler][1] | (gBattleBufferA[gActiveBattler][2] << 8)); + SafariBufferExecCompleted(); +} + +static void SafariHandleFaintingCry(void) +{ + u16 species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES); + + PlayCry1(species, 25); + SafariBufferExecCompleted(); +} + +static void SafariHandleIntroSlide(void) +{ + HandleIntroSlide(gBattleBufferA[gActiveBattler][1]); + gIntroSlideFlags |= 1; + SafariBufferExecCompleted(); +} + +static void SafariHandleIntroTrainerBallThrow(void) +{ + UpdateHealthboxAttribute(gHealthboxSpriteIds[gActiveBattler], &gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], HEALTHBOX_SAFARI_ALL_TEXT); + sub_804BD94(gActiveBattler); + SetHealthboxSpriteVisible(gHealthboxSpriteIds[gActiveBattler]); + gBattlerControllerFuncs[gActiveBattler] = CompleteOnHealthboxSpriteCallbackDummy; +} + +static void SafariHandleDrawPartyStatusSummary(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleHidePartyStatusSummary(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleEndBounceEffect(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleSpriteInvisibility(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleBattleAnimation(void) +{ + u8 animationId = gBattleBufferA[gActiveBattler][1]; + u16 argument = gBattleBufferA[gActiveBattler][2] | (gBattleBufferA[gActiveBattler][3] << 8); + + if (TryHandleLaunchBattleTableAnimation(gActiveBattler, gActiveBattler, gActiveBattler, animationId, argument)) + SafariBufferExecCompleted(); + else + gBattlerControllerFuncs[gActiveBattler] = CompleteOnFinishedBattleAnimation_3; +} + +static void SafariHandleLinkStandbyMsg(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleResetActionMoveSelection(void) +{ + SafariBufferExecCompleted(); +} + +static void SafariHandleCmd55(void) +{ + gBattleOutcome = gBattleBufferA[gActiveBattler][1]; + FadeOutMapMusic(5); + BeginFastPaletteFade(3); + SafariBufferExecCompleted(); + if ((gBattleTypeFlags & BATTLE_TYPE_LINK) && !(gBattleTypeFlags & BATTLE_TYPE_IS_MASTER)) + gBattlerControllerFuncs[gActiveBattler] = sub_80DD7B0; +} + +static void SafariCmdEnd(void) +{ +} |