DoPlayerTurn: ; 34000 call SetPlayerTurn ld a, [wPlayerAction] 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, BattleScriptBuffer .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, BattleScriptBuffer ld a, l ld [BattleScriptBufferAddress], a ld a, h ld [BattleScriptBufferAddress + 1], a .ReadMoveEffectCommand: ; ld a, [BattleScriptBufferAddress++] ld a, [BattleScriptBufferAddress] ld l, a ld a, [BattleScriptBufferAddress + 1] ld h, a ld a, [hli] push af ld a, l ld [BattleScriptBufferAddress], a ld a, h ld [BattleScriptBufferAddress + 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 [AttackMissed], a ld [EffectFailed], a ld [wKickCounter], a ld [AlreadyDisobeyed], a ld [AlreadyFailed], a ld [wSomeoneIsRampaging], a ld a, EFFECTIVE ld [TypeModifier], a ld a, [hBattleTurn] and a jp nz, CheckEnemyTurn CheckPlayerTurn: ld hl, PlayerSubStatus4 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, BattleMonStatus ld a, [hl] and SLP jr z, .not_asleep dec a ld [BattleMonStatus], 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, PlayerSubStatus1 res SUBSTATUS_NIGHTMARE, [hl] jr .not_asleep .fast_asleep ld hl, FastAsleepText call StdBattleTextBox ; Snore and Sleep Talk bypass sleep. ld a, [CurPlayerMove] cp SNORE jr z, .not_asleep cp SLEEP_TALK jr z, .not_asleep call CantMove jp EndTurn .not_asleep ld hl, BattleMonStatus bit FRZ, [hl] jr z, .not_frozen ; Flame Wheel and Sacred Fire thaw the user. ld a, [CurPlayerMove] 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, PlayerSubStatus3 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, PlayerDisableCount ld a, [hl] and a jr z, .not_disabled dec a ld [hl], a and $f jr nz, .not_disabled ld [hl], a ld [DisabledMove], a ld hl, DisabledNoMoreText call StdBattleTextBox .not_disabled ld a, [PlayerSubStatus3] add a jr nc, .not_confused ld hl, PlayerConfuseCount dec [hl] jr nz, .confused ld hl, PlayerSubStatus3 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, PlayerSubStatus3 ld a, [hl] and 1 << SUBSTATUS_CONFUSED ld [hl], a call HitConfusion call CantMove jp EndTurn .not_confused ld a, [PlayerSubStatus1] 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, [DisabledMove] and a jr z, .no_disabled_move ; Are we using the disabled move? ld hl, CurPlayerMove cp [hl] jr nz, .no_disabled_move call MoveDisabled call CantMove jp EndTurn .no_disabled_move ld hl, BattleMonStatus 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< 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, [AlreadyFailed] 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, BattleMonMoves ld a, [hBattleTurn] and a jr z, .ok ld de, EnemyMonMoves .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 [AlreadyDisobeyed], 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, EnemyScreens ld a, [hBattleTurn] and a jr z, .got_turn ld hl, PlayerScreens .got_turn bit SCREENS_SAFEGUARD, [hl] pop hl ret ; 37972 BattleCommand_CheckSafeguard: ; 37972 ; checksafeguard ld hl, EnemyScreens ld a, [hBattleTurn] and a jr z, .got_turn ld hl, PlayerScreens .got_turn bit SCREENS_SAFEGUARD, [hl] ret z ld a, 1 ld [AttackMissed], 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, BattleMonMaxHP ld de, BattleMonHP ld a, [hBattleTurn] and a jr z, .start ld hl, EnemyMonMaxHP ld de, EnemyMonHP .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, [TimeOfDay] cp b jr z, .Weather dec c ; double .Weather: ld a, [Weather] 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, CurDamage + 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, [Weather] 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, BattleMonItem ld a, [hBattleTurn] and a jr z, .go ld hl, EnemyMonItem .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, EnemyMonItem ld a, [hBattleTurn] and a jr z, .go ld hl, BattleMonItem .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 [FXAnimID + 1], a ld a, BATTLE_VARS_MOVE_ANIM call GetBattleVar and a ret z ld [FXAnimID], 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 [FXAnimID + 1], a ld a, BATTLE_VARS_MOVE_ANIM call GetBattleVar and a ret z ; fallthrough ; 37e44 LoadAnim: ; 37e44 ld [FXAnimID], 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 [FXAnimID], a ld a, d ld [FXAnimID + 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, [BattleScriptBufferAddress + 1] ld h, a ld a, [BattleScriptBufferAddress] ld l, a .loop ld a, [hli] cp b jr nz, .loop ld a, h ld [BattleScriptBufferAddress + 1], a ld a, l ld [BattleScriptBufferAddress], 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