DoPlayerTurn: ; 34000 call SetPlayerTurn ld a, [wBattlePlayerAction] and a ret nz jr DoTurn ; 3400a DoEnemyTurn: ; 3400a call SetEnemyTurn ld a, [wLinkMode] and a jr z, DoTurn ld a, [wBattleAction] cp BATTLEACTION_E jr z, DoTurn cp BATTLEACTION_SWITCH1 ret nc ; fallthrough ; 3401d DoTurn: ; 3401d ; Read in and execute the user's move effects for this turn. xor a ld [wTurnEnded], a ; Effect command checkturn is called for every move. call CheckTurn ld a, [wTurnEnded] and a ret nz call UpdateMoveData ; 3402c DoMove: ; 3402c ; Get the user's move effect. ld a, BATTLE_VARS_MOVE_EFFECT call GetBattleVar ld c, a ld b, 0 ld hl, MoveEffectsPointers add hl, bc add hl, bc ld a, BANK(MoveEffectsPointers) call GetFarHalfword ld de, wBattleScriptBuffer .GetMoveEffect: ld a, BANK(MoveEffects) call GetFarByte inc hl ld [de], a inc de cp -1 jr nz, .GetMoveEffect ; Start at the first command. ld hl, wBattleScriptBuffer ld a, l ld [wBattleScriptBufferAddress], a ld a, h ld [wBattleScriptBufferAddress + 1], a .ReadMoveEffectCommand: ; ld a, [wBattleScriptBufferAddress++] ld a, [wBattleScriptBufferAddress] ld l, a ld a, [wBattleScriptBufferAddress + 1] ld h, a ld a, [hli] push af ld a, l ld [wBattleScriptBufferAddress], a ld a, h ld [wBattleScriptBufferAddress + 1], a pop af ; endturn_command (-2) is used to terminate branches without ending the read cycle. cp endturn_command ret nc ; The rest of the commands (01-af) are read from BattleCommandPointers. push bc dec a ld c, a ld b, 0 ld hl, BattleCommandPointers add hl, bc add hl, bc pop bc ld a, BANK(BattleCommandPointers) call GetFarHalfword call .DoMoveEffectCommand jr .ReadMoveEffectCommand .DoMoveEffectCommand: jp hl ; 34084 CheckTurn: BattleCommand_CheckTurn: ; 34084 ; checkturn ; Repurposed as hardcoded turn handling. Useless as a command. ; Move $ff immediately ends the turn. ld a, BATTLE_VARS_MOVE call GetBattleVar inc a jp z, EndTurn xor a ld [wAttackMissed], a ld [wEffectFailed], a ld [wKickCounter], a ld [wAlreadyDisobeyed], a ld [wAlreadyFailed], a ld [wSomeoneIsRampaging], a ld a, EFFECTIVE ld [wTypeModifier], a ld a, [hBattleTurn] and a jp nz, CheckEnemyTurn CheckPlayerTurn: ld hl, wPlayerSubStatus4 bit SUBSTATUS_RECHARGE, [hl] jr z, .no_recharge res SUBSTATUS_RECHARGE, [hl] ld hl, MustRechargeText call StdBattleTextBox call CantMove jp EndTurn .no_recharge ld hl, wBattleMonStatus ld a, [hl] and SLP jr z, .not_asleep dec a ld [wBattleMonStatus], a and SLP jr z, .woke_up xor a ld [wNumHits], a ld de, ANIM_SLP call FarPlayBattleAnimation jr .fast_asleep .woke_up ld hl, WokeUpText call StdBattleTextBox call CantMove call UpdateBattleMonInParty ld hl, UpdatePlayerHUD call CallBattleCore ld a, $1 ld [hBGMapMode], a ld hl, wPlayerSubStatus1 res SUBSTATUS_NIGHTMARE, [hl] jr .not_asleep .fast_asleep ld hl, FastAsleepText call StdBattleTextBox ; Snore and Sleep Talk bypass sleep. ld a, [wCurPlayerMove] cp SNORE jr z, .not_asleep cp SLEEP_TALK jr z, .not_asleep call CantMove jp EndTurn .not_asleep ld hl, wBattleMonStatus bit FRZ, [hl] jr z, .not_frozen ; Flame Wheel and Sacred Fire thaw the user. ld a, [wCurPlayerMove] cp FLAME_WHEEL jr z, .not_frozen cp SACRED_FIRE jr z, .not_frozen ld hl, FrozenSolidText call StdBattleTextBox call CantMove jp EndTurn .not_frozen ld hl, wPlayerSubStatus3 bit SUBSTATUS_FLINCHED, [hl] jr z, .not_flinched res SUBSTATUS_FLINCHED, [hl] ld hl, FlinchedText call StdBattleTextBox call CantMove jp EndTurn .not_flinched ld hl, wPlayerDisableCount ld a, [hl] and a jr z, .not_disabled dec a ld [hl], a and $f jr nz, .not_disabled ld [hl], a ld [wDisabledMove], a ld hl, DisabledNoMoreText call StdBattleTextBox .not_disabled ld a, [wPlayerSubStatus3] add a jr nc, .not_confused ld hl, wPlayerConfuseCount dec [hl] jr nz, .confused ld hl, wPlayerSubStatus3 res SUBSTATUS_CONFUSED, [hl] ld hl, ConfusedNoMoreText call StdBattleTextBox jr .not_confused .confused ld hl, IsConfusedText call StdBattleTextBox xor a ld [wNumHits], a ld de, ANIM_CONFUSED call FarPlayBattleAnimation ; 50% chance of hitting itself call BattleRandom cp 50 percent + 1 jr nc, .not_confused ; clear confusion-dependent substatus ld hl, wPlayerSubStatus3 ld a, [hl] and 1 << SUBSTATUS_CONFUSED ld [hl], a call HitConfusion call CantMove jp EndTurn .not_confused ld a, [wPlayerSubStatus1] add a ; bit SUBSTATUS_ATTRACT jr nc, .not_infatuated ld hl, InLoveWithText call StdBattleTextBox xor a ld [wNumHits], a ld de, ANIM_IN_LOVE call FarPlayBattleAnimation ; 50% chance of infatuation call BattleRandom cp 50 percent + 1 jr c, .not_infatuated ld hl, InfatuationText call StdBattleTextBox call CantMove jp EndTurn .not_infatuated ; We can't disable a move that doesn't exist. ld a, [wDisabledMove] and a jr z, .no_disabled_move ; Are we using the disabled move? ld hl, wCurPlayerMove cp [hl] jr nz, .no_disabled_move call MoveDisabled call CantMove jp EndTurn .no_disabled_move ld hl, wBattleMonStatus bit PAR, [hl] ret z ; 25% chance to be fully paralyzed call BattleRandom cp 25 percent ret nc ld hl, FullyParalyzedText call StdBattleTextBox call CantMove jp EndTurn ; 341f0 CantMove: ; 341f0 ld a, BATTLE_VARS_SUBSTATUS1 call GetBattleVarAddr res SUBSTATUS_ROLLOUT, [hl] ld a, BATTLE_VARS_SUBSTATUS3 call GetBattleVarAddr ld a, [hl] and $ff ^ (1<" start_asm ld a, BATTLE_VARS_MOVE_ANIM call GetBattleVar cp RAZOR_WIND ld hl, .RazorWind jr z, .done cp SOLARBEAM ld hl, .Solarbeam jr z, .done cp SKULL_BASH ld hl, .SkullBash jr z, .done cp SKY_ATTACK ld hl, .SkyAttack jr z, .done cp FLY ld hl, .Fly jr z, .done cp DIG ld hl, .Dig .done ret .RazorWind: ; 'made a whirlwind!' text_jump UnknownText_0x1c0d12 db "@" .Solarbeam: ; 'took in sunlight!' text_jump UnknownText_0x1c0d26 db "@" .SkullBash: ; 'lowered its head!' text_jump UnknownText_0x1c0d3a db "@" .SkyAttack: ; 'is glowing!' text_jump UnknownText_0x1c0d4e db "@" .Fly: ; 'flew up high!' text_jump UnknownText_0x1c0d5c db "@" .Dig: ; 'dug a hole!' text_jump UnknownText_0x1c0d6c db "@" ; 36c2c BattleCommand3c: ; 36c2c ; unused ret ; 36c2d BattleCommand_TrapTarget: ; 36c2d ; traptarget ld a, [wAttackMissed] and a ret nz ld hl, wEnemyWrapCount ld de, wEnemyTrappingMove ld a, [hBattleTurn] and a jr z, .got_trap ld hl, wPlayerWrapCount ld de, wPlayerTrappingMove .got_trap ld a, [hl] and a ret nz ld a, BATTLE_VARS_SUBSTATUS4_OPP call GetBattleVar bit SUBSTATUS_SUBSTITUTE, a ret nz call BattleRandom ; trapped for 2-5 turns and %11 inc a inc a inc a ld [hl], a ld a, BATTLE_VARS_MOVE_ANIM call GetBattleVar ld [de], a ld b, a ld hl, .Traps .find_trap_text ld a, [hli] cp b jr z, .found_trap_text inc hl inc hl jr .find_trap_text .found_trap_text ld a, [hli] ld h, [hl] ld l, a jp StdBattleTextBox .Traps: dbw BIND, UsedBindText ; 'used BIND on' dbw WRAP, WrappedByText ; 'was WRAPPED by' dbw FIRE_SPIN, FireSpinTrapText ; 'was trapped!' dbw CLAMP, ClampedByText ; 'was CLAMPED by' dbw WHIRLPOOL, WhirlpoolTrapText ; 'was trapped!' ; 36c7e INCLUDE "engine/battle/move_effects/mist.asm" INCLUDE "engine/battle/move_effects/focus_energy.asm" BattleCommand_Recoil: ; 36cb2 ; recoil ld hl, wBattleMonMaxHP ld a, [hBattleTurn] and a jr z, .got_hp ld hl, wEnemyMonMaxHP .got_hp ld a, BATTLE_VARS_MOVE_ANIM call GetBattleVar ld d, a ; get 1/4 damage or 1 HP, whichever is higher ld a, [wCurDamage] ld b, a ld a, [wCurDamage + 1] ld c, a srl b rr c srl b rr c ld a, b or c jr nz, .min_damage inc c .min_damage ld a, [hli] ld [wBuffer2], a ld a, [hl] ld [wBuffer1], a dec hl dec hl ld a, [hl] ld [wBuffer3], a sub c ld [hld], a ld [wBuffer5], a ld a, [hl] ld [wBuffer4], a sbc b ld [hl], a ld [wBuffer6], a jr nc, .dont_ko xor a ld [hli], a ld [hl], a ld hl, wBuffer5 ld [hli], a ld [hl], a .dont_ko hlcoord 10, 9 ld a, [hBattleTurn] and a ld a, 1 jr z, .animate_hp_bar hlcoord 2, 2 xor a .animate_hp_bar ld [wWhichHPBar], a predef AnimateHPBar call RefreshBattleHuds ld hl, RecoilText jp StdBattleTextBox ; 36d1d BattleCommand_ConfuseTarget: ; 36d1d ; confusetarget call GetOpponentItem ld a, b cp HELD_PREVENT_CONFUSE ret z ld a, [wEffectFailed] and a ret nz call SafeCheckSafeguard ret nz call CheckSubstituteOpp ret nz ld a, BATTLE_VARS_SUBSTATUS3_OPP call GetBattleVarAddr bit SUBSTATUS_CONFUSED, [hl] ret nz jr BattleCommand_FinishConfusingTarget BattleCommand_Confuse: ; 36d3b ; confuse call GetOpponentItem ld a, b cp HELD_PREVENT_CONFUSE jr nz, .no_item_protection ld a, [hl] ld [wNamedObjectIndexBuffer], a call GetItemName call AnimateFailedMove ld hl, ProtectedByText jp StdBattleTextBox .no_item_protection ld a, BATTLE_VARS_SUBSTATUS3_OPP call GetBattleVarAddr bit SUBSTATUS_CONFUSED, [hl] jr z, .not_already_confused call AnimateFailedMove ld hl, AlreadyConfusedText jp StdBattleTextBox .not_already_confused call CheckSubstituteOpp jr nz, BattleCommand_Confuse_CheckSnore_Swagger_ConfuseHit ld a, [wAttackMissed] and a jr nz, BattleCommand_Confuse_CheckSnore_Swagger_ConfuseHit BattleCommand_FinishConfusingTarget: ; 36d70 ld bc, wEnemyConfuseCount ld a, [hBattleTurn] and a jr z, .got_confuse_count ld bc, wPlayerConfuseCount .got_confuse_count set SUBSTATUS_CONFUSED, [hl] ; confused for 2-5 turns call BattleRandom and %11 inc a inc a ld [bc], a ld a, BATTLE_VARS_MOVE_EFFECT call GetBattleVar cp EFFECT_CONFUSE_HIT jr z, .got_effect cp EFFECT_SNORE jr z, .got_effect cp EFFECT_SWAGGER jr z, .got_effect call AnimateCurrentMove .got_effect ld de, ANIM_CONFUSED call PlayOpponentBattleAnim ld hl, BecameConfusedText call StdBattleTextBox call GetOpponentItem ld a, b cp HELD_HEAL_STATUS jr z, .heal_confusion cp HELD_HEAL_CONFUSION ret nz .heal_confusion ld hl, UseConfusionHealingItem jp CallBattleCore ; 36db6 BattleCommand_Confuse_CheckSnore_Swagger_ConfuseHit: ; 36db6 ld a, BATTLE_VARS_MOVE_EFFECT call GetBattleVar cp EFFECT_CONFUSE_HIT ret z cp EFFECT_SNORE ret z cp EFFECT_SWAGGER ret z jp PrintDidntAffect2 ; 36dc7 BattleCommand_Paralyze: ; 36dc7 ; paralyze ld a, BATTLE_VARS_STATUS_OPP call GetBattleVar bit PAR, a jr nz, .paralyzed ld a, [wTypeModifier] and $7f jr z, .didnt_affect call GetOpponentItem ld a, b cp HELD_PREVENT_PARALYZE jr nz, .no_item_protection ld a, [hl] ld [wNamedObjectIndexBuffer], a call GetItemName call AnimateFailedMove ld hl, ProtectedByText jp StdBattleTextBox .no_item_protection ld a, [hBattleTurn] and a jr z, .dont_sample_failure ld a, [wLinkMode] and a jr nz, .dont_sample_failure ld a, [wInBattleTowerBattle] and a jr nz, .dont_sample_failure ld a, [wPlayerSubStatus5] bit SUBSTATUS_LOCK_ON, a jr nz, .dont_sample_failure call BattleRandom cp 25 percent + 1 ; 25% chance AI fails jr c, .failed .dont_sample_failure ld a, BATTLE_VARS_STATUS_OPP call GetBattleVarAddr and a jr nz, .failed ld a, [wAttackMissed] and a jr nz, .failed call CheckSubstituteOpp jr nz, .failed ld c, 30 call DelayFrames call AnimateCurrentMove ld a, $1 ld [hBGMapMode], a ld a, BATTLE_VARS_STATUS_OPP call GetBattleVarAddr set PAR, [hl] call UpdateOpponentInParty ld hl, ApplyPrzEffectOnSpeed call CallBattleCore call UpdateBattleHuds call PrintParalyze ld hl, UseHeldStatusHealingItem jp CallBattleCore .paralyzed call AnimateFailedMove ld hl, AlreadyParalyzedText jp StdBattleTextBox .failed jp PrintDidntAffect2 .didnt_affect call AnimateFailedMove jp PrintDoesntAffect ; 36e5b CheckMoveTypeMatchesTarget: ; 36e5b ; Compare move type to opponent type. ; Return z if matching the opponent type, ; unless the move is Normal (Tri Attack). push hl ld hl, wEnemyMonType1 ld a, [hBattleTurn] and a jr z, .ok ld hl, wBattleMonType1 .ok ld a, BATTLE_VARS_MOVE_TYPE call GetBattleVar cp NORMAL jr z, .normal cp [hl] jr z, .return inc hl cp [hl] .return pop hl ret .normal ld a, 1 and a pop hl ret ; 36e7c INCLUDE "engine/battle/move_effects/substitute.asm" BattleCommand_RechargeNextTurn: ; 36f0b ; rechargenextturn ld a, BATTLE_VARS_SUBSTATUS4 call GetBattleVarAddr set SUBSTATUS_RECHARGE, [hl] ret ; 36f13 EndRechargeOpp: ; 36f13 push hl ld a, BATTLE_VARS_SUBSTATUS4_OPP call GetBattleVarAddr res SUBSTATUS_RECHARGE, [hl] pop hl ret ; 36f1d INCLUDE "engine/battle/move_effects/rage.asm" BattleCommand_DoubleFlyingDamage: ; 36f25 ; doubleflyingdamage ld a, BATTLE_VARS_SUBSTATUS3_OPP call GetBattleVar bit SUBSTATUS_FLYING, a ret z jr DoubleDamage ; 36f2f BattleCommand_DoubleUndergroundDamage: ; 36f2f ; doubleundergrounddamage ld a, BATTLE_VARS_SUBSTATUS3_OPP call GetBattleVar bit SUBSTATUS_UNDERGROUND, a ret z ; fallthrough ; 36f37 DoubleDamage: ; 36f37 ld hl, wCurDamage + 1 sla [hl] dec hl rl [hl] jr nc, .quit ld a, $ff ld [hli], a ld [hl], a .quit ret ; 36f46 INCLUDE "engine/battle/move_effects/mimic.asm" INCLUDE "engine/battle/move_effects/leech_seed.asm" INCLUDE "engine/battle/move_effects/splash.asm" INCLUDE "engine/battle/move_effects/disable.asm" INCLUDE "engine/battle/move_effects/pay_day.asm" INCLUDE "engine/battle/move_effects/conversion.asm" BattleCommand_ResetStats: ; 3710e ; resetstats ld a, 7 ; neutral ld hl, wPlayerStatLevels call .Fill ld hl, wEnemyStatLevels call .Fill ld a, [hBattleTurn] push af call SetPlayerTurn call CalcPlayerStats call SetEnemyTurn call CalcEnemyStats pop af ld [hBattleTurn], a call AnimateCurrentMove ld hl, EliminatedStatsText jp StdBattleTextBox .Fill: ld b, wPlayerStatLevelsEnd - wPlayerStatLevels .next ld [hli], a dec b jr nz, .next ret ; 3713e BattleCommand_Heal: ; 3713e ; heal ld de, wBattleMonHP ld hl, wBattleMonMaxHP ld a, [hBattleTurn] and a jr z, .got_hp ld de, wEnemyMonHP ld hl, wEnemyMonMaxHP .got_hp ld a, BATTLE_VARS_MOVE_ANIM call GetBattleVar ld b, a push hl push de push bc ld c, 2 call StringCmp pop bc pop de pop hl jp z, .hp_full ld a, b cp REST jr nz, .not_rest push hl push de push af call BattleCommand_MoveDelay ld a, BATTLE_VARS_SUBSTATUS5 call GetBattleVarAddr res SUBSTATUS_TOXIC, [hl] ld a, BATTLE_VARS_STATUS call GetBattleVarAddr ld a, [hl] and a ld [hl], REST_SLEEP_TURNS + 1 ld hl, WentToSleepText jr z, .no_status_to_heal ld hl, RestedText .no_status_to_heal call StdBattleTextBox ld a, [hBattleTurn] and a jr nz, .calc_enemy_stats call CalcPlayerStats jr .got_stats .calc_enemy_stats call CalcEnemyStats .got_stats pop af pop de pop hl .not_rest jr z, .restore_full_hp ld hl, GetHalfMaxHP call CallBattleCore jr .finish .restore_full_hp ld hl, GetMaxHP call CallBattleCore .finish call AnimateCurrentMove call BattleCommand_SwitchTurn ld hl, RestoreHP call CallBattleCore call BattleCommand_SwitchTurn call UpdateUserInParty call RefreshBattleHuds ld hl, RegainedHealthText jp StdBattleTextBox .hp_full call AnimateFailedMove ld hl, HPIsFullText jp StdBattleTextBox ; 371cd INCLUDE "engine/battle/move_effects/transform.asm" BattleSideCopy: ; 372c6 ; Copy bc bytes from hl to de if it's the player's turn. ; Copy bc bytes from de to hl if it's the enemy's turn. ld a, [hBattleTurn] and a jr z, .copy ; Swap hl and de push hl ld h, d ld l, e pop de .copy jp CopyBytes ; 372d2 BattleEffect_ButItFailed: ; 372d2 call AnimateFailedMove jp PrintButItFailed ; 372d8 ClearLastMove: ; 372d8 ld a, BATTLE_VARS_LAST_COUNTER_MOVE call GetBattleVarAddr xor a ld [hl], a ld a, BATTLE_VARS_LAST_MOVE call GetBattleVarAddr xor a ld [hl], a ret ; 372e7 ResetActorDisable: ; 372e7 ld a, [hBattleTurn] and a jr z, .player xor a ld [wEnemyDisableCount], a ld [wEnemyDisabledMove], a ret .player xor a ld [wPlayerDisableCount], a ld [wDisabledMove], a ret ; 372fc BattleCommand_Screen: ; 372fc ; screen ld hl, wPlayerScreens ld bc, wPlayerLightScreenCount ld a, [hBattleTurn] and a jr z, .got_screens_pointer ld hl, wEnemyScreens ld bc, wEnemyLightScreenCount .got_screens_pointer ld a, BATTLE_VARS_MOVE_EFFECT call GetBattleVar cp EFFECT_LIGHT_SCREEN jr nz, .Reflect bit SCREENS_LIGHT_SCREEN, [hl] jr nz, .failed set SCREENS_LIGHT_SCREEN, [hl] ld a, 5 ld [bc], a ld hl, LightScreenEffectText jr .good .Reflect: bit SCREENS_REFLECT, [hl] jr nz, .failed set SCREENS_REFLECT, [hl] ; LightScreenCount -> ReflectCount inc bc ld a, 5 ld [bc], a ld hl, ReflectEffectText .good call AnimateCurrentMove jp StdBattleTextBox .failed call AnimateFailedMove jp PrintButItFailed ; 3733d PrintDoesntAffect: ; 3733d ; 'it doesn't affect' ld hl, DoesntAffectText jp StdBattleTextBox ; 37343 PrintNothingHappened: ; 37343 ; 'but nothing happened!' ld hl, NothingHappenedText jp StdBattleTextBox ; 37349 TryPrintButItFailed: ; 37349 ld a, [wAlreadyFailed] and a ret nz ; fallthrough ; 3734e PrintButItFailed: ; 3734e ; 'but it failed!' ld hl, ButItFailedText jp StdBattleTextBox ; 37354 FailMove: call AnimateFailedMove ; fallthrough ; 37357 FailMimic: ; 37357 ld hl, ButItFailedText ; 'but it failed!' ld de, ItFailedText ; 'it failed!' jp FailText_CheckOpponentProtect ; 37360 PrintDidntAffect: ; 37360 ; 'it didn't affect' ld hl, DidntAffect1Text jp StdBattleTextBox ; 37366 PrintDidntAffect2: ; 37366 call AnimateFailedMove ld hl, DidntAffect1Text ; 'it didn't affect' ld de, DidntAffect2Text ; 'it didn't affect' jp FailText_CheckOpponentProtect ; 37372 PrintParalyze: ; 37372 ; 'paralyzed! maybe it can't attack!' ld hl, ParalyzedText jp StdBattleTextBox ; 37378 CheckSubstituteOpp: ; 37378 ld a, BATTLE_VARS_SUBSTATUS4_OPP call GetBattleVar bit SUBSTATUS_SUBSTITUTE, a ret ; 37380 INCLUDE "engine/battle/move_effects/selfdestruct.asm" INCLUDE "engine/battle/move_effects/mirror_move.asm" INCLUDE "engine/battle/move_effects/metronome.asm" CheckUserMove: ; 37462 ; Return z if the user has move a. ld b, a ld de, wBattleMonMoves ld a, [hBattleTurn] and a jr z, .ok ld de, wEnemyMonMoves .ok ld c, NUM_MOVES .loop ld a, [de] inc de cp b ret z dec c jr nz, .loop ld a, 1 and a ret ; 3747b ResetTurn: ; 3747b ld hl, wPlayerCharging ld a, [hBattleTurn] and a jr z, .player ld hl, wEnemyCharging .player ld [hl], 1 xor a ld [wAlreadyDisobeyed], a call DoMove jp EndMoveEffect ; 37492 INCLUDE "engine/battle/move_effects/thief.asm" BattleCommand_ArenaTrap: ; 37517 ; arenatrap ; Doesn't work on an absent opponent. call CheckHiddenOpponent jr nz, .failed ; Don't trap if the opponent is already trapped. ld a, BATTLE_VARS_SUBSTATUS5 call GetBattleVarAddr bit SUBSTATUS_CANT_RUN, [hl] jr nz, .failed ; Otherwise trap the opponent. set SUBSTATUS_CANT_RUN, [hl] call AnimateCurrentMove ld hl, CantEscapeNowText jp StdBattleTextBox .failed call AnimateFailedMove jp PrintButItFailed ; 37536 INCLUDE "engine/battle/move_effects/nightmare.asm" BattleCommand_Defrost: ; 37563 ; defrost ; Thaw the user. ld a, BATTLE_VARS_STATUS call GetBattleVarAddr bit FRZ, [hl] ret z res FRZ, [hl] ; Don't update the enemy's party struct in a wild battle. ld a, [hBattleTurn] and a jr z, .party ld a, [wBattleMode] dec a jr z, .done .party ld a, MON_STATUS call UserPartyAttr res FRZ, [hl] .done call RefreshBattleHuds ld hl, WasDefrostedText jp StdBattleTextBox ; 37588 INCLUDE "engine/battle/move_effects/curse.asm" INCLUDE "engine/battle/move_effects/protect.asm" INCLUDE "engine/battle/move_effects/endure.asm" INCLUDE "engine/battle/move_effects/spikes.asm" INCLUDE "engine/battle/move_effects/foresight.asm" INCLUDE "engine/battle/move_effects/perish_song.asm" INCLUDE "engine/battle/move_effects/sandstorm.asm" INCLUDE "engine/battle/move_effects/rollout.asm" BattleCommand5d: ; 37791 ; unused ret ; 37792 INCLUDE "engine/battle/move_effects/fury_cutter.asm" INCLUDE "engine/battle/move_effects/attract.asm" INCLUDE "engine/battle/move_effects/return.asm" INCLUDE "engine/battle/move_effects/present.asm" INCLUDE "engine/battle/move_effects/frustration.asm" INCLUDE "engine/battle/move_effects/safeguard.asm" SafeCheckSafeguard: ; 37962 push hl ld hl, wEnemyScreens ld a, [hBattleTurn] and a jr z, .got_turn ld hl, wPlayerScreens .got_turn bit SCREENS_SAFEGUARD, [hl] pop hl ret ; 37972 BattleCommand_CheckSafeguard: ; 37972 ; checksafeguard ld hl, wEnemyScreens ld a, [hBattleTurn] and a jr z, .got_turn ld hl, wPlayerScreens .got_turn bit SCREENS_SAFEGUARD, [hl] ret z ld a, 1 ld [wAttackMissed], a call BattleCommand_MoveDelay ld hl, SafeguardProtectText call StdBattleTextBox jp EndMoveEffect ; 37991 INCLUDE "engine/battle/move_effects/magnitude.asm" INCLUDE "engine/battle/move_effects/baton_pass.asm" INCLUDE "engine/battle/move_effects/pursuit.asm" INCLUDE "engine/battle/move_effects/rapid_spin.asm" BattleCommand_HealMorn: ; 37b74 ; healmorn ld b, MORN_F jr BattleCommand_TimeBasedHealContinue ; 37b78 BattleCommand_HealDay: ; 37b78 ; healday ld b, DAY_F jr BattleCommand_TimeBasedHealContinue ; 37b7c BattleCommand_HealNite: ; 37b7c ; healnite ld b, NITE_F ; fallthrough ; 37b7e BattleCommand_TimeBasedHealContinue: ; 37b7e ; Time- and weather-sensitive heal. ld hl, wBattleMonMaxHP ld de, wBattleMonHP ld a, [hBattleTurn] and a jr z, .start ld hl, wEnemyMonMaxHP ld de, wEnemyMonHP .start ; Index for .Multipliers ; Default restores half max HP. ld c, 2 ; Don't bother healing if HP is already full. push bc call StringCmp pop bc jr z, .Full ; Don't factor in time of day in link battles. ld a, [wLinkMode] and a jr nz, .Weather ld a, [wTimeOfDay] cp b jr z, .Weather dec c ; double .Weather: ld a, [wBattleWeather] and a jr z, .Heal ; x2 in sun ; /2 in rain/sandstorm inc c cp WEATHER_SUN jr z, .Heal dec c dec c .Heal: ld b, 0 ld hl, .Multipliers add hl, bc add hl, bc ld a, [hli] ld h, [hl] ld l, a ld a, BANK(GetMaxHP) rst FarCall call AnimateCurrentMove call BattleCommand_SwitchTurn callfar RestoreHP call BattleCommand_SwitchTurn call UpdateUserInParty ; 'regained health!' ld hl, RegainedHealthText jp StdBattleTextBox .Full: call AnimateFailedMove ; 'hp is full!' ld hl, HPIsFullText jp StdBattleTextBox .Multipliers: dw GetEighthMaxHP dw GetQuarterMaxHP dw GetHalfMaxHP dw GetMaxHP ; 37be8 INCLUDE "engine/battle/move_effects/hidden_power.asm" INCLUDE "engine/battle/move_effects/rain_dance.asm" INCLUDE "engine/battle/move_effects/sunny_day.asm" INCLUDE "engine/battle/move_effects/belly_drum.asm" INCLUDE "engine/battle/move_effects/psych_up.asm" INCLUDE "engine/battle/move_effects/mirror_coat.asm" BattleCommand_DoubleMinimizeDamage: ; 37ce6 ; doubleminimizedamage ld hl, wEnemyMinimized ld a, [hBattleTurn] and a jr z, .ok ld hl, wPlayerMinimized .ok ld a, [hl] and a ret z ld hl, wCurDamage + 1 sla [hl] dec hl rl [hl] ret nc ld a, $ff ld [hli], a ld [hl], a ret ; 37d02 BattleCommand_SkipSunCharge: ; 37d02 ; mimicsuncharge ld a, [wBattleWeather] cp WEATHER_SUN ret nz ld b, charge_command jp SkipToBattleCommand ; 37d0d INCLUDE "engine/battle/move_effects/future_sight.asm" INCLUDE "engine/battle/move_effects/thunder.asm" CheckHiddenOpponent: ; 37daa ; BUG: This routine should account for Lock-On and Mind Reader. ld a, BATTLE_VARS_SUBSTATUS3_OPP call GetBattleVar and 1 << SUBSTATUS_FLYING | 1 << SUBSTATUS_UNDERGROUND ret ; 37db2 GetUserItem: ; 37db2 ; Return the effect of the user's item in bc, and its id at hl. ld hl, wBattleMonItem ld a, [hBattleTurn] and a jr z, .go ld hl, wEnemyMonItem .go ld b, [hl] jp GetItemHeldEffect ; 37dc1 GetOpponentItem: ; 37dc1 ; Return the effect of the opponent's item in bc, and its id at hl. ld hl, wEnemyMonItem ld a, [hBattleTurn] and a jr z, .go ld hl, wBattleMonItem .go ld b, [hl] jp GetItemHeldEffect ; 37dd0 GetItemHeldEffect: ; 37dd0 ; Return the effect of item b in bc. ld a, b and a ret z push hl ld hl, ItemAttributes + ITEMATTR_EFFECT dec a ld c, a ld b, 0 ld a, ITEMATTR_STRUCT_LENGTH call AddNTimes ld a, BANK(ItemAttributes) call GetFarHalfword ld b, l ld c, h pop hl ret ; 37de9 AnimateCurrentMoveEitherSide: ; 37de9 push hl push de push bc ld a, [wKickCounter] push af call BattleCommand_LowerSub pop af ld [wKickCounter], a call PlayDamageAnim call BattleCommand_RaiseSub pop bc pop de pop hl ret ; 37e01 AnimateCurrentMove: ; 37e01 push hl push de push bc ld a, [wKickCounter] push af call BattleCommand_LowerSub pop af ld [wKickCounter], a call LoadMoveAnim call BattleCommand_RaiseSub pop bc pop de pop hl ret ; 37e19 PlayDamageAnim: ; 37e19 xor a ld [wFXAnimID + 1], a ld a, BATTLE_VARS_MOVE_ANIM call GetBattleVar and a ret z ld [wFXAnimID], a ld a, [hBattleTurn] and a ld a, BATTLEANIM_ENEMY_DAMAGE jr z, .player ld a, BATTLEANIM_PLAYER_DAMAGE .player ld [wNumHits], a jp PlayUserBattleAnim ; 37e36 LoadMoveAnim: ; 37e36 xor a ld [wNumHits], a ld [wFXAnimID + 1], a ld a, BATTLE_VARS_MOVE_ANIM call GetBattleVar and a ret z ; fallthrough ; 37e44 LoadAnim: ; 37e44 ld [wFXAnimID], a ; fallthrough ; 37e47 PlayUserBattleAnim: ; 37e47 push hl push de push bc callfar PlayBattleAnim pop bc pop de pop hl ret ; 37e54 PlayOpponentBattleAnim: ; 37e54 ld a, e ld [wFXAnimID], a ld a, d ld [wFXAnimID + 1], a xor a ld [wNumHits], a push hl push de push bc call BattleCommand_SwitchTurn callfar PlayBattleAnim call BattleCommand_SwitchTurn pop bc pop de pop hl ret ; 37e73 CallBattleCore: ; 37e73 ld a, BANK(BattleCore) rst FarCall ret ; 37e77 AnimateFailedMove: ; 37e77 call BattleCommand_LowerSub call BattleCommand_MoveDelay jp BattleCommand_RaiseSub ; 37e80 BattleCommand_MoveDelay: ; 37e80 ; movedelay ; Wait 40 frames. ld c, 40 jp DelayFrames ; 37e85 BattleCommand_ClearText: ; 37e85 ; cleartext ; Used in multi-hit moves. ld hl, .text jp BattleTextBox .text db "@" ; 37e8c SkipToBattleCommand: ; 37e8c ; Skip over commands until reaching command b. ld a, [wBattleScriptBufferAddress + 1] ld h, a ld a, [wBattleScriptBufferAddress] ld l, a .loop ld a, [hli] cp b jr nz, .loop ld a, h ld [wBattleScriptBufferAddress + 1], a ld a, l ld [wBattleScriptBufferAddress], a ret ; 37ea1 GetMoveAttr: ; 37ea1 ; Assuming hl = Moves + x, return attribute x of move a. push bc ld bc, MOVE_LENGTH call AddNTimes call GetMoveByte pop bc ret ; 37ead GetMoveData: ; 37ead ; Copy move struct a to de. ld hl, Moves ld bc, MOVE_LENGTH call AddNTimes ld a, Bank(Moves) jp FarCopyBytes ; 37ebb GetMoveByte: ; 37ebb ld a, BANK(Moves) jp GetFarByte ; 37ec0 DisappearUser: ; 37ec0 farcall _DisappearUser ret ; 37ec7 AppearUserLowerSub: ; 37ec7 farcall _AppearUserLowerSub ret ; 37ece AppearUserRaiseSub: ; 37ece farcall _AppearUserRaiseSub ret ; 37ed5 _CheckBattleScene: ; 37ed5 ; Checks the options. Returns carry if battle animations are disabled. push hl push de push bc farcall CheckBattleScene pop bc pop de pop hl ret ; 37ee2