From e74dce24b4bbb0d0d23a1724932b289050b66d4a Mon Sep 17 00:00:00 2001 From: xCrystal Date: Wed, 1 Apr 2015 11:23:27 +0200 Subject: Rename battle files and split move effects Part 1 1.asm, 4.asm, and 4_2.asm --- main.asm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'main.asm') diff --git a/main.asm b/main.asm index cb77e5a3..958c774f 100755 --- a/main.asm +++ b/main.asm @@ -1907,7 +1907,7 @@ FieldMoveDisplayData: ; 7823 (1:7823) db $ff ; list terminator -INCLUDE "engine/battle/1.asm" +INCLUDE "engine/battle/moveEffects/drain_hp_effect.asm" INCLUDE "engine/menu/players_pc.asm" @@ -4755,7 +4755,7 @@ PlayerCharacterTitleGraphics: INCBIN "gfx/player_title.2bpp" SECTION "Battle (bank 4)", ROMX, BANK[$4] -INCLUDE "engine/battle/4.asm" +INCLUDE "engine/overworld/is_player_just_outside_map.asm" INCLUDE "engine/menu/status_screen.asm" INCLUDE "engine/menu/party_menu.asm" @@ -4766,7 +4766,12 @@ ShrinkPic2:: INCBIN "pic/trainer/shrink2.pic" INCLUDE "engine/turn_sprite.asm" INCLUDE "engine/menu/start_sub_menus.asm" INCLUDE "engine/items/tms.asm" -INCLUDE "engine/battle/4_2.asm" +INCLUDE "engine/battle/end_of_battle.asm" +INCLUDE "engine/battle/wild_encounters.asm" +INCLUDE "engine/battle/moveEffects/recoil_effect.asm" +INCLUDE "engine/battle/moveEffects/conversion_effect.asm" +INCLUDE "engine/battle/moveEffects/haze_effect.asm" +INCLUDE "engine/battle/get_trainer_name.asm" INCLUDE "engine/random.asm" -- cgit v1.3.1-sl0p From 46c2a38c7c55ff01e8787dfd624cb1c771248b6c Mon Sep 17 00:00:00 2001 From: xCrystal Date: Wed, 1 Apr 2015 11:41:20 +0200 Subject: Rename battle files and split move effects Part 2 5.asm, 9.asm, and a.asm --- engine/battle/5.asm | 77 --------- engine/battle/9.asm | 190 ---------------------- engine/battle/a.asm | 39 ----- engine/battle/core.asm | 4 +- engine/battle/moveEffects/focus_energy_effect.asm | 24 +++ engine/battle/moveEffects/leech_seed_effect.asm | 39 +++++ engine/battle/moveEffects/substitute_effect.asm | 77 +++++++++ engine/battle/print_type.asm | 52 ++++++ engine/battle/save_trainer_name.asm | 112 +++++++++++++ main.asm | 8 +- 10 files changed, 311 insertions(+), 311 deletions(-) delete mode 100755 engine/battle/5.asm delete mode 100755 engine/battle/9.asm delete mode 100755 engine/battle/a.asm create mode 100644 engine/battle/moveEffects/focus_energy_effect.asm create mode 100644 engine/battle/moveEffects/leech_seed_effect.asm create mode 100644 engine/battle/moveEffects/substitute_effect.asm create mode 100644 engine/battle/print_type.asm create mode 100644 engine/battle/save_trainer_name.asm (limited to 'main.asm') diff --git a/engine/battle/5.asm b/engine/battle/5.asm deleted file mode 100755 index ef3e1362..00000000 --- a/engine/battle/5.asm +++ /dev/null @@ -1,77 +0,0 @@ -SubstituteEffectHandler: ; 17dad (5:7dad) - ld c, 50 - call DelayFrames - ld hl, wBattleMonMaxHP - ld de, wPlayerSubstituteHP - ld bc, W_PLAYERBATTSTATUS2 - ld a, [H_WHOSETURN] - and a - jr z, .notEnemy - ld hl, wEnemyMonMaxHP - ld de, wEnemySubstituteHP - ld bc, W_ENEMYBATTSTATUS2 -.notEnemy - ld a, [bc] ;load flags - bit HasSubstituteUp, a ;user already has substitute? - jr nz, .alreadyHasSubstitute ;skip this code if so - ;user doesn't have a substitute [yet] - push bc - ld a, [hli] ;load max hp - ld b, [hl] - srl a ;max hp / 4, [quarter health to remove from user] - rr b - srl a - rr b - push de - ld de, wBattleMonHP - wBattleMonMaxHP - add hl, de ; point hl to current HP - pop de - ld a, b - ld [de], a ;save copy of HP to subtract in ccd7/ccd8 [how much HP substitute has] - ld a, [hld] ;load current hp - sub b ;subtract [max hp / 4] - ld d, a ;save low byte result in D - ld a, [hl] - sbc a, 0 ;borrow from high byte if needed - pop bc - jr c, .notEnoughHP ;underflow means user would be left with negative health - ;bug: note since it only brances on carry, it will possibly leave user with 0HP -.userHasZeroOrMoreHP - ldi [hl], a ;store high byte HP - ld [hl], d ;store low byte HP - ld h, b - ld l, c - set HasSubstituteUp, [hl] ;set bit 4 of flags, user now has substitute - ld a, [W_OPTIONS] ;load options - bit 7, a ;battle animation is enabled? - ld hl, PlayCurrentMoveAnimation ;animation enabled: 0F:7BA8 - ld b, BANK(PlayCurrentMoveAnimation) - jr z, .animationEnabled - ld hl, AnimationSubstitute ;animation disabled: 1E:56E0 - ld b, BANK(AnimationSubstitute) -.animationEnabled - call Bankswitch ;jump to routine depending on animation setting - ld hl, SubstituteText - call PrintText - ld hl, DrawHUDsAndHPBars - ld b, BANK(DrawHUDsAndHPBars) - jp Bankswitch -.alreadyHasSubstitute - ld hl, HasSubstituteText - jr .printText -.notEnoughHP - ld hl, TooWeakSubstituteText -.printText - jp PrintText - -SubstituteText: ; 17e1d (5:7e1d) - TX_FAR _SubstituteText - db "@" - -HasSubstituteText: ; 17e22 (5:7e22) - TX_FAR _HasSubstituteText - db "@" - -TooWeakSubstituteText: ; 17e27 (5:7e27) - TX_FAR _TooWeakSubstituteText - db "@" diff --git a/engine/battle/9.asm b/engine/battle/9.asm deleted file mode 100755 index e7265f41..00000000 --- a/engine/battle/9.asm +++ /dev/null @@ -1,190 +0,0 @@ -; [wd0b5] = pokemon ID -; hl = dest addr -PrintMonType: ; 27d6b (9:7d6b) - call GetPredefRegisters - push hl - call GetMonHeader - pop hl - push hl - ld a, [W_MONHTYPE1] - call PrintType - ld a, [W_MONHTYPE1] - ld b, a - ld a, [W_MONHTYPE2] - cp b - pop hl - jr z, EraseType2Text - ld bc, SCREEN_WIDTH * 2 - add hl, bc - -; a = type -; hl = dest addr -PrintType: ; 27d89 (9:7d89) - push hl - jr PrintType_ - -; erase "TYPE2/" if the mon only has 1 type -EraseType2Text: ; 27d8c (9:7d8c) - ld a, " " - ld bc, $13 - add hl, bc - ld bc, $6 - jp FillMemory - -PrintMoveType: ; 27d98 (9:7d98) - call GetPredefRegisters - push hl - ld a, [W_PLAYERMOVETYPE] -; fall through - -PrintType_: ; 27d9f (9:7d9f) - add a - ld hl, TypeNames - ld e, a - ld d, $0 - add hl, de - ld a, [hli] - ld e, a - ld d, [hl] - pop hl - jp PlaceString - -INCLUDE "text/type_names.asm" - -SaveTrainerName: ; 27e4a (9:7e4a) - ld hl,TrainerNamePointers - ld a,[W_TRAINERCLASS] - dec a - ld c,a - ld b,0 - add hl,bc - add hl,bc - ld a,[hli] - ld h,[hl] - ld l,a - ld de,wcd6d -.CopyCharacter - ld a,[hli] - ld [de],a - inc de - cp "@" - jr nz,.CopyCharacter - ret - -TrainerNamePointers: ; 27e64 (9:7e64) -; what is the point of these? - dw YoungsterName - dw BugCatcherName - dw LassName - dw W_TRAINERNAME - dw JrTrainerMName - dw JrTrainerFName - dw PokemaniacName - dw SuperNerdName - dw W_TRAINERNAME - dw W_TRAINERNAME - dw BurglarName - dw EngineerName - dw JugglerXName - dw W_TRAINERNAME - dw SwimmerName - dw W_TRAINERNAME - dw W_TRAINERNAME - dw BeautyName - dw W_TRAINERNAME - dw RockerName - dw JugglerName - dw W_TRAINERNAME - dw W_TRAINERNAME - dw BlackbeltName - dw W_TRAINERNAME - dw ProfOakName - dw ChiefName - dw ScientistName - dw W_TRAINERNAME - dw RocketName - dw CooltrainerMName - dw CooltrainerFName - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - -YoungsterName: ; 27ec2 (9:7ec2) - db "YOUNGSTER@" -BugCatcherName: ; 27ecc (9:7ecc) - db "BUG CATCHER@" -LassName: ; 27ed8 (9:7ed8) - db "LASS@" -JrTrainerMName: ; 27edd (9:7edd) - db "JR.TRAINER♂@" -JrTrainerFName: ; 27ee9 (9:7ee9) - db "JR.TRAINER♀@" -PokemaniacName: ; 27ef5 (9:7ef5) - db "POKéMANIAC@" -SuperNerdName: ; 27f00 (9:7f00) - db "SUPER NERD@" -BurglarName: ; 27f0b (9:7f0b) - db "BURGLAR@" -EngineerName: ; 27f13 (9:7f13) - db "ENGINEER@" -JugglerXName: ; 27f1c (9:7f1c) - db "JUGGLER@" -SwimmerName: ; 27f24 (9:7f24) - db "SWIMMER@" -BeautyName: ; 27f2c (9:7f2c) - db "BEAUTY@" -RockerName: ; 27f33 (9:7f33) - db "ROCKER@" -JugglerName: ; 27f3a (9:7f3a) - db "JUGGLER@" -BlackbeltName: ; 27f42 (9:7f42) - db "BLACKBELT@" -ProfOakName: ; 27f4c (9:7f4c) - db "PROF.OAK@" -ChiefName: ; 27f55 (9:7f55) - db "CHIEF@" -ScientistName: ; 27f5b (9:7f5b) - db "SCIENTIST@" -RocketName: ; 27f65 (9:7f65) - db "ROCKET@" -CooltrainerMName: ; 27f6c (9:7f6c) - db "COOLTRAINER♂@" -CooltrainerFName: ; 27f79 (9:7f79) - db "COOLTRAINER♀@" - -FocusEnergyEffect_: ; 27f86 (9:7f86) - ld hl, W_PLAYERBATTSTATUS2 - ld a, [H_WHOSETURN] - and a - jr z, .notEnemy - ld hl, W_ENEMYBATTSTATUS2 -.notEnemy - bit GettingPumped, [hl] ; is mon already using focus energy? - jr nz, .alreadyUsing - set GettingPumped, [hl] ; mon is now using focus energy - callab PlayCurrentMoveAnimation - ld hl, GettingPumpedText - jp PrintText -.alreadyUsing - ld c, $32 - call DelayFrames - ld hl, PrintButItFailedText_ - ld b, BANK(PrintButItFailedText_) - jp Bankswitch - -GettingPumpedText: ; 27fb3 (9:7fb3) - db $0a - TX_FAR _GettingPumpedText - db "@" diff --git a/engine/battle/a.asm b/engine/battle/a.asm deleted file mode 100755 index a257d143..00000000 --- a/engine/battle/a.asm +++ /dev/null @@ -1,39 +0,0 @@ -LeechSeedEffect_: ; 2bea9 (a:7ea9) - callab MoveHitTest - ld a, [W_MOVEMISSED] ; W_MOVEMISSED - and a - jr nz, .asm_2bee7 - ld hl, W_ENEMYBATTSTATUS2 ; W_ENEMYBATTSTATUS2 - ld de, wEnemyMonType1 ; wcfea (aliases: wEnemyMonType) - ld a, [H_WHOSETURN] ; $fff3 - and a - jr z, .asm_2bec8 - ld hl, W_PLAYERBATTSTATUS2 ; W_PLAYERBATTSTATUS2 - ld de, wBattleMonType1 ; wd019 (aliases: wBattleMonType) -.asm_2bec8 - ld a, [de] - cp GRASS - jr z, .asm_2bee7 - inc de - ld a, [de] - cp GRASS - jr z, .asm_2bee7 - bit Seeded, [hl] - jr nz, .asm_2bee7 - set Seeded, [hl] - callab PlayCurrentMoveAnimation - ld hl, WasSeededText ; $7ef2 - jp PrintText -.asm_2bee7 - ld c, $32 - call DelayFrames - ld hl, EvadedAttackText ; $7ef7 - jp PrintText - -WasSeededText: ; 2bef2 (a:7ef2) - TX_FAR _WasSeededText - db "@" - -EvadedAttackText: ; 2bef7 (a:7ef7) - TX_FAR _EvadedAttackText - db "@" diff --git a/engine/battle/core.asm b/engine/battle/core.asm index bad8f831..48bed512 100755 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -8369,8 +8369,8 @@ ParalyzeEffect: ; 3f9b1 (f:79b1) jp Bankswitch SubstituteEffect: ; 3f9b9 (f:79b9) - ld hl, SubstituteEffectHandler - ld b, BANK(SubstituteEffectHandler) + ld hl, SubstituteEffect_ + ld b, BANK(SubstituteEffect_) jp Bankswitch HyperBeamEffect: ; 3f9c1 (f:79c1) diff --git a/engine/battle/moveEffects/focus_energy_effect.asm b/engine/battle/moveEffects/focus_energy_effect.asm new file mode 100644 index 00000000..f01e61cc --- /dev/null +++ b/engine/battle/moveEffects/focus_energy_effect.asm @@ -0,0 +1,24 @@ +FocusEnergyEffect_: ; 27f86 (9:7f86) + ld hl, W_PLAYERBATTSTATUS2 + ld a, [H_WHOSETURN] + and a + jr z, .notEnemy + ld hl, W_ENEMYBATTSTATUS2 +.notEnemy + bit GettingPumped, [hl] ; is mon already using focus energy? + jr nz, .alreadyUsing + set GettingPumped, [hl] ; mon is now using focus energy + callab PlayCurrentMoveAnimation + ld hl, GettingPumpedText + jp PrintText +.alreadyUsing + ld c, $32 + call DelayFrames + ld hl, PrintButItFailedText_ + ld b, BANK(PrintButItFailedText_) + jp Bankswitch + +GettingPumpedText: ; 27fb3 (9:7fb3) + db $0a + TX_FAR _GettingPumpedText + db "@" diff --git a/engine/battle/moveEffects/leech_seed_effect.asm b/engine/battle/moveEffects/leech_seed_effect.asm new file mode 100644 index 00000000..a257d143 --- /dev/null +++ b/engine/battle/moveEffects/leech_seed_effect.asm @@ -0,0 +1,39 @@ +LeechSeedEffect_: ; 2bea9 (a:7ea9) + callab MoveHitTest + ld a, [W_MOVEMISSED] ; W_MOVEMISSED + and a + jr nz, .asm_2bee7 + ld hl, W_ENEMYBATTSTATUS2 ; W_ENEMYBATTSTATUS2 + ld de, wEnemyMonType1 ; wcfea (aliases: wEnemyMonType) + ld a, [H_WHOSETURN] ; $fff3 + and a + jr z, .asm_2bec8 + ld hl, W_PLAYERBATTSTATUS2 ; W_PLAYERBATTSTATUS2 + ld de, wBattleMonType1 ; wd019 (aliases: wBattleMonType) +.asm_2bec8 + ld a, [de] + cp GRASS + jr z, .asm_2bee7 + inc de + ld a, [de] + cp GRASS + jr z, .asm_2bee7 + bit Seeded, [hl] + jr nz, .asm_2bee7 + set Seeded, [hl] + callab PlayCurrentMoveAnimation + ld hl, WasSeededText ; $7ef2 + jp PrintText +.asm_2bee7 + ld c, $32 + call DelayFrames + ld hl, EvadedAttackText ; $7ef7 + jp PrintText + +WasSeededText: ; 2bef2 (a:7ef2) + TX_FAR _WasSeededText + db "@" + +EvadedAttackText: ; 2bef7 (a:7ef7) + TX_FAR _EvadedAttackText + db "@" diff --git a/engine/battle/moveEffects/substitute_effect.asm b/engine/battle/moveEffects/substitute_effect.asm new file mode 100644 index 00000000..e88def4a --- /dev/null +++ b/engine/battle/moveEffects/substitute_effect.asm @@ -0,0 +1,77 @@ +SubstituteEffect_: ; 17dad (5:7dad) + ld c, 50 + call DelayFrames + ld hl, wBattleMonMaxHP + ld de, wPlayerSubstituteHP + ld bc, W_PLAYERBATTSTATUS2 + ld a, [H_WHOSETURN] + and a + jr z, .notEnemy + ld hl, wEnemyMonMaxHP + ld de, wEnemySubstituteHP + ld bc, W_ENEMYBATTSTATUS2 +.notEnemy + ld a, [bc] ;load flags + bit HasSubstituteUp, a ;user already has substitute? + jr nz, .alreadyHasSubstitute ;skip this code if so + ;user doesn't have a substitute [yet] + push bc + ld a, [hli] ;load max hp + ld b, [hl] + srl a ;max hp / 4, [quarter health to remove from user] + rr b + srl a + rr b + push de + ld de, wBattleMonHP - wBattleMonMaxHP + add hl, de ; point hl to current HP + pop de + ld a, b + ld [de], a ;save copy of HP to subtract in ccd7/ccd8 [how much HP substitute has] + ld a, [hld] ;load current hp + sub b ;subtract [max hp / 4] + ld d, a ;save low byte result in D + ld a, [hl] + sbc a, 0 ;borrow from high byte if needed + pop bc + jr c, .notEnoughHP ;underflow means user would be left with negative health + ;bug: note since it only brances on carry, it will possibly leave user with 0HP +.userHasZeroOrMoreHP + ldi [hl], a ;store high byte HP + ld [hl], d ;store low byte HP + ld h, b + ld l, c + set HasSubstituteUp, [hl] ;set bit 4 of flags, user now has substitute + ld a, [W_OPTIONS] ;load options + bit 7, a ;battle animation is enabled? + ld hl, PlayCurrentMoveAnimation ;animation enabled: 0F:7BA8 + ld b, BANK(PlayCurrentMoveAnimation) + jr z, .animationEnabled + ld hl, AnimationSubstitute ;animation disabled: 1E:56E0 + ld b, BANK(AnimationSubstitute) +.animationEnabled + call Bankswitch ;jump to routine depending on animation setting + ld hl, SubstituteText + call PrintText + ld hl, DrawHUDsAndHPBars + ld b, BANK(DrawHUDsAndHPBars) + jp Bankswitch +.alreadyHasSubstitute + ld hl, HasSubstituteText + jr .printText +.notEnoughHP + ld hl, TooWeakSubstituteText +.printText + jp PrintText + +SubstituteText: ; 17e1d (5:7e1d) + TX_FAR _SubstituteText + db "@" + +HasSubstituteText: ; 17e22 (5:7e22) + TX_FAR _HasSubstituteText + db "@" + +TooWeakSubstituteText: ; 17e27 (5:7e27) + TX_FAR _TooWeakSubstituteText + db "@" diff --git a/engine/battle/print_type.asm b/engine/battle/print_type.asm new file mode 100644 index 00000000..38c701a8 --- /dev/null +++ b/engine/battle/print_type.asm @@ -0,0 +1,52 @@ +; [wd0b5] = pokemon ID +; hl = dest addr +PrintMonType: ; 27d6b (9:7d6b) + call GetPredefRegisters + push hl + call GetMonHeader + pop hl + push hl + ld a, [W_MONHTYPE1] + call PrintType + ld a, [W_MONHTYPE1] + ld b, a + ld a, [W_MONHTYPE2] + cp b + pop hl + jr z, EraseType2Text + ld bc, SCREEN_WIDTH * 2 + add hl, bc + +; a = type +; hl = dest addr +PrintType: ; 27d89 (9:7d89) + push hl + jr PrintType_ + +; erase "TYPE2/" if the mon only has 1 type +EraseType2Text: ; 27d8c (9:7d8c) + ld a, " " + ld bc, $13 + add hl, bc + ld bc, $6 + jp FillMemory + +PrintMoveType: ; 27d98 (9:7d98) + call GetPredefRegisters + push hl + ld a, [W_PLAYERMOVETYPE] +; fall through + +PrintType_: ; 27d9f (9:7d9f) + add a + ld hl, TypeNames + ld e, a + ld d, $0 + add hl, de + ld a, [hli] + ld e, a + ld d, [hl] + pop hl + jp PlaceString + +INCLUDE "text/type_names.asm" diff --git a/engine/battle/save_trainer_name.asm b/engine/battle/save_trainer_name.asm new file mode 100644 index 00000000..84ef1f69 --- /dev/null +++ b/engine/battle/save_trainer_name.asm @@ -0,0 +1,112 @@ +SaveTrainerName: ; 27e4a (9:7e4a) + ld hl,TrainerNamePointers + ld a,[W_TRAINERCLASS] + dec a + ld c,a + ld b,0 + add hl,bc + add hl,bc + ld a,[hli] + ld h,[hl] + ld l,a + ld de,wcd6d +.CopyCharacter + ld a,[hli] + ld [de],a + inc de + cp "@" + jr nz,.CopyCharacter + ret + +TrainerNamePointers: ; 27e64 (9:7e64) +; what is the point of these? + dw YoungsterName + dw BugCatcherName + dw LassName + dw W_TRAINERNAME + dw JrTrainerMName + dw JrTrainerFName + dw PokemaniacName + dw SuperNerdName + dw W_TRAINERNAME + dw W_TRAINERNAME + dw BurglarName + dw EngineerName + dw JugglerXName + dw W_TRAINERNAME + dw SwimmerName + dw W_TRAINERNAME + dw W_TRAINERNAME + dw BeautyName + dw W_TRAINERNAME + dw RockerName + dw JugglerName + dw W_TRAINERNAME + dw W_TRAINERNAME + dw BlackbeltName + dw W_TRAINERNAME + dw ProfOakName + dw ChiefName + dw ScientistName + dw W_TRAINERNAME + dw RocketName + dw CooltrainerMName + dw CooltrainerFName + dw W_TRAINERNAME + dw W_TRAINERNAME + dw W_TRAINERNAME + dw W_TRAINERNAME + dw W_TRAINERNAME + dw W_TRAINERNAME + dw W_TRAINERNAME + dw W_TRAINERNAME + dw W_TRAINERNAME + dw W_TRAINERNAME + dw W_TRAINERNAME + dw W_TRAINERNAME + dw W_TRAINERNAME + dw W_TRAINERNAME + dw W_TRAINERNAME + +YoungsterName: ; 27ec2 (9:7ec2) + db "YOUNGSTER@" +BugCatcherName: ; 27ecc (9:7ecc) + db "BUG CATCHER@" +LassName: ; 27ed8 (9:7ed8) + db "LASS@" +JrTrainerMName: ; 27edd (9:7edd) + db "JR.TRAINER♂@" +JrTrainerFName: ; 27ee9 (9:7ee9) + db "JR.TRAINER♀@" +PokemaniacName: ; 27ef5 (9:7ef5) + db "POKéMANIAC@" +SuperNerdName: ; 27f00 (9:7f00) + db "SUPER NERD@" +BurglarName: ; 27f0b (9:7f0b) + db "BURGLAR@" +EngineerName: ; 27f13 (9:7f13) + db "ENGINEER@" +JugglerXName: ; 27f1c (9:7f1c) + db "JUGGLER@" +SwimmerName: ; 27f24 (9:7f24) + db "SWIMMER@" +BeautyName: ; 27f2c (9:7f2c) + db "BEAUTY@" +RockerName: ; 27f33 (9:7f33) + db "ROCKER@" +JugglerName: ; 27f3a (9:7f3a) + db "JUGGLER@" +BlackbeltName: ; 27f42 (9:7f42) + db "BLACKBELT@" +ProfOakName: ; 27f4c (9:7f4c) + db "PROF.OAK@" +ChiefName: ; 27f55 (9:7f55) + db "CHIEF@" +ScientistName: ; 27f5b (9:7f5b) + db "SCIENTIST@" +RocketName: ; 27f65 (9:7f65) + db "ROCKET@" +CooltrainerMName: ; 27f6c (9:7f6c) + db "COOLTRAINER♂@" +CooltrainerFName: ; 27f79 (9:7f79) + db "COOLTRAINER♀@" diff --git a/main.asm b/main.asm index 958c774f..1c7f15f9 100755 --- a/main.asm +++ b/main.asm @@ -4825,7 +4825,7 @@ INCLUDE "engine/load_pokedex_tiles.asm" INCLUDE "engine/overworld/map_sprites.asm" INCLUDE "engine/overworld/emotion_bubbles.asm" INCLUDE "engine/evolve_trade.asm" -INCLUDE "engine/battle/5.asm" +INCLUDE "engine/battle/moveEffects/substitute_effect.asm" INCLUDE "engine/menu/pc.asm" @@ -5154,7 +5154,9 @@ TangelaPicBack:: INCBIN "pic/monback/tangelab.pic" SECTION "Battle (bank 9)", ROMX, BANK[$9] -INCLUDE "engine/battle/9.asm" +INCLUDE "engine/battle/print_type.asm" +INCLUDE "engine/battle/save_trainer_name.asm" +INCLUDE "engine/battle/moveEffects/focus_energy_effect.asm" SECTION "Pics 2", ROMX, BANK[PICS_2] @@ -5226,7 +5228,7 @@ MoltresPicBack:: INCBIN "pic/monback/moltresb.pic" SECTION "Battle (bank A)", ROMX, BANK[$A] -INCLUDE "engine/battle/a.asm" +INCLUDE "engine/battle/moveEffects/leech_seed_effect.asm" SECTION "Pics 3", ROMX, BANK[PICS_3] -- cgit v1.3.1-sl0p From 77d0e5ff84cc61ae625da19f184094241eddd4dc Mon Sep 17 00:00:00 2001 From: xCrystal Date: Wed, 1 Apr 2015 16:16:43 +0200 Subject: Rename battle files and split move effects Part 3 b.asm, b_2.asm, c.asm, and d.asm --- engine/battle/b.asm | 18 ---- engine/battle/b_2.asm | 129 ------------------------ engine/battle/c.asm | 58 ----------- engine/battle/d.asm | 23 ----- engine/battle/display_effectiveness.asm | 18 ++++ engine/battle/link_battle_versus_text.asm | 23 +++++ engine/battle/moveEffects/mist_effect.asm | 21 ++++ engine/battle/moveEffects/one_hit_ko_effect.asm | 36 +++++++ engine/battle/moveEffects/pay_day_effect.asm | 43 ++++++++ engine/battle/scale_sprites.asm | 85 ++++++++++++++++ main.asm | 10 +- 11 files changed, 232 insertions(+), 232 deletions(-) delete mode 100755 engine/battle/b.asm delete mode 100755 engine/battle/b_2.asm delete mode 100755 engine/battle/c.asm delete mode 100755 engine/battle/d.asm create mode 100644 engine/battle/display_effectiveness.asm create mode 100644 engine/battle/link_battle_versus_text.asm create mode 100644 engine/battle/moveEffects/mist_effect.asm create mode 100644 engine/battle/moveEffects/one_hit_ko_effect.asm create mode 100644 engine/battle/moveEffects/pay_day_effect.asm create mode 100644 engine/battle/scale_sprites.asm (limited to 'main.asm') diff --git a/engine/battle/b.asm b/engine/battle/b.asm deleted file mode 100755 index 17f0bd5b..00000000 --- a/engine/battle/b.asm +++ /dev/null @@ -1,18 +0,0 @@ -DisplayEffectiveness: ; 2fb7b (b:7b7b) - ld a, [wDamageMultipliers] - and a, $7F - cp a, $0A - ret z - ld hl, SuperEffectiveText - jr nc, .done - ld hl, NotVeryEffectiveText -.done - jp PrintText - -SuperEffectiveText: ; 2fb8e (b:7b8e) - TX_FAR _SuperEffectiveText - db "@" - -NotVeryEffectiveText: ; 2fb93 (b:7b93) - TX_FAR _NotVeryEffectiveText - db "@" diff --git a/engine/battle/b_2.asm b/engine/battle/b_2.asm deleted file mode 100755 index 4a49bb10..00000000 --- a/engine/battle/b_2.asm +++ /dev/null @@ -1,129 +0,0 @@ -; scales both uncompressed sprite chunks by two in every dimension (creating 2x2 output pixels per input pixel) -; assumes that input sprite chunks are 4x4 tiles, and the rightmost and bottommost 4 pixels will be ignored -; resulting in a 7*7 tile output sprite chunk -ScaleSpriteByTwo: ; 2fe40 (b:7e40) - ld de, S_SPRITEBUFFER1 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped - ld hl, S_SPRITEBUFFER0 + SPRITEBUFFERSIZE - 1 ; end of destination buffer - call ScaleLastSpriteColumnByTwo ; last tile column is special case - call ScaleFirstThreeSpriteColumnsByTwo ; scale first 3 tile columns - ld de, S_SPRITEBUFFER2 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped - ld hl, S_SPRITEBUFFER1 + SPRITEBUFFERSIZE - 1 ; end of destination buffer - call ScaleLastSpriteColumnByTwo ; last tile column is special case - -ScaleFirstThreeSpriteColumnsByTwo: ; 2fe55 (b:7e55) - ld b, $3 ; 3 tile columns -.columnLoop - ld c, 4*8 - 4 ; $1c, 4 tiles minus 4 unused rows -.columnInnerLoop - push bc - ld a, [de] - ld bc, -(7*8)+1 ; $ffc9, scale lower nybble and seek to previous output column - call ScalePixelsByTwo - ld a, [de] - dec de - swap a - ld bc, 7*8+1-2 ; $37, scale upper nybble and seek back to current output column and to the next 2 rows - call ScalePixelsByTwo - pop bc - dec c - jr nz, .columnInnerLoop - dec de - dec de - dec de - dec de - ld a, b - ld bc, -7*8 ; $ffc8, skip one output column (which has already been written along with the current one) - add hl, bc - ld b, a - dec b - jr nz, .columnLoop - ret - -ScaleLastSpriteColumnByTwo: ; 2fe7d (b:7e7d) - ld a, 4*8 - 4 ; $1c, 4 tiles minus 4 unused rows - ld [H_SPRITEINTERLACECOUNTER], a ; $ff8b - ld bc, -1 ; $ffff -.columnInnerLoop - ld a, [de] - dec de - swap a ; only high nybble contains information - call ScalePixelsByTwo - ld a, [H_SPRITEINTERLACECOUNTER] ; $ff8b - dec a - ld [H_SPRITEINTERLACECOUNTER], a ; $ff8b - jr nz, .columnInnerLoop - dec de ; skip last 4 rows of new column - dec de - dec de - dec de - ret - -; scales the given 4 bits in a (4x1 pixels) to 2 output bytes (8x2 pixels) -; hl: destination pointer -; bc: destination pointer offset (added after the two bytes have been written) -ScalePixelsByTwo: ; 2fe97 (b:7e97) - push hl - and $f - ld hl, DuplicateBitsTable - add l - ld l, a - jr nc, .noCarry - inc h -.noCarry - ld a, [hl] - pop hl - ld [hld], a ; write output byte twice to make it 2 pixels high - ld [hl], a - add hl, bc ; add offset - ret - -; repeats each input bit twice -DuplicateBitsTable: ; 2fea8 (b:7ea8) - db $00, $03, $0c, $0f - db $30, $33, $3c, $3f - db $c0, $c3, $cc, $cf - db $f0, $f3, $fc, $ff - -PayDayEffect_ ; 2feb8 (b:7eb8) - xor a - ld hl, wcd6d - ld [hli], a - ld a, [H_WHOSETURN] - and a - ld a, [wBattleMonLevel] - jr z, .asm_2fec8 - ld a, [wEnemyMonLevel] -.asm_2fec8 - add a - ld [H_DIVIDEND + 3], a - xor a - ld [H_DIVIDEND], a - ld [H_DIVIDEND + 1], a - ld [H_DIVIDEND + 2], a - ld a, $64 - ld [H_DIVISOR], a - ld b, $4 - call Divide - ld a, [H_QUOTIENT + 3] - ld [hli], a - ld a, [H_REMAINDER] - ld [H_DIVIDEND + 3], a - ld a, $a - ld [H_DIVISOR], a - ld b, $4 - call Divide - ld a, [H_QUOTIENT + 3] - swap a - ld b, a - ld a, [H_REMAINDER] - add b - ld [hl], a - ld de, wTotalPayDayMoney + 2 - ld c, $3 - predef AddBCDPredef - ld hl, CoinsScatteredText - jp PrintText - -CoinsScatteredText: ; 2ff04 (b:7f04) - TX_FAR _CoinsScatteredText - db "@" diff --git a/engine/battle/c.asm b/engine/battle/c.asm deleted file mode 100755 index b7c20ef6..00000000 --- a/engine/battle/c.asm +++ /dev/null @@ -1,58 +0,0 @@ -MistEffect_: ; 33f2b (c:7f2b) - ld hl, W_PLAYERBATTSTATUS2 - ld a, [$fff3] - and a - jr z, .asm_33f36 - ld hl, W_ENEMYBATTSTATUS2 -.asm_33f36 - bit ProtectedByMist, [hl] ; is mon protected by mist? - jr nz, .asm_33f4a - set ProtectedByMist, [hl] ; mon is now protected by mist - callab PlayCurrentMoveAnimation - ld hl, ShroudedInMistText - jp PrintText -.asm_33f4a - ld hl, PrintButItFailedText_ - ld b, BANK(PrintButItFailedText_) - jp Bankswitch - -ShroudedInMistText: ; 33f52 (c:7f52) - TX_FAR _ShroudedInMistText - db "@" - -OneHitKOEffect_: ; 33f57 (c:7f57) - ld hl, W_DAMAGE - xor a - ld [hli], a - ld [hl], a ; set the damage output to zero - dec a - ld [wCriticalHitOrOHKO], a - ld hl, wBattleMonSpeed + 1 - ld de, wEnemyMonSpeed + 1 - ld a, [H_WHOSETURN] ; $fff3 - and a - jr z, .asm_33f72 - ld hl, wEnemyMonSpeed + 1 - ld de, wBattleMonSpeed + 1 -.asm_33f72 - ld a, [de] - dec de - ld b, a - ld a, [hld] - sub b - ld a, [de] - ld b, a - ld a, [hl] - sbc b - jr c, .asm_33f8a - ld hl, W_DAMAGE - ld a, $ff - ld [hli], a - ld [hl], a - ld a, $2 - ld [wCriticalHitOrOHKO], a - ret -.asm_33f8a - ld a, $1 - ld [W_MOVEMISSED], a - ret diff --git a/engine/battle/d.asm b/engine/battle/d.asm deleted file mode 100755 index 7320da29..00000000 --- a/engine/battle/d.asm +++ /dev/null @@ -1,23 +0,0 @@ -; display "[player] VS [enemy]" text box with pokeballs representing their parties next to the names -DisplayLinkBattleVersusTextBox: ; 372d6 (d:72d6) - call LoadTextBoxTilePatterns - hlCoord 3, 4 - ld b, $7 - ld c, $c - call TextBoxBorder - hlCoord 4, 5 - ld de, wPlayerName - call PlaceString - hlCoord 4, 10 - ld de, wLinkEnemyTrainerName - call PlaceString -; place bold "VS" tiles between the names - hlCoord 9, 8 - ld a, $69 - ld [hli], a - ld [hl], $6a - xor a - ld [wUpdateSpritesEnabled], a - callab SetupPlayerAndEnemyPokeballs - ld c, 150 - jp DelayFrames diff --git a/engine/battle/display_effectiveness.asm b/engine/battle/display_effectiveness.asm new file mode 100644 index 00000000..17f0bd5b --- /dev/null +++ b/engine/battle/display_effectiveness.asm @@ -0,0 +1,18 @@ +DisplayEffectiveness: ; 2fb7b (b:7b7b) + ld a, [wDamageMultipliers] + and a, $7F + cp a, $0A + ret z + ld hl, SuperEffectiveText + jr nc, .done + ld hl, NotVeryEffectiveText +.done + jp PrintText + +SuperEffectiveText: ; 2fb8e (b:7b8e) + TX_FAR _SuperEffectiveText + db "@" + +NotVeryEffectiveText: ; 2fb93 (b:7b93) + TX_FAR _NotVeryEffectiveText + db "@" diff --git a/engine/battle/link_battle_versus_text.asm b/engine/battle/link_battle_versus_text.asm new file mode 100644 index 00000000..7320da29 --- /dev/null +++ b/engine/battle/link_battle_versus_text.asm @@ -0,0 +1,23 @@ +; display "[player] VS [enemy]" text box with pokeballs representing their parties next to the names +DisplayLinkBattleVersusTextBox: ; 372d6 (d:72d6) + call LoadTextBoxTilePatterns + hlCoord 3, 4 + ld b, $7 + ld c, $c + call TextBoxBorder + hlCoord 4, 5 + ld de, wPlayerName + call PlaceString + hlCoord 4, 10 + ld de, wLinkEnemyTrainerName + call PlaceString +; place bold "VS" tiles between the names + hlCoord 9, 8 + ld a, $69 + ld [hli], a + ld [hl], $6a + xor a + ld [wUpdateSpritesEnabled], a + callab SetupPlayerAndEnemyPokeballs + ld c, 150 + jp DelayFrames diff --git a/engine/battle/moveEffects/mist_effect.asm b/engine/battle/moveEffects/mist_effect.asm new file mode 100644 index 00000000..adee1dfd --- /dev/null +++ b/engine/battle/moveEffects/mist_effect.asm @@ -0,0 +1,21 @@ +MistEffect_: ; 33f2b (c:7f2b) + ld hl, W_PLAYERBATTSTATUS2 + ld a, [$fff3] + and a + jr z, .asm_33f36 + ld hl, W_ENEMYBATTSTATUS2 +.asm_33f36 + bit ProtectedByMist, [hl] ; is mon protected by mist? + jr nz, .asm_33f4a + set ProtectedByMist, [hl] ; mon is now protected by mist + callab PlayCurrentMoveAnimation + ld hl, ShroudedInMistText + jp PrintText +.asm_33f4a + ld hl, PrintButItFailedText_ + ld b, BANK(PrintButItFailedText_) + jp Bankswitch + +ShroudedInMistText: ; 33f52 (c:7f52) + TX_FAR _ShroudedInMistText + db "@" diff --git a/engine/battle/moveEffects/one_hit_ko_effect.asm b/engine/battle/moveEffects/one_hit_ko_effect.asm new file mode 100644 index 00000000..84418e33 --- /dev/null +++ b/engine/battle/moveEffects/one_hit_ko_effect.asm @@ -0,0 +1,36 @@ +OneHitKOEffect_: ; 33f57 (c:7f57) + ld hl, W_DAMAGE + xor a + ld [hli], a + ld [hl], a ; set the damage output to zero + dec a + ld [wCriticalHitOrOHKO], a + ld hl, wBattleMonSpeed + 1 + ld de, wEnemyMonSpeed + 1 + ld a, [H_WHOSETURN] ; $fff3 + and a + jr z, .asm_33f72 + ld hl, wEnemyMonSpeed + 1 + ld de, wBattleMonSpeed + 1 +.asm_33f72 + ld a, [de] + dec de + ld b, a + ld a, [hld] + sub b + ld a, [de] + ld b, a + ld a, [hl] + sbc b + jr c, .asm_33f8a + ld hl, W_DAMAGE + ld a, $ff + ld [hli], a + ld [hl], a + ld a, $2 + ld [wCriticalHitOrOHKO], a + ret +.asm_33f8a + ld a, $1 + ld [W_MOVEMISSED], a + ret diff --git a/engine/battle/moveEffects/pay_day_effect.asm b/engine/battle/moveEffects/pay_day_effect.asm new file mode 100644 index 00000000..75a005ed --- /dev/null +++ b/engine/battle/moveEffects/pay_day_effect.asm @@ -0,0 +1,43 @@ +PayDayEffect_ ; 2feb8 (b:7eb8) + xor a + ld hl, wcd6d + ld [hli], a + ld a, [H_WHOSETURN] + and a + ld a, [wBattleMonLevel] + jr z, .asm_2fec8 + ld a, [wEnemyMonLevel] +.asm_2fec8 + add a + ld [H_DIVIDEND + 3], a + xor a + ld [H_DIVIDEND], a + ld [H_DIVIDEND + 1], a + ld [H_DIVIDEND + 2], a + ld a, $64 + ld [H_DIVISOR], a + ld b, $4 + call Divide + ld a, [H_QUOTIENT + 3] + ld [hli], a + ld a, [H_REMAINDER] + ld [H_DIVIDEND + 3], a + ld a, $a + ld [H_DIVISOR], a + ld b, $4 + call Divide + ld a, [H_QUOTIENT + 3] + swap a + ld b, a + ld a, [H_REMAINDER] + add b + ld [hl], a + ld de, wTotalPayDayMoney + 2 + ld c, $3 + predef AddBCDPredef + ld hl, CoinsScatteredText + jp PrintText + +CoinsScatteredText: ; 2ff04 (b:7f04) + TX_FAR _CoinsScatteredText + db "@" diff --git a/engine/battle/scale_sprites.asm b/engine/battle/scale_sprites.asm new file mode 100644 index 00000000..dae4ad42 --- /dev/null +++ b/engine/battle/scale_sprites.asm @@ -0,0 +1,85 @@ +; scales both uncompressed sprite chunks by two in every dimension (creating 2x2 output pixels per input pixel) +; assumes that input sprite chunks are 4x4 tiles, and the rightmost and bottommost 4 pixels will be ignored +; resulting in a 7*7 tile output sprite chunk +ScaleSpriteByTwo: ; 2fe40 (b:7e40) + ld de, S_SPRITEBUFFER1 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped + ld hl, S_SPRITEBUFFER0 + SPRITEBUFFERSIZE - 1 ; end of destination buffer + call ScaleLastSpriteColumnByTwo ; last tile column is special case + call ScaleFirstThreeSpriteColumnsByTwo ; scale first 3 tile columns + ld de, S_SPRITEBUFFER2 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped + ld hl, S_SPRITEBUFFER1 + SPRITEBUFFERSIZE - 1 ; end of destination buffer + call ScaleLastSpriteColumnByTwo ; last tile column is special case + +ScaleFirstThreeSpriteColumnsByTwo: ; 2fe55 (b:7e55) + ld b, $3 ; 3 tile columns +.columnLoop + ld c, 4*8 - 4 ; $1c, 4 tiles minus 4 unused rows +.columnInnerLoop + push bc + ld a, [de] + ld bc, -(7*8)+1 ; $ffc9, scale lower nybble and seek to previous output column + call ScalePixelsByTwo + ld a, [de] + dec de + swap a + ld bc, 7*8+1-2 ; $37, scale upper nybble and seek back to current output column and to the next 2 rows + call ScalePixelsByTwo + pop bc + dec c + jr nz, .columnInnerLoop + dec de + dec de + dec de + dec de + ld a, b + ld bc, -7*8 ; $ffc8, skip one output column (which has already been written along with the current one) + add hl, bc + ld b, a + dec b + jr nz, .columnLoop + ret + +ScaleLastSpriteColumnByTwo: ; 2fe7d (b:7e7d) + ld a, 4*8 - 4 ; $1c, 4 tiles minus 4 unused rows + ld [H_SPRITEINTERLACECOUNTER], a ; $ff8b + ld bc, -1 ; $ffff +.columnInnerLoop + ld a, [de] + dec de + swap a ; only high nybble contains information + call ScalePixelsByTwo + ld a, [H_SPRITEINTERLACECOUNTER] ; $ff8b + dec a + ld [H_SPRITEINTERLACECOUNTER], a ; $ff8b + jr nz, .columnInnerLoop + dec de ; skip last 4 rows of new column + dec de + dec de + dec de + ret + +; scales the given 4 bits in a (4x1 pixels) to 2 output bytes (8x2 pixels) +; hl: destination pointer +; bc: destination pointer offset (added after the two bytes have been written) +ScalePixelsByTwo: ; 2fe97 (b:7e97) + push hl + and $f + ld hl, DuplicateBitsTable + add l + ld l, a + jr nc, .noCarry + inc h +.noCarry + ld a, [hl] + pop hl + ld [hld], a ; write output byte twice to make it 2 pixels high + ld [hl], a + add hl, bc ; add offset + ret + +; repeats each input bit twice +DuplicateBitsTable: ; 2fea8 (b:7ea8) + db $00, $03, $0c, $0f + db $30, $33, $3c, $3f + db $c0, $c3, $cc, $cf + db $f0, $f3, $fc, $ff diff --git a/main.asm b/main.asm index 1c7f15f9..838c4c39 100755 --- a/main.asm +++ b/main.asm @@ -5307,7 +5307,7 @@ FossilKabutopsPic:: INCBIN "pic/bmon/fossilkabutops.pic" SECTION "Battle (bank B)", ROMX, BANK[$B] -INCLUDE "engine/battle/b.asm" +INCLUDE "engine/battle/display_effectiveness.asm" TrainerInfoTextBoxTileGraphics: INCBIN "gfx/trainer_info.2bpp" BlankLeaderNames: INCBIN "gfx/blank_leader_names.2bpp" @@ -5315,7 +5315,8 @@ CircleTile: INCBIN "gfx/circle_tile.2bpp" BadgeNumbersTileGraphics: INCBIN "gfx/badge_numbers.2bpp" INCLUDE "engine/items/tmhm.asm" -INCLUDE "engine/battle/b_2.asm" +INCLUDE "engine/battle/scale_sprites.asm" +INCLUDE "engine/battle/moveEffects/pay_day_effect.asm" INCLUDE "engine/game_corner_slots2.asm" @@ -5385,7 +5386,8 @@ OldManPic:: INCBIN "pic/trainer/oldman.pic" SECTION "Battle (bank C)", ROMX, BANK[$C] -INCLUDE "engine/battle/c.asm" +INCLUDE "engine/battle/moveEffects/mist_effect.asm" +INCLUDE "engine/battle/moveEffects/one_hit_ko_effect.asm" SECTION "Pics 5", ROMX, BANK[PICS_5] @@ -5449,7 +5451,7 @@ VictreebelPicBack:: INCBIN "pic/monback/victreebelb.pic" SECTION "Battle (bank D)", ROMX, BANK[$D] INCLUDE "engine/titlescreen2.asm" -INCLUDE "engine/battle/d.asm" +INCLUDE "engine/battle/link_battle_versus_text.asm" INCLUDE "engine/slot_machine.asm" INCLUDE "engine/overworld/pewter_guys.asm" INCLUDE "engine/multiply_divide.asm" -- cgit v1.3.1-sl0p From 2fe782b11a039b52fd236da28fb2f1ae10cae7db Mon Sep 17 00:00:00 2001 From: xCrystal Date: Wed, 1 Apr 2015 16:51:04 +0200 Subject: Rename battle files and split move effects Part 4 e.asm, e_2. asm, and 14.asm --- engine/battle/14.asm | 94 -- engine/battle/draw_hud_pokeball_gfx.asm | 191 +++ engine/battle/e.asm | 1569 -------------------- engine/battle/e_2.asm | 301 ---- engine/battle/init_battle_variables.asm | 40 + engine/battle/moveEffects/heal_effect.asm | 116 ++ engine/battle/moveEffects/paralyze_effect.asm | 53 + .../moveEffects/reflect_light_screen_effect.asm | 45 + engine/battle/moveEffects/transform_effect.asm | 138 ++ engine/battle/scroll_draw_trainer_pic.asm | 50 + engine/battle/trainer_party_ai_misc.asm | 1263 ++++++++++++++++ engine/battle/unused_stats_functions.asm | 62 + main.asm | 12 +- 13 files changed, 1967 insertions(+), 1967 deletions(-) delete mode 100755 engine/battle/14.asm create mode 100644 engine/battle/draw_hud_pokeball_gfx.asm delete mode 100755 engine/battle/e.asm delete mode 100755 engine/battle/e_2.asm create mode 100644 engine/battle/init_battle_variables.asm create mode 100644 engine/battle/moveEffects/heal_effect.asm create mode 100644 engine/battle/moveEffects/paralyze_effect.asm create mode 100644 engine/battle/moveEffects/reflect_light_screen_effect.asm create mode 100644 engine/battle/moveEffects/transform_effect.asm create mode 100644 engine/battle/scroll_draw_trainer_pic.asm create mode 100644 engine/battle/trainer_party_ai_misc.asm create mode 100644 engine/battle/unused_stats_functions.asm (limited to 'main.asm') diff --git a/engine/battle/14.asm b/engine/battle/14.asm deleted file mode 100755 index 1b2d7462..00000000 --- a/engine/battle/14.asm +++ /dev/null @@ -1,94 +0,0 @@ -InitBattleVariables: ; 525af (14:65af) - ld a, [hTilesetType] - ld [wd0d4], a - xor a - ld [wcd6a], a - ld [wBattleResult], a - ld hl, wcc2b - ld [hli], a - ld [hli], a - ld [hli], a - ld [hl], a - ld [wListScrollOffset], a - ld [wCriticalHitOrOHKO], a - ld [wBattleMonSpecies], a - ld [wPartyGainExpFlags], a - ld [wPlayerMonNumber], a - ld [wEscapedFromBattle], a - ld [wMapPalOffset], a - ld hl, wcf1d - ld [hli], a - ld [hl], a - ld hl, wccd3 - ld b, $3c -.loop - ld [hli], a - dec b - jr nz, .loop - inc a - ld [wccd9], a - ld a, [W_CURMAP] - cp SAFARI_ZONE_EAST - jr c, .notSafariBattle - cp SAFARI_ZONE_REST_HOUSE_1 - jr nc, .notSafariBattle - ld a, $2 ; safari battle - ld [W_BATTLETYPE], a -.notSafariBattle - ld hl, PlayBattleMusic - ld b, BANK(PlayBattleMusic) - jp Bankswitch - -ParalyzeEffect_: ; 52601 (14:6601) - ld hl, wEnemyMonStatus - ld de, W_PLAYERMOVETYPE - ld a, [H_WHOSETURN] - and a - jp z, .next - ld hl, wBattleMonStatus - ld de, W_ENEMYMOVETYPE -.next - ld a, [hl] - and a ; does the target already have a status ailment? - jr nz, .didntAffect -; check if the target is immune due to types - ld a, [de] - cp ELECTRIC - jr nz, .hitTest - ld b, h - ld c, l - inc bc - ld a, [bc] - cp GROUND - jr z, .doesntAffect - inc bc - ld a, [bc] - cp GROUND - jr z, .doesntAffect -.hitTest - push hl - callab MoveHitTest - pop hl - ld a, [W_MOVEMISSED] - and a - jr nz, .didntAffect - set PAR, [hl] - callab QuarterSpeedDueToParalysis - ld c, 30 - call DelayFrames - callab PlayCurrentMoveAnimation - ld hl, PrintMayNotAttackText - ld b, BANK(PrintMayNotAttackText) - jp Bankswitch -.didntAffect - ld c, 50 - call DelayFrames - ld hl, PrintDidntAffectText - ld b, BANK(PrintDidntAffectText) - jp Bankswitch -.doesntAffect - ld c, 50 - call DelayFrames - ld hl, PrintDoesntAffectText - ld b, BANK(PrintDoesntAffectText) - jp Bankswitch diff --git a/engine/battle/draw_hud_pokeball_gfx.asm b/engine/battle/draw_hud_pokeball_gfx.asm new file mode 100644 index 00000000..fce3701c --- /dev/null +++ b/engine/battle/draw_hud_pokeball_gfx.asm @@ -0,0 +1,191 @@ +DrawAllPokeballs: ; 3a849 (e:6849) + call LoadPartyPokeballGfx + call SetupOwnPartyPokeballs + ld a, [W_ISINBATTLE] ; W_ISINBATTLE + dec a + ret z ; return if wild pokémon + jp SetupEnemyPartyPokeballs + +DrawEnemyPokeballs: ; 0x3a857 + call LoadPartyPokeballGfx + jp SetupEnemyPartyPokeballs + +LoadPartyPokeballGfx: ; 3a85d (e:685d) + ld de, PokeballTileGraphics ; $697e + ld hl, vSprites + $310 + ld bc, (BANK(PokeballTileGraphics) << 8) + $04 + jp CopyVideoData + +SetupOwnPartyPokeballs: ; 3a869 (e:6869) + call PlacePlayerHUDTiles + ld hl, wPartyMon1 + ld de, wPartyCount ; wPartyCount + call SetupPokeballs + ld a, $60 + ld hl, W_BASECOORDX ; wd081 + ld [hli], a + ld [hl], a + ld a, $8 + ld [wTrainerEngageDistance], a + ld hl, wOAMBuffer + jp WritePokeballOAMData + +SetupEnemyPartyPokeballs: ; 3a887 (e:6887) + call PlaceEnemyHUDTiles + ld hl, wEnemyMons + ld de, wEnemyPartyCount ; wEnemyPartyCount + call SetupPokeballs + ld hl, W_BASECOORDX ; wd081 + ld a, $48 + ld [hli], a + ld [hl], $20 + ld a, $f8 + ld [wTrainerEngageDistance], a + ld hl, wOAMBuffer + PARTY_LENGTH * 4 + jp WritePokeballOAMData + +SetupPokeballs: ; 0x3a8a6 + ld a, [de] + push af + ld de, wBuffer + ld c, PARTY_LENGTH + ld a, $34 ; empty pokeball +.emptyloop + ld [de], a + inc de + dec c + jr nz, .emptyloop + pop af + ld de, wBuffer +.monloop + push af + call PickPokeball + inc de + pop af + dec a + jr nz, .monloop + ret + +PickPokeball: ; 3a8c2 (e:68c2) + inc hl + ld a, [hli] + and a + jr nz, .alive + ld a, [hl] + and a + ld b, $33 ; crossed ball (fainted) + jr z, .done_fainted +.alive + inc hl + inc hl + ld a, [hl] ; status + and a + ld b, $32 ; black ball (status) + jr nz, .done + dec b ; regular ball + jr .done +.done_fainted + inc hl + inc hl +.done + ld a, b + ld [de], a + ld bc, $0028 ; rest of mon struct + add hl, bc + ret + +WritePokeballOAMData: ; 3a8e1 (e:68e1) + ld de, wBuffer + ld c, PARTY_LENGTH +.loop + ld a, [W_BASECOORDY] ; wd082 + ld [hli], a + ld a, [W_BASECOORDX] ; wd081 + ld [hli], a + ld a, [de] + ld [hli], a + xor a + ld [hli], a + ld a, [W_BASECOORDX] ; wd081 + ld b, a + ld a, [wTrainerEngageDistance] + add b + ld [W_BASECOORDX], a ; wd081 + inc de + dec c + jr nz, .loop + ret + +PlacePlayerHUDTiles: ; 3a902 (e:6902) + ld hl, PlayerBattleHUDGraphicsTiles ; $6916 + ld de, wTrainerFacingDirection + ld bc, $3 + call CopyData + hlCoord 18, 10 + ld de, rIE ; $ffff + jr PlaceHUDTiles + +PlayerBattleHUDGraphicsTiles: ; 3a916 (e:6916) +; The tile numbers for specific parts of the battle display for the player's pokemon + db $73 ; unused ($73 is hardcoded into the routine that uses these bytes) + db $77 ; lower-right corner tile of the HUD + db $6F ; lower-left triangle tile of the HUD + +PlaceEnemyHUDTiles: ; 3a919 (e:6919) + ld hl, EnemyBattleHUDGraphicsTiles ; $692d + ld de, wTrainerFacingDirection + ld bc, $3 + call CopyData + hlCoord 1, 2 + ld de, $1 + jr PlaceHUDTiles + +EnemyBattleHUDGraphicsTiles: ; 3a92d (e:692d) +; The tile numbers for specific parts of the battle display for the enemy + db $73 ; unused ($73 is hardcoded in the routine that uses these bytes) + db $74 ; lower-left corner tile of the HUD + db $78 ; lower-right triangle tile of the HUD + +PlaceHUDTiles: ; 3a930 (e:6930) + ld [hl], $73 + ld bc, $14 + add hl, bc + ld a, [wTrainerScreenY] + ld [hl], a + ld a, $8 +.asm_3a93c + add hl, de + ld [hl], $76 + dec a + jr nz, .asm_3a93c + add hl, de + ld a, [wTrainerScreenX] + ld [hl], a + ret + +SetupPlayerAndEnemyPokeballs: ; 3a948 (e:6948) + call LoadPartyPokeballGfx + ld hl, wPartyMon1Species ; wPartyMon1Species (aliases: wPartyMon1) + ld de, wPartyCount ; wPartyCount + call SetupPokeballs + ld hl, W_BASECOORDX ; wd081 + ld a, $50 + ld [hli], a + ld [hl], $40 + ld a, $8 + ld [wTrainerEngageDistance], a + ld hl, wOAMBuffer + call WritePokeballOAMData + ld hl, wEnemyMons ; wEnemyMon1Species + ld de, wEnemyPartyCount ; wEnemyPartyCount + call SetupPokeballs + ld hl, W_BASECOORDX ; wd081 + ld a, $50 + ld [hli], a + ld [hl], $68 + ld hl, wOAMBuffer + $18 + jp WritePokeballOAMData + +; four tiles: pokeball, black pokeball (status ailment), crossed out pokeball (faited) and pokeball slot (no mon) +PokeballTileGraphics:: ; 3a97e (e:697e) + INCBIN "gfx/pokeball.2bpp" diff --git a/engine/battle/e.asm b/engine/battle/e.asm deleted file mode 100755 index 1144abe8..00000000 --- a/engine/battle/e.asm +++ /dev/null @@ -1,1569 +0,0 @@ -; does nothing since no stats are ever selected (barring glitches) -DoubleSelectedStats: ; 39680 (e:5680) - ld a, [H_WHOSETURN] - and a - ld a, [wPlayerStatsToDouble] - ld hl, wBattleMonAttack + 1 - jr z, .notEnemyTurn - ld a, [wEnemyStatsToDouble] - ld hl, wEnemyMonAttack + 1 -.notEnemyTurn - ld c, 4 - ld b, a -.loop - srl b - call c, .doubleStat - inc hl - inc hl - dec c - ret z - jr .loop - -.doubleStat - ld a, [hl] - add a - ld [hld], a - ld a, [hl] - rl a - ld [hli], a - ret - -; does nothing since no stats are ever selected (barring glitches) -HalveSelectedStats: ; 396a7 (e:56a7) - ld a, [H_WHOSETURN] - and a - ld a, [wPlayerStatsToHalve] - ld hl, wBattleMonAttack - jr z, .notEnemyTurn - ld a, [wEnemyStatsToHalve] - ld hl, wEnemyMonAttack -.notEnemyTurn - ld c, 4 - ld b, a -.loop - srl b - call c, .halveStat - inc hl - inc hl - dec c - ret z - jr .loop - -.halveStat - ld a, [hl] - srl a - ld [hli], a - rr [hl] - or [hl] - jr nz, .nonzeroStat - ld [hl], 1 -.nonzeroStat - dec hl - ret - -_ScrollTrainerPicAfterBattle: ; 396d3 (e:56d3) -; Load the enemy trainer's pic and scrolls it into -; the screen from the right. - xor a - ld [wEnemyMonSpecies2], a - ld b, $1 - call GoPAL_SET - callab _LoadTrainerPic - hlCoord 19, 0 - ld c, $0 -.scrollLoop - inc c - ld a, c - cp 7 - ret z - ld d, $0 - push bc - push hl -.drawTrainerPicLoop - call DrawTrainerPicColumn - inc hl - ld a, 7 - add d - ld d, a - dec c - jr nz, .drawTrainerPicLoop - ld c, 4 - call DelayFrames - pop hl - pop bc - dec hl - jr .scrollLoop - -; write one 7-tile column of the trainer pic to the tilemap -DrawTrainerPicColumn: ; 39707 (e:5707) - push hl - push de - push bc - ld e, 7 -.loop - ld [hl], d - ld bc, SCREEN_WIDTH - add hl, bc - inc d - dec e - jr nz, .loop - pop bc - pop de - pop hl - ret - -; creates a set of moves that may be used and returns its address in hl -; unused slots are filled with 0, all used slots may be chosen with equal probability -AIEnemyTrainerChooseMoves: ; 39719 (e:5719) - ld a, $a - ld hl, wHPBarMaxHP ; init temporary move selection array. Only the moves with the lowest numbers are chosen in the end - ld [hli], a ; move 1 - ld [hli], a ; move 2 - ld [hli], a ; move 3 - ld [hl], a ; move 4 - ld a, [W_ENEMYDISABLEDMOVE] ; forbid disabled move (if any) - swap a - and $f - jr z, .noMoveDisabled - ld hl, wHPBarMaxHP - dec a - ld c, a - ld b, $0 - add hl, bc ; advance pointer to forbidden move - ld [hl], $50 ; forbid (highly discourage) disabled move -.noMoveDisabled - ld hl, TrainerClassMoveChoiceModifications ; 589B - ld a, [W_TRAINERCLASS] - ld b, a -.loopTrainerClasses - dec b - jr z, .readTrainerClassData -.loopTrainerClassData - ld a, [hli] - and a - jr nz, .loopTrainerClassData - jr .loopTrainerClasses -.readTrainerClassData - ld a, [hl] - and a - jp z, .useOriginalMoveSet - push hl -.nextMoveChoiceModification - pop hl - ld a, [hli] - and a - jr z, .loopFindMinimumEntries - push hl - ld hl, AIMoveChoiceModificationFunctionPointers ; $57a3 - dec a - add a - ld c, a - ld b, $0 - add hl, bc ; skip to pointer - ld a, [hli] ; read pointer into hl - ld h, [hl] - ld l, a - ld de, .nextMoveChoiceModification ; set return address - push de - jp [hl] ; execute modification function -.loopFindMinimumEntries ; all entries will be decremented sequentially until one of them is zero - ld hl, wHPBarMaxHP ; temp move selection array - ld de, wEnemyMonMoves ; enemy moves - ld c, $4 -.loopDecrementEntries - ld a, [de] - inc de - and a - jr z, .loopFindMinimumEntries - dec [hl] - jr z, .minimumEntriesFound - inc hl - dec c - jr z, .loopFindMinimumEntries - jr .loopDecrementEntries -.minimumEntriesFound - ld a, c -.loopUndoPartialIteration ; undo last (partial) loop iteration - inc [hl] - dec hl - inc a - cp $5 - jr nz, .loopUndoPartialIteration - ld hl, wHPBarMaxHP ; temp move selection array - ld de, wEnemyMonMoves ; enemy moves - ld c, $4 -.filterMinimalEntries ; all minimal entries now have value 1. All other slots will be disabled (move set to 0) - ld a, [de] - and a - jr nz, .moveExisting ; 0x3978a $1 - ld [hl], a -.moveExisting - ld a, [hl] - dec a - jr z, .slotWithMinimalValue - xor a - ld [hli], a ; disable move slot - jr .next -.slotWithMinimalValue - ld a, [de] - ld [hli], a ; enable move slot -.next - inc de - dec c - jr nz, .filterMinimalEntries - ld hl, wHPBarMaxHP ; use created temporary array as move set - ret -.useOriginalMoveSet - ld hl, wEnemyMonMoves ; use original move set - ret - -AIMoveChoiceModificationFunctionPointers: ; 397a3 (e:57a3) - dw AIMoveChoiceModification1 - dw AIMoveChoiceModification2 - dw AIMoveChoiceModification3 - dw AIMoveChoiceModification4 ; unused, does nothing - -; discourages moves that cause no damage but only a status ailment if player's mon already has one -AIMoveChoiceModification1: ; 397ab (e:57ab) - ld a, [wBattleMonStatus] - and a - ret z ; return if no status ailment on player's mon - ld hl, wBuffer - 1 ; temp move selection array (-1 byte offest) - ld de, wEnemyMonMoves ; enemy moves - ld b, NUM_MOVES + 1 -.nextMove - dec b - ret z ; processed all 4 moves - inc hl - ld a, [de] - and a - ret z ; no more moves in move set - inc de - call ReadMove - ld a, [W_ENEMYMOVEPOWER] - and a - jr nz, .nextMove - ld a, [W_ENEMYMOVEEFFECT] - push hl - push de - push bc - ld hl, StatusAilmentMoveEffects - ld de, $0001 - call IsInArray - pop bc - pop de - pop hl - jr nc, .nextMove - ld a, [hl] - add $5 ; heavily discourage move - ld [hl], a - jr .nextMove - -StatusAilmentMoveEffects ; 57e2 - db $01 ; unused sleep effect - db SLEEP_EFFECT - db POISON_EFFECT - db PARALYZE_EFFECT - db $FF - -; slightly encourage moves with specific effects. -; in particular, stat-modifying moves and other move effects -; that fall in-bewteen -AIMoveChoiceModification2: ; 397e7 (e:57e7) - ld a, [wAILayer2Encouragement] - cp $1 - ret nz - ld hl, wBuffer - 1 ; temp move selection array (-1 byte offset) - ld de, wEnemyMonMoves ; enemy moves - ld b, NUM_MOVES + 1 -.nextMove - dec b - ret z ; processed all 4 moves - inc hl - ld a, [de] - and a - ret z ; no more moves in move set - inc de - call ReadMove - ld a, [W_ENEMYMOVEEFFECT] - cp ATTACK_UP1_EFFECT - jr c, .nextMove - cp BIDE_EFFECT - jr c, .preferMove - cp ATTACK_UP2_EFFECT - jr c, .nextMove - cp POISON_EFFECT - jr c, .preferMove - jr .nextMove -.preferMove - dec [hl] ; sligthly encourage this move - jr .nextMove - -; encourages moves that are effective against the player's mon (even if non-damaging). -; discourage damaging moves that are ineffective or not very effective against the player's mon, -; unless there's no damaging move that deals at least neutral damage -AIMoveChoiceModification3: ; 39817 (e:5817) - ld hl, wBuffer - 1 ; temp move selection array (-1 byte offset) - ld de, wEnemyMonMoves ; enemy moves - ld b, $5 -.nextMove - dec b - ret z ; processed all 4 moves - inc hl - ld a, [de] - and a - ret z ; no more moves in move set - inc de - call ReadMove - push hl - push bc - push de - callab AIGetTypeEffectiveness - pop de - pop bc - pop hl - ld a, [wd11e] - cp $10 - jr z, .nextMove - jr c, .notEffectiveMove - dec [hl] ; sligthly encourage this move - jr .nextMove -.notEffectiveMove ; discourages non-effective moves if better moves are available - push hl - push de - push bc - ld a, [W_ENEMYMOVETYPE] - ld d, a - ld hl, wEnemyMonMoves ; enemy moves - ld b, NUM_MOVES + 1 - ld c, $0 -.loopMoves - dec b - jr z, .done - ld a, [hli] - and a - jr z, .done - call ReadMove - ld a, [W_ENEMYMOVEEFFECT] - cp SUPER_FANG_EFFECT - jr z, .betterMoveFound ; Super Fang is considered to be a better move - cp SPECIAL_DAMAGE_EFFECT - jr z, .betterMoveFound ; any special damage moves are considered to be better moves - cp FLY_EFFECT - jr z, .betterMoveFound ; Fly is considered to be a better move - ld a, [W_ENEMYMOVETYPE] - cp d - jr z, .loopMoves - ld a, [W_ENEMYMOVEPOWER] - and a - jr nz, .betterMoveFound ; damaging moves of a different type are considered to be better moves - jr .loopMoves -.betterMoveFound - ld c, a -.done - ld a, c - pop bc - pop de - pop hl - and a - jr z, .nextMove - inc [hl] ; sligthly discourage this move - jr .nextMove -AIMoveChoiceModification4: ; 39883 (e:5883) - ret - -ReadMove: ; 39884 (e:5884) - push hl - push de - push bc - dec a - ld hl,Moves - ld bc,6 - call AddNTimes - ld de,W_ENEMYMOVENUM - call CopyData - pop bc - pop de - pop hl - ret - -; move choice modification methods that are applied for each trainer class -; 0 is sentinel value -TrainerClassMoveChoiceModifications: ; 3989b (e:589b) - db 0 ; YOUNGSTER - db 1,0 ; BUG CATCHER - db 1,0 ; LASS - db 1,3,0 ; SAILOR - db 1,0 ; JR__TRAINER_M - db 1,0 ; JR__TRAINER_F - db 1,2,3,0; POKEMANIAC - db 1,2,0 ; SUPER_NERD - db 1,0 ; HIKER - db 1,0 ; BIKER - db 1,3,0 ; BURGLAR - db 1,0 ; ENGINEER - db 1,2,0 ; JUGGLER_X - db 1,3,0 ; FISHER - db 1,3,0 ; SWIMMER - db 0 ; CUE_BALL - db 1,0 ; GAMBLER - db 1,3,0 ; BEAUTY - db 1,2,0 ; PSYCHIC_TR - db 1,3,0 ; ROCKER - db 1,0 ; JUGGLER - db 1,0 ; TAMER - db 1,0 ; BIRD_KEEPER - db 1,0 ; BLACKBELT - db 1,0 ; SONY1 - db 1,3,0 ; PROF_OAK - db 1,2,0 ; CHIEF - db 1,2,0 ; SCIENTIST - db 1,3,0 ; GIOVANNI - db 1,0 ; ROCKET - db 1,3,0 ; COOLTRAINER_M - db 1,3,0 ; COOLTRAINER_F - db 1,0 ; BRUNO - db 1,0 ; BROCK - db 1,3,0 ; MISTY - db 1,3,0 ; LT__SURGE - db 1,3,0 ; ERIKA - db 1,3,0 ; KOGA - db 1,3,0 ; BLAINE - db 1,3,0 ; SABRINA - db 1,2,0 ; GENTLEMAN - db 1,3,0 ; SONY2 - db 1,3,0 ; SONY3 - db 1,2,3,0; LORELEI - db 1,0 ; CHANNELER - db 1,0 ; AGATHA - db 1,3,0 ; LANCE - -TrainerPicAndMoneyPointers: ; 39914 (e:5914) -; trainer pic pointers and base money. -; money received after battle = base money × level of highest-level enemy mon - dw YoungsterPic - money 1500 - - dw BugCatcherPic - money 1000 - - dw LassPic - money 1500 - - dw SailorPic - money 3000 - - dw JrTrainerMPic - money 2000 - - dw JrTrainerFPic - money 2000 - - dw PokemaniacPic - money 5000 - - dw SuperNerdPic - money 2500 - - dw HikerPic - money 3500 - - dw BikerPic - money 2000 - - dw BurglarPic - money 9000 - - dw EngineerPic - money 5000 - - dw JugglerPic - money 3500 - - dw FisherPic - money 3500 - - dw SwimmerPic - money 500 - - dw CueBallPic - money 2500 - - dw GamblerPic - money 7000 - - dw BeautyPic - money 7000 - - dw PsychicPic - money 1000 - - dw RockerPic - money 2500 - - dw JugglerPic - money 3500 - - dw TamerPic - money 4000 - - dw BirdKeeperPic - money 2500 - - dw BlackbeltPic - money 2500 - - dw Rival1Pic - money 3500 - - dw ProfOakPic - money 9900 - - dw ChiefPic - money 3000 - - dw ScientistPic - money 5000 - - dw GiovanniPic - money 9900 - - dw RocketPic - money 3000 - - dw CooltrainerMPic - money 3500 - - dw CooltrainerFPic - money 3500 - - dw BrunoPic - money 9900 - - dw BrockPic - money 9900 - - dw MistyPic - money 9900 - - dw LtSurgePic - money 9900 - - dw ErikaPic - money 9900 - - dw KogaPic - money 9900 - - dw BlainePic - money 9900 - - dw SabrinaPic - money 9900 - - dw GentlemanPic - money 7000 - - dw Rival2Pic - money 6500 - - dw Rival3Pic - money 9900 - - dw LoreleiPic - money 9900 - - dw ChannelerPic - money 3000 - - dw AgathaPic - money 9900 - - dw LancePic - money 9900 - -INCLUDE "text/trainer_names.asm" - -; formats a string at wMovesString that lists the moves at wMoves -FormatMovesString: ; 39b87 (e:5b87) - ld hl, wMoves - ld de, wMovesString - ld b, $0 -.printMoveNameLoop - ld a, [hli] - and a ; end of move list? - jr z, .printDashLoop ; print dashes when no moves are left - push hl - ld [wd0b5], a - ld a, BANK(MoveNames) - ld [wPredefBank], a - ld a, MOVE_NAME - ld [wNameListType], a - call GetName - ld hl, wcd6d -.copyNameLoop - ld a, [hli] - cp $50 - jr z, .doneCopyingName - ld [de], a - inc de - jr .copyNameLoop -.doneCopyingName - ld a, b - ld [wcd6c], a - inc b - ld a, $4e ; line break - ld [de], a - inc de - pop hl - ld a, b - cp NUM_MOVES - jr z, .done - jr .printMoveNameLoop -.printDashLoop - ld a, "-" - ld [de], a - inc de - inc b - ld a, b - cp NUM_MOVES - jr z, .done - ld a, $4e ; line break - ld [de], a - inc de - jr .printDashLoop -.done - ld a, "@" - ld [de], a - ret - -; XXX this is called in a few places, but it doesn't appear to do anything useful -Func_39bd5: ; 39bd5 (e:5bd5) - ld a, [wd11b] - cp $1 - jr nz, .asm_39be6 - ld hl, wEnemyPartyCount - ld de, wEnemyMonOT - ld a, ENEMYOT_NAME - jr .asm_39c18 -.asm_39be6 - cp $4 - jr nz, .calcAttackStat4 - ld hl, wPartyCount - ld de, wPartyMonOT - ld a, PLAYEROT_NAME - jr .asm_39c18 -.calcAttackStat4 - cp $5 - jr nz, .asm_39c02 - ld hl, wStringBuffer2 + 11 - ld de, MonsterNames - ld a, MONSTER_NAME - jr .asm_39c18 -.asm_39c02 - cp $2 - jr nz, .asm_39c10 - ld hl, wNumBagItems - ld de, ItemNames - ld a, ITEM_NAME - jr .asm_39c18 -.asm_39c10 - ld hl, wStringBuffer2 + 11 - ld de, ItemNames - ld a, ITEM_NAME -.asm_39c18 - ld [wNameListType], a - ld a, l - ld [wList], a - ld a, h - ld [wList + 1], a - ld a, e - ld [wcf8d], a - ld a, d - ld [wcf8e], a - ld bc, ItemPrices - ld a, c - ld [wItemPrices], a - ld a, b - ld [wItemPrices + 1], a - ret - -; get species of mon e in list [wcc49] for LoadMonData -GetMonSpecies: ; 39c37 (e:5c37) - ld hl, wPartySpecies - ld a, [wcc49] - and a - jr z, .getSpecies - dec a - jr z, .enemyParty - ld hl, wBoxSpecies - jr .getSpecies -.enemyParty - ld hl, wEnemyPartyMons -.getSpecies - ld d, 0 - add hl, de - ld a, [hl] - ld [wcf91], a - ret - -ReadTrainer: ; 39c53 (e:5c53) - -; don't change any moves in a link battle - ld a,[wLinkState] - and a - ret nz - -; set [wEnemyPartyCount] to 0, [wEnemyPartyMons] to FF -; XXX first is total enemy pokemon? -; XXX second is species of first pokemon? - ld hl,wEnemyPartyCount - xor a - ld [hli],a - dec a - ld [hl],a - -; get the pointer to trainer data for this class - ld a,[W_CUROPPONENT] - sub $C9 ; convert value from pokemon to trainer - add a,a - ld hl,TrainerDataPointers - ld c,a - ld b,0 - add hl,bc ; hl points to trainer class - ld a,[hli] - ld h,[hl] - ld l,a - ld a,[W_TRAINERNO] - ld b,a -; At this point b contains the trainer number, -; and hl points to the trainer class. -; Our next task is to iterate through the trainers, -; decrementing b each time, until we get to the right one. -.outer - dec b - jr z,.IterateTrainer -.inner - ld a,[hli] - and a - jr nz,.inner - jr .outer - -; if the first byte of trainer data is FF, -; - each pokemon has a specific level -; (as opposed to the whole team being of the same level) -; - if [W_LONEATTACKNO] != 0, one pokemon on the team has a special move -; else the first byte is the level of every pokemon on the team -.IterateTrainer - ld a,[hli] - cp $FF ; is the trainer special? - jr z,.SpecialTrainer ; if so, check for special moves - ld [W_CURENEMYLVL],a -.LoopTrainerData - ld a,[hli] - and a ; have we reached the end of the trainer data? - jr z,.FinishUp - ld [wcf91],a ; write species somewhere (XXX why?) - ld a,1 - ld [wcc49],a - push hl - call AddPartyMon - pop hl - jr .LoopTrainerData -.SpecialTrainer -; if this code is being run: -; - each pokemon has a specific level -; (as opposed to the whole team being of the same level) -; - if [W_LONEATTACKNO] != 0, one pokemon on the team has a special move - ld a,[hli] - and a ; have we reached the end of the trainer data? - jr z,.AddLoneMove - ld [W_CURENEMYLVL],a - ld a,[hli] - ld [wcf91],a - ld a,1 - ld [wcc49],a - push hl - call AddPartyMon - pop hl - jr .SpecialTrainer -.AddLoneMove -; does the trainer have a single monster with a different move - ld a,[W_LONEATTACKNO] ; Brock is 01, Misty is 02, Erika is 04, etc - and a - jr z,.AddTeamMove - dec a - add a,a - ld c,a - ld b,0 - ld hl,LoneMoves - add hl,bc - ld a,[hli] - ld d,[hl] - ld hl,wEnemyMon1Moves + 2 - ld bc,wEnemyMon2 - wEnemyMon1 - call AddNTimes - ld [hl],d - jr .FinishUp -.AddTeamMove -; check if our trainer's team has special moves - -; get trainer class number - ld a,[W_CUROPPONENT] - sub $C8 - ld b,a - ld hl,TeamMoves - -; iterate through entries in TeamMoves, checking each for our trainer class -.IterateTeamMoves - ld a,[hli] - cp b - jr z,.GiveTeamMoves ; is there a match? - inc hl ; if not, go to the next entry - inc a - jr nz,.IterateTeamMoves - - ; no matches found. is this trainer champion rival? - ld a,b - cp SONY3 - jr z,.ChampionRival - jr .FinishUp ; nope -.GiveTeamMoves - ld a,[hl] - ld [wEnemyMon5Moves + 2],a - jr .FinishUp -.ChampionRival ; give moves to his team - -; pidgeot - ld a,SKY_ATTACK - ld [wEnemyMon1Moves + 2],a - -; starter - ld a,[W_RIVALSTARTER] - cp STARTER3 - ld b,MEGA_DRAIN - jr z,.GiveStarterMove - cp STARTER1 - ld b,FIRE_BLAST - jr z,.GiveStarterMove - ld b,BLIZZARD ; must be squirtle -.GiveStarterMove - ld a,b - ld [wEnemyMon6Moves + 2],a -.FinishUp ; XXX this needs documenting - xor a ; clear D079-D07B - ld de,wd079 - ld [de],a - inc de - ld [de],a - inc de - ld [de],a - ld a,[W_CURENEMYLVL] - ld b,a -.LastLoop - ld hl,wd047 - ld c,2 - push bc - predef AddBCDPredef - pop bc - inc de - inc de - dec b - jr nz,.LastLoop - ret - -INCLUDE "data/trainer_moves.asm" - -INCLUDE "data/trainer_parties.asm" - -TrainerAI: ; 3a52e (e:652e) -;XXX called at 34964, 3c342, 3c398 - and a - ld a,[W_ISINBATTLE] - dec a - ret z ; if not a trainer, we're done here - ld a,[wLinkState] - cp LINK_STATE_BATTLING - ret z - ld a,[W_TRAINERCLASS] ; what trainer class is this? - dec a - ld c,a - ld b,0 - ld hl,TrainerAIPointers - add hl,bc - add hl,bc - add hl,bc - ld a,[wAICount] - and a - ret z ; if no AI uses left, we're done here - inc hl - inc a - jr nz,.getpointer - dec hl - ld a,[hli] - ld [wAICount],a -.getpointer - ld a,[hli] - ld h,[hl] - ld l,a - call Random - jp [hl] - -TrainerAIPointers: ; 3a55c (e:655c) -; one entry per trainer class -; first byte, number of times (per Pokémon) it can occur -; next two bytes, pointer to AI subroutine for trainer class - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,JugglerAI ; juggler_x - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,JugglerAI ; juggler - dbw 3,GenericAI - dbw 3,GenericAI - dbw 2,BlackbeltAI ; blackbelt - dbw 3,GenericAI - dbw 3,GenericAI - dbw 1,GenericAI ; chief - dbw 3,GenericAI - dbw 1,GiovanniAI ; giovanni - dbw 3,GenericAI - dbw 2,CooltrainerMAI ; cooltrainerm - dbw 1,CooltrainerFAI ; cooltrainerf - dbw 2,BrunoAI ; bruno - dbw 5,BrockAI ; brock - dbw 1,MistyAI ; misty - dbw 1,LtSurgeAI ; surge - dbw 1,ErikaAI ; erika - dbw 2,KogaAI ; koga - dbw 2,BlaineAI ; blaine - dbw 1,SabrinaAI ; sabrina - dbw 3,GenericAI - dbw 1,Sony2AI ; sony2 - dbw 1,Sony3AI ; sony3 - dbw 2,LoreleiAI ; lorelei - dbw 3,GenericAI - dbw 2,AgathaAI ; agatha - dbw 1,LanceAI ; lance - -JugglerAI: ; 3a5e9 (e:65e9) - cp $40 - ret nc - jp AISwitchIfEnoughMons - -BlackbeltAI: ; 3a5ef (e:65ef) - cp $20 - ret nc - jp AIUseXAttack - -GiovanniAI: ; 3a5f5 (e:65f5) - cp $40 - ret nc - jp AIUseGuardSpec - -CooltrainerMAI: ; 3a5fb (e:65fb) - cp $40 - ret nc - jp AIUseXAttack - -CooltrainerFAI: ; 3a601 (e:6601) - cp $40 - ld a,$A - call AICheckIfHPBelowFraction - jp c,AIUseHyperPotion - ld a,5 - call AICheckIfHPBelowFraction - ret nc - jp AISwitchIfEnoughMons - -BrockAI: ; 3a614 (e:6614) -; if his active monster has a status condition, use a full heal - ld a,[wEnemyMonStatus] - and a - ret z - jp AIUseFullHeal - -MistyAI: ; 3a61c (e:661c) - cp $40 - ret nc - jp AIUseXDefend - -LtSurgeAI: ; 3a622 (e:6622) - cp $40 - ret nc - jp AIUseXSpeed - -ErikaAI: ; 3a628 (e:6628) - cp $80 - ret nc - ld a,$A - call AICheckIfHPBelowFraction - ret nc - jp AIUseSuperPotion - -KogaAI: ; 3a634 (e:6634) - cp $40 - ret nc - jp AIUseXAttack - -BlaineAI: ; 3a63a (e:663a) - cp $40 - ret nc - jp AIUseSuperPotion - -SabrinaAI: ; 3a640 (e:6640) - cp $40 - ret nc - ld a,$A - call AICheckIfHPBelowFraction - ret nc - jp AIUseHyperPotion - -Sony2AI: ; 3a64c (e:664c) - cp $20 - ret nc - ld a,5 - call AICheckIfHPBelowFraction - ret nc - jp AIUsePotion - -Sony3AI: ; 3a658 (e:6658) - cp $20 - ret nc - ld a,5 - call AICheckIfHPBelowFraction - ret nc - jp AIUseFullRestore - -LoreleiAI: ; 3a664 (e:6664) - cp $80 - ret nc - ld a,5 - call AICheckIfHPBelowFraction - ret nc - jp AIUseSuperPotion - -BrunoAI: ; 3a670 (e:6670) - cp $40 - ret nc - jp AIUseXDefend - -AgathaAI: ; 3a676 (e:6676) - cp $14 - jp c,AISwitchIfEnoughMons - cp $80 - ret nc - ld a,4 - call AICheckIfHPBelowFraction - ret nc - jp AIUseSuperPotion - -LanceAI: ; 3a687 (e:6687) - cp $80 - ret nc - ld a,5 - call AICheckIfHPBelowFraction - ret nc - jp AIUseHyperPotion - -GenericAI: ; 3a693 (e:6693) - and a ; clear carry - ret - -; end of individual trainer AI routines - -DecrementAICount: ; 3a695 (e:6695) - ld hl,wAICount - dec [hl] - scf - ret - -Func_3a69b: ; 3a69b (e:669b) - ld a,(SFX_08_3e - SFX_Headers_08) / 3 - jp PlaySoundWaitForCurrent - -AIUseFullRestore: ; 3a6a0 (e:66a0) - call AICureStatus - ld a,FULL_RESTORE - ld [wcf05],a - ld de,wHPBarOldHP - ld hl,wEnemyMonHP + 1 - ld a,[hld] - ld [de],a - inc de - ld a,[hl] - ld [de],a - inc de - ld hl,wEnemyMonMaxHP + 1 - ld a,[hld] - ld [de],a - inc de - ld [wHPBarMaxHP],a - ld [wEnemyMonHP + 1],a - ld a,[hl] - ld [de],a - ld [wHPBarMaxHP+1],a - ld [wEnemyMonHP],a - jr AIPrintItemUseAndUpdateHPBar - -AIUsePotion: ; 3a6ca (e:66ca) -; enemy trainer heals his monster with a potion - ld a,POTION - ld b,20 - jr AIRecoverHP - -AIUseSuperPotion: ; 3a6d0 (e:66d0) -; enemy trainer heals his monster with a super potion - ld a,SUPER_POTION - ld b,50 - jr AIRecoverHP - -AIUseHyperPotion: ; 3a6d6 (e:66d6) -; enemy trainer heals his monster with a hyper potion - ld a,HYPER_POTION - ld b,200 - ; fallthrough - -AIRecoverHP: ; 3a6da (e:66da) -; heal b HP and print "trainer used $(a) on pokemon!" - ld [wcf05],a - ld hl,wEnemyMonHP + 1 - ld a,[hl] - ld [wHPBarOldHP],a - add b - ld [hld],a - ld [wHPBarNewHP],a - ld a,[hl] - ld [wHPBarOldHP+1],a - ld [wHPBarNewHP+1],a - jr nc,.next - inc a - ld [hl],a - ld [wHPBarNewHP+1],a -.next - inc hl - ld a,[hld] - ld b,a - ld de,wEnemyMonMaxHP + 1 - ld a,[de] - dec de - ld [wHPBarMaxHP],a - sub b - ld a,[hli] - ld b,a - ld a,[de] - ld [wHPBarMaxHP+1],a - sbc b - jr nc,AIPrintItemUseAndUpdateHPBar - inc de - ld a,[de] - dec de - ld [hld],a - ld [wHPBarNewHP],a - ld a,[de] - ld [hl],a - ld [wHPBarNewHP+1],a - ; fallthrough - -AIPrintItemUseAndUpdateHPBar: ; 3a718 (e:6718) - call AIPrintItemUse_ - hlCoord 2, 2 - xor a - ld [wHPBarType],a - predef UpdateHPBar2 - jp DecrementAICount - -AISwitchIfEnoughMons: ; 3a72a (e:672a) -; enemy trainer switches if there are 3 or more unfainted mons in party - ld a,[wEnemyPartyCount] - ld c,a - ld hl,wEnemyMon1HP - - ld d,0 ; keep count of unfainted monsters - - ; count how many monsters haven't fainted yet -.loop - ld a,[hli] - ld b,a - ld a,[hld] - or b - jr z,.Fainted ; has monster fainted? - inc d -.Fainted - push bc - ld bc,$2C - add hl,bc - pop bc - dec c - jr nz,.loop - - ld a,d ; how many available monsters are there? - cp 2 ; don't bother if only 1 or 2 - jp nc,SwitchEnemyMon - and a - ret - -SwitchEnemyMon: ; 3a74b (e:674b) - -; prepare to withdraw the active monster: copy hp, number, and status to roster - - ld a,[wEnemyMonPartyPos] - ld hl,wEnemyMon1HP - ld bc,wEnemyMon2 - wEnemyMon1 - call AddNTimes - ld d,h - ld e,l - ld hl,wEnemyMonHP - ld bc,4 - call CopyData - - ld hl, AIBattleWithdrawText - call PrintText - - ld a,1 - ld [wd11d],a - callab EnemySendOut - xor a - ld [wd11d],a - - ld a,[wLinkState] - cp LINK_STATE_BATTLING - ret z - scf - ret - -AIBattleWithdrawText: ; 3a781 (e:6781) - TX_FAR _AIBattleWithdrawText - db "@" - -AIUseFullHeal: ; 3a786 (e:6786) - call Func_3a69b - call AICureStatus - ld a,FULL_HEAL - jp AIPrintItemUse - -AICureStatus: ; 3a791 (e:6791) -; cures the status of enemy's active pokemon - ld a,[wEnemyMonPartyPos] - ld hl,wEnemyMon1Status - ld bc,wEnemyMon2 - wEnemyMon1 - call AddNTimes - xor a - ld [hl],a ; clear status in enemy team roster - ld [wEnemyMonStatus],a ; clear status of active enemy - ld hl,W_ENEMYBATTSTATUS3 - res 0,[hl] - ret - -AIUseXAccuracy: ; 0x3a7a8 unused - call Func_3a69b - ld hl,W_ENEMYBATTSTATUS2 - set 0,[hl] - ld a,X_ACCURACY - jp AIPrintItemUse - -AIUseGuardSpec: ; 3a7b5 (e:67b5) - call Func_3a69b - ld hl,W_ENEMYBATTSTATUS2 - set 1,[hl] - ld a,GUARD_SPEC_ - jp AIPrintItemUse - -AIUseDireHit: ; 0x3a7c2 unused - call Func_3a69b - ld hl,W_ENEMYBATTSTATUS2 - set 2,[hl] - ld a,DIRE_HIT - jp AIPrintItemUse - -AICheckIfHPBelowFraction: ; 3a7cf (e:67cf) -; return carry if enemy trainer's current HP is below 1 / a of the maximum - ld [H_DIVISOR],a - ld hl,wEnemyMonMaxHP - ld a,[hli] - ld [H_DIVIDEND],a - ld a,[hl] - ld [H_DIVIDEND + 1],a - ld b,2 - call Divide - ld a,[H_QUOTIENT + 3] - ld c,a - ld a,[H_QUOTIENT + 2] - ld b,a - ld hl,wEnemyMonHP + 1 - ld a,[hld] - ld e,a - ld a,[hl] - ld d,a - ld a,d - sub b - ret nz - ld a,e - sub c - ret - -AIUseXAttack: ; 3a7f2 (e:67f2) - ld b,$A - ld a,X_ATTACK - jr AIIncreaseStat - -AIUseXDefend: ; 3a7f8 (e:67f8) - ld b,$B - ld a,X_DEFEND - jr AIIncreaseStat - -AIUseXSpeed: ; 3a7fe (e:67fe) - ld b,$C - ld a,X_SPEED - jr AIIncreaseStat - -AIUseXSpecial: ; 3a804 (e:6804) - ld b,$D - ld a,X_SPECIAL - ; fallthrough - -AIIncreaseStat: ; 3a808 (e:6808) - ld [wcf05],a - push bc - call AIPrintItemUse_ - pop bc - ld hl,W_ENEMYMOVEEFFECT - ld a,[hld] - push af - ld a,[hl] - push af - push hl - ld a,$AF - ld [hli],a - ld [hl],b - callab StatModifierUpEffect - pop hl - pop af - ld [hli],a - pop af - ld [hl],a - jp DecrementAICount - -AIPrintItemUse: ; 3a82c (e:682c) - ld [wcf05],a - call AIPrintItemUse_ - jp DecrementAICount - -AIPrintItemUse_: ; 3a835 (e:6835) -; print "x used [wcf05] on z!" - ld a,[wcf05] - ld [wd11e],a - call GetItemName - ld hl, AIBattleUseItemText - jp PrintText - -AIBattleUseItemText: ; 3a844 (e:6844) - TX_FAR _AIBattleUseItemText - db "@" - -DrawAllPokeballs: ; 3a849 (e:6849) - call LoadPartyPokeballGfx - call SetupOwnPartyPokeballs - ld a, [W_ISINBATTLE] ; W_ISINBATTLE - dec a - ret z ; return if wild pokémon - jp SetupEnemyPartyPokeballs - -DrawEnemyPokeballs: ; 0x3a857 - call LoadPartyPokeballGfx - jp SetupEnemyPartyPokeballs - -LoadPartyPokeballGfx: ; 3a85d (e:685d) - ld de, PokeballTileGraphics ; $697e - ld hl, vSprites + $310 - ld bc, (BANK(PokeballTileGraphics) << 8) + $04 - jp CopyVideoData - -SetupOwnPartyPokeballs: ; 3a869 (e:6869) - call PlacePlayerHUDTiles - ld hl, wPartyMon1 - ld de, wPartyCount ; wPartyCount - call SetupPokeballs - ld a, $60 - ld hl, W_BASECOORDX ; wd081 - ld [hli], a - ld [hl], a - ld a, $8 - ld [wTrainerEngageDistance], a - ld hl, wOAMBuffer - jp WritePokeballOAMData - -SetupEnemyPartyPokeballs: ; 3a887 (e:6887) - call PlaceEnemyHUDTiles - ld hl, wEnemyMons - ld de, wEnemyPartyCount ; wEnemyPartyCount - call SetupPokeballs - ld hl, W_BASECOORDX ; wd081 - ld a, $48 - ld [hli], a - ld [hl], $20 - ld a, $f8 - ld [wTrainerEngageDistance], a - ld hl, wOAMBuffer + PARTY_LENGTH * 4 - jp WritePokeballOAMData - -SetupPokeballs: ; 0x3a8a6 - ld a, [de] - push af - ld de, wBuffer - ld c, PARTY_LENGTH - ld a, $34 ; empty pokeball -.emptyloop - ld [de], a - inc de - dec c - jr nz, .emptyloop - pop af - ld de, wBuffer -.monloop - push af - call PickPokeball - inc de - pop af - dec a - jr nz, .monloop - ret - -PickPokeball: ; 3a8c2 (e:68c2) - inc hl - ld a, [hli] - and a - jr nz, .alive - ld a, [hl] - and a - ld b, $33 ; crossed ball (fainted) - jr z, .done_fainted -.alive - inc hl - inc hl - ld a, [hl] ; status - and a - ld b, $32 ; black ball (status) - jr nz, .done - dec b ; regular ball - jr .done -.done_fainted - inc hl - inc hl -.done - ld a, b - ld [de], a - ld bc, $0028 ; rest of mon struct - add hl, bc - ret - -WritePokeballOAMData: ; 3a8e1 (e:68e1) - ld de, wBuffer - ld c, PARTY_LENGTH -.loop - ld a, [W_BASECOORDY] ; wd082 - ld [hli], a - ld a, [W_BASECOORDX] ; wd081 - ld [hli], a - ld a, [de] - ld [hli], a - xor a - ld [hli], a - ld a, [W_BASECOORDX] ; wd081 - ld b, a - ld a, [wTrainerEngageDistance] - add b - ld [W_BASECOORDX], a ; wd081 - inc de - dec c - jr nz, .loop - ret - -PlacePlayerHUDTiles: ; 3a902 (e:6902) - ld hl, PlayerBattleHUDGraphicsTiles ; $6916 - ld de, wTrainerFacingDirection - ld bc, $3 - call CopyData - hlCoord 18, 10 - ld de, rIE ; $ffff - jr PlaceHUDTiles - -PlayerBattleHUDGraphicsTiles: ; 3a916 (e:6916) -; The tile numbers for specific parts of the battle display for the player's pokemon - db $73 ; unused ($73 is hardcoded into the routine that uses these bytes) - db $77 ; lower-right corner tile of the HUD - db $6F ; lower-left triangle tile of the HUD - -PlaceEnemyHUDTiles: ; 3a919 (e:6919) - ld hl, EnemyBattleHUDGraphicsTiles ; $692d - ld de, wTrainerFacingDirection - ld bc, $3 - call CopyData - hlCoord 1, 2 - ld de, $1 - jr PlaceHUDTiles - -EnemyBattleHUDGraphicsTiles: ; 3a92d (e:692d) -; The tile numbers for specific parts of the battle display for the enemy - db $73 ; unused ($73 is hardcoded in the routine that uses these bytes) - db $74 ; lower-left corner tile of the HUD - db $78 ; lower-right triangle tile of the HUD - -PlaceHUDTiles: ; 3a930 (e:6930) - ld [hl], $73 - ld bc, $14 - add hl, bc - ld a, [wTrainerScreenY] - ld [hl], a - ld a, $8 -.asm_3a93c - add hl, de - ld [hl], $76 - dec a - jr nz, .asm_3a93c - add hl, de - ld a, [wTrainerScreenX] - ld [hl], a - ret - -SetupPlayerAndEnemyPokeballs: ; 3a948 (e:6948) - call LoadPartyPokeballGfx - ld hl, wPartyMon1Species ; wPartyMon1Species (aliases: wPartyMon1) - ld de, wPartyCount ; wPartyCount - call SetupPokeballs - ld hl, W_BASECOORDX ; wd081 - ld a, $50 - ld [hli], a - ld [hl], $40 - ld a, $8 - ld [wTrainerEngageDistance], a - ld hl, wOAMBuffer - call WritePokeballOAMData - ld hl, wEnemyMons ; wEnemyMon1Species - ld de, wEnemyPartyCount ; wEnemyPartyCount - call SetupPokeballs - ld hl, W_BASECOORDX ; wd081 - ld a, $50 - ld [hli], a - ld [hl], $68 - ld hl, wOAMBuffer + $18 - jp WritePokeballOAMData - -; four tiles: pokeball, black pokeball (status ailment), crossed out pokeball (faited) and pokeball slot (no mon) -PokeballTileGraphics:: ; 3a97e (e:697e) - INCBIN "gfx/pokeball.2bpp" diff --git a/engine/battle/e_2.asm b/engine/battle/e_2.asm deleted file mode 100755 index 9400282d..00000000 --- a/engine/battle/e_2.asm +++ /dev/null @@ -1,301 +0,0 @@ -HealEffect_: ; 3b9ec (e:79ec) - ld a, [H_WHOSETURN] - and a - ld de, wBattleMonHP - ld hl, wBattleMonMaxHP - ld a, [W_PLAYERMOVENUM] - jr z, .asm_3ba03 - ld de, wEnemyMonHP - ld hl, wEnemyMonMaxHP - ld a, [W_ENEMYMOVENUM] -.asm_3ba03 - ld b, a - ld a, [de] - cp [hl] - inc de - inc hl - ld a, [de] - sbc [hl] - jp z, .failed - ld a, b - cp REST - jr nz, .asm_3ba37 - push hl - push de - push af - ld c, 50 - call DelayFrames - ld hl, wBattleMonStatus - ld a, [H_WHOSETURN] - and a - jr z, .asm_3ba25 - ld hl, wEnemyMonStatus -.asm_3ba25 - ld a, [hl] - and a - ld [hl], 2 ; Number of turns from Rest - ld hl, StartedSleepingEffect - jr z, .asm_3ba31 - ld hl, FellAsleepBecameHealthyText -.asm_3ba31 - call PrintText - pop af - pop de - pop hl -.asm_3ba37 - ld a, [hld] - ld [wHPBarMaxHP], a - ld c, a - ld a, [hl] - ld [wHPBarMaxHP+1], a - ld b, a - jr z, .asm_3ba47 - srl b - rr c -.asm_3ba47 - ld a, [de] - ld [wHPBarOldHP], a - add c - ld [de], a - ld [wHPBarNewHP], a - dec de - ld a, [de] - ld [wHPBarOldHP+1], a - adc b - ld [de], a - ld [wHPBarNewHP+1], a - inc hl - inc de - ld a, [de] - dec de - sub [hl] - dec hl - ld a, [de] - sbc [hl] - jr c, .asm_3ba6f - ld a, [hli] - ld [de], a - ld [wHPBarNewHP+1], a - inc de - ld a, [hl] - ld [de], a - ld [wHPBarNewHP], a -.asm_3ba6f - ld hl, PlayCurrentMoveAnimation - call BankswitchEtoF - ld a, [H_WHOSETURN] - and a - hlCoord 10, 9 - ld a, $1 - jr z, .asm_3ba83 - hlCoord 2, 2 - xor a -.asm_3ba83 - ld [wHPBarType], a - predef UpdateHPBar2 - ld hl, DrawHUDsAndHPBars - call BankswitchEtoF - ld hl, RegainedHealthText - jp PrintText -.failed - ld c, 50 - call DelayFrames - ld hl, PrintButItFailedText_ - jp BankswitchEtoF - -StartedSleepingEffect: ; 3baa2 (e:7aa2) - TX_FAR _StartedSleepingEffect - db "@" - -FellAsleepBecameHealthyText: ; 3baa7 (e:7aa7) - TX_FAR _FellAsleepBecameHealthyText - db "@" - -RegainedHealthText: ; 3baac (e:7aac) - TX_FAR _RegainedHealthText - db "@" - -TransformEffect_: ; 3bab1 (e:7ab1) - ld hl, wBattleMonSpecies - ld de, wEnemyMonSpecies - ld bc, W_ENEMYBATTSTATUS3 - ld a, [W_ENEMYBATTSTATUS1] - ld a, [H_WHOSETURN] - and a - jr nz, .asm_3bad1 - ld hl, wEnemyMonSpecies - ld de, wBattleMonSpecies - ld bc, W_PLAYERBATTSTATUS3 - ld [wPlayerMoveListIndex], a - ld a, [W_PLAYERBATTSTATUS1] -.asm_3bad1 - bit Invulnerable, a ; is mon invulnerable to typical attacks? (fly/dig) - jp nz, .failed - push hl - push de - push bc - ld hl, W_PLAYERBATTSTATUS2 - ld a, [H_WHOSETURN] - and a - jr z, .asm_3bae4 - ld hl, W_ENEMYBATTSTATUS2 -.asm_3bae4 - bit HasSubstituteUp, [hl] - push af - ld hl, Func_79747 - ld b, BANK(Func_79747) - call nz, Bankswitch - ld a, [W_OPTIONS] - add a - ld hl, PlayCurrentMoveAnimation - ld b, BANK(PlayCurrentMoveAnimation) - jr nc, .asm_3baff - ld hl, AnimationTransformMon - ld b, BANK(AnimationTransformMon) -.asm_3baff - call Bankswitch - ld hl, Func_79771 - ld b, BANK(Func_79771) - pop af - call nz, Bankswitch - pop bc - ld a, [bc] - set Transformed, a - ld [bc], a - pop de - pop hl - push hl - ld a, [hl] - ld [de], a - ld bc, $5 - add hl, bc - inc de - inc de - inc de - inc de - inc de - inc bc - inc bc - call CopyData - ld a, [H_WHOSETURN] - and a - jr z, .asm_3bb32 - ld a, [de] - ld [wcceb], a - inc de - ld a, [de] - ld [wccec], a - dec de -.asm_3bb32 - ld a, [hli] - ld [de], a - inc de - ld a, [hli] - ld [de], a - inc de - inc hl - inc hl - inc hl - inc de - inc de - inc de - ld bc, $8 - call CopyData - ld bc, $ffef - add hl, bc - ld b, $4 -.asm_3bb4a - ld a, [hli] - and a - jr z, .asm_3bb57 - ld a, $5 - ld [de], a - inc de - dec b - jr nz, .asm_3bb4a - jr .asm_3bb5d -.asm_3bb57 - xor a - ld [de], a - inc de - dec b - jr nz, .asm_3bb57 -.asm_3bb5d - pop hl - ld a, [hl] - ld [wd11e], a - call GetMonName - ld hl, wEnemyMonUnmodifiedAttack - ld de, wPlayerMonUnmodifiedAttack - call .copyBasedOnTurn - ld hl, wEnemyMonStatMods - ld de, wPlayerMonStatMods - call .copyBasedOnTurn - ld hl, TransformedText - jp PrintText - -.copyBasedOnTurn - ld a, [H_WHOSETURN] - and a - jr z, .asm_3bb86 - push hl - ld h, d - ld l, e - pop de -.asm_3bb86 - ld bc, $8 - jp CopyData - -.failed - ld hl, PrintButItFailedText_ - jp BankswitchEtoF - -TransformedText: ; 3bb92 (e:7b92) - TX_FAR _TransformedText - db "@" - -ReflectLightScreenEffect_: ; 3bb97 (e:7b97) - ld hl, W_PLAYERBATTSTATUS3 - ld de, W_PLAYERMOVEEFFECT - ld a, [H_WHOSETURN] - and a - jr z, .asm_3bba8 - ld hl, W_ENEMYBATTSTATUS3 - ld de, W_ENEMYMOVEEFFECT -.asm_3bba8 - ld a, [de] - cp LIGHT_SCREEN_EFFECT - jr nz, .reflect - bit HasLightScreenUp, [hl] ; is mon already protected by light screen? - jr nz, .moveFailed - set HasLightScreenUp, [hl] ; mon is now protected by light screen - ld hl, LightScreenProtectedText - jr .asm_3bbc1 -.reflect - bit HasReflectUp, [hl] ; is mon already protected by reflect? - jr nz, .moveFailed - set HasReflectUp, [hl] ; mon is now protected by reflect - ld hl, ReflectGainedArmorText -.asm_3bbc1 - push hl - ld hl, PlayCurrentMoveAnimation - call BankswitchEtoF - pop hl - jp PrintText -.moveFailed - ld c, $32 - call DelayFrames - ld hl, PrintButItFailedText_ - jp BankswitchEtoF - -LightScreenProtectedText: ; 3bbd7 (e:7bd7) - TX_FAR _LightScreenProtectedText - db "@" - -ReflectGainedArmorText: ; 3bbdc (e:7bdc) - TX_FAR _ReflectGainedArmorText - db "@" - -BankswitchEtoF: ; 3bbe1 (e:7be1) - ld b, BANK(BattleCore) - jp Bankswitch diff --git a/engine/battle/init_battle_variables.asm b/engine/battle/init_battle_variables.asm new file mode 100644 index 00000000..457cc4e1 --- /dev/null +++ b/engine/battle/init_battle_variables.asm @@ -0,0 +1,40 @@ +InitBattleVariables: ; 525af (14:65af) + ld a, [hTilesetType] + ld [wd0d4], a + xor a + ld [wcd6a], a + ld [wBattleResult], a + ld hl, wcc2b + ld [hli], a + ld [hli], a + ld [hli], a + ld [hl], a + ld [wListScrollOffset], a + ld [wCriticalHitOrOHKO], a + ld [wBattleMonSpecies], a + ld [wPartyGainExpFlags], a + ld [wPlayerMonNumber], a + ld [wEscapedFromBattle], a + ld [wMapPalOffset], a + ld hl, wcf1d + ld [hli], a + ld [hl], a + ld hl, wccd3 + ld b, $3c +.loop + ld [hli], a + dec b + jr nz, .loop + inc a + ld [wccd9], a + ld a, [W_CURMAP] + cp SAFARI_ZONE_EAST + jr c, .notSafariBattle + cp SAFARI_ZONE_REST_HOUSE_1 + jr nc, .notSafariBattle + ld a, $2 ; safari battle + ld [W_BATTLETYPE], a +.notSafariBattle + ld hl, PlayBattleMusic + ld b, BANK(PlayBattleMusic) + jp Bankswitch diff --git a/engine/battle/moveEffects/heal_effect.asm b/engine/battle/moveEffects/heal_effect.asm new file mode 100644 index 00000000..22d482e7 --- /dev/null +++ b/engine/battle/moveEffects/heal_effect.asm @@ -0,0 +1,116 @@ +HealEffect_: ; 3b9ec (e:79ec) + ld a, [H_WHOSETURN] + and a + ld de, wBattleMonHP + ld hl, wBattleMonMaxHP + ld a, [W_PLAYERMOVENUM] + jr z, .asm_3ba03 + ld de, wEnemyMonHP + ld hl, wEnemyMonMaxHP + ld a, [W_ENEMYMOVENUM] +.asm_3ba03 + ld b, a + ld a, [de] + cp [hl] + inc de + inc hl + ld a, [de] + sbc [hl] + jp z, .failed + ld a, b + cp REST + jr nz, .asm_3ba37 + push hl + push de + push af + ld c, 50 + call DelayFrames + ld hl, wBattleMonStatus + ld a, [H_WHOSETURN] + and a + jr z, .asm_3ba25 + ld hl, wEnemyMonStatus +.asm_3ba25 + ld a, [hl] + and a + ld [hl], 2 ; Number of turns from Rest + ld hl, StartedSleepingEffect + jr z, .asm_3ba31 + ld hl, FellAsleepBecameHealthyText +.asm_3ba31 + call PrintText + pop af + pop de + pop hl +.asm_3ba37 + ld a, [hld] + ld [wHPBarMaxHP], a + ld c, a + ld a, [hl] + ld [wHPBarMaxHP+1], a + ld b, a + jr z, .asm_3ba47 + srl b + rr c +.asm_3ba47 + ld a, [de] + ld [wHPBarOldHP], a + add c + ld [de], a + ld [wHPBarNewHP], a + dec de + ld a, [de] + ld [wHPBarOldHP+1], a + adc b + ld [de], a + ld [wHPBarNewHP+1], a + inc hl + inc de + ld a, [de] + dec de + sub [hl] + dec hl + ld a, [de] + sbc [hl] + jr c, .asm_3ba6f + ld a, [hli] + ld [de], a + ld [wHPBarNewHP+1], a + inc de + ld a, [hl] + ld [de], a + ld [wHPBarNewHP], a +.asm_3ba6f + ld hl, PlayCurrentMoveAnimation + call BankswitchEtoF + ld a, [H_WHOSETURN] + and a + hlCoord 10, 9 + ld a, $1 + jr z, .asm_3ba83 + hlCoord 2, 2 + xor a +.asm_3ba83 + ld [wHPBarType], a + predef UpdateHPBar2 + ld hl, DrawHUDsAndHPBars + call BankswitchEtoF + ld hl, RegainedHealthText + jp PrintText +.failed + ld c, 50 + call DelayFrames + ld hl, PrintButItFailedText_ + jp BankswitchEtoF + +StartedSleepingEffect: ; 3baa2 (e:7aa2) + TX_FAR _StartedSleepingEffect + db "@" + +FellAsleepBecameHealthyText: ; 3baa7 (e:7aa7) + TX_FAR _FellAsleepBecameHealthyText + db "@" + +RegainedHealthText: ; 3baac (e:7aac) + TX_FAR _RegainedHealthText + db "@" diff --git a/engine/battle/moveEffects/paralyze_effect.asm b/engine/battle/moveEffects/paralyze_effect.asm new file mode 100644 index 00000000..69acbb01 --- /dev/null +++ b/engine/battle/moveEffects/paralyze_effect.asm @@ -0,0 +1,53 @@ +ParalyzeEffect_: ; 52601 (14:6601) + ld hl, wEnemyMonStatus + ld de, W_PLAYERMOVETYPE + ld a, [H_WHOSETURN] + and a + jp z, .next + ld hl, wBattleMonStatus + ld de, W_ENEMYMOVETYPE +.next + ld a, [hl] + and a ; does the target already have a status ailment? + jr nz, .didntAffect +; check if the target is immune due to types + ld a, [de] + cp ELECTRIC + jr nz, .hitTest + ld b, h + ld c, l + inc bc + ld a, [bc] + cp GROUND + jr z, .doesntAffect + inc bc + ld a, [bc] + cp GROUND + jr z, .doesntAffect +.hitTest + push hl + callab MoveHitTest + pop hl + ld a, [W_MOVEMISSED] + and a + jr nz, .didntAffect + set PAR, [hl] + callab QuarterSpeedDueToParalysis + ld c, 30 + call DelayFrames + callab PlayCurrentMoveAnimation + ld hl, PrintMayNotAttackText + ld b, BANK(PrintMayNotAttackText) + jp Bankswitch +.didntAffect + ld c, 50 + call DelayFrames + ld hl, PrintDidntAffectText + ld b, BANK(PrintDidntAffectText) + jp Bankswitch +.doesntAffect + ld c, 50 + call DelayFrames + ld hl, PrintDoesntAffectText + ld b, BANK(PrintDoesntAffectText) + jp Bankswitch diff --git a/engine/battle/moveEffects/reflect_light_screen_effect.asm b/engine/battle/moveEffects/reflect_light_screen_effect.asm new file mode 100644 index 00000000..39a2c154 --- /dev/null +++ b/engine/battle/moveEffects/reflect_light_screen_effect.asm @@ -0,0 +1,45 @@ +ReflectLightScreenEffect_: ; 3bb97 (e:7b97) + ld hl, W_PLAYERBATTSTATUS3 + ld de, W_PLAYERMOVEEFFECT + ld a, [H_WHOSETURN] + and a + jr z, .asm_3bba8 + ld hl, W_ENEMYBATTSTATUS3 + ld de, W_ENEMYMOVEEFFECT +.asm_3bba8 + ld a, [de] + cp LIGHT_SCREEN_EFFECT + jr nz, .reflect + bit HasLightScreenUp, [hl] ; is mon already protected by light screen? + jr nz, .moveFailed + set HasLightScreenUp, [hl] ; mon is now protected by light screen + ld hl, LightScreenProtectedText + jr .asm_3bbc1 +.reflect + bit HasReflectUp, [hl] ; is mon already protected by reflect? + jr nz, .moveFailed + set HasReflectUp, [hl] ; mon is now protected by reflect + ld hl, ReflectGainedArmorText +.asm_3bbc1 + push hl + ld hl, PlayCurrentMoveAnimation + call BankswitchEtoF + pop hl + jp PrintText +.moveFailed + ld c, $32 + call DelayFrames + ld hl, PrintButItFailedText_ + jp BankswitchEtoF + +LightScreenProtectedText: ; 3bbd7 (e:7bd7) + TX_FAR _LightScreenProtectedText + db "@" + +ReflectGainedArmorText: ; 3bbdc (e:7bdc) + TX_FAR _ReflectGainedArmorText + db "@" + +BankswitchEtoF: ; 3bbe1 (e:7be1) + ld b, BANK(BattleCore) + jp Bankswitch diff --git a/engine/battle/moveEffects/transform_effect.asm b/engine/battle/moveEffects/transform_effect.asm new file mode 100644 index 00000000..6e25712a --- /dev/null +++ b/engine/battle/moveEffects/transform_effect.asm @@ -0,0 +1,138 @@ +TransformEffect_: ; 3bab1 (e:7ab1) + ld hl, wBattleMonSpecies + ld de, wEnemyMonSpecies + ld bc, W_ENEMYBATTSTATUS3 + ld a, [W_ENEMYBATTSTATUS1] + ld a, [H_WHOSETURN] + and a + jr nz, .asm_3bad1 + ld hl, wEnemyMonSpecies + ld de, wBattleMonSpecies + ld bc, W_PLAYERBATTSTATUS3 + ld [wPlayerMoveListIndex], a + ld a, [W_PLAYERBATTSTATUS1] +.asm_3bad1 + bit Invulnerable, a ; is mon invulnerable to typical attacks? (fly/dig) + jp nz, .failed + push hl + push de + push bc + ld hl, W_PLAYERBATTSTATUS2 + ld a, [H_WHOSETURN] + and a + jr z, .asm_3bae4 + ld hl, W_ENEMYBATTSTATUS2 +.asm_3bae4 + bit HasSubstituteUp, [hl] + push af + ld hl, Func_79747 + ld b, BANK(Func_79747) + call nz, Bankswitch + ld a, [W_OPTIONS] + add a + ld hl, PlayCurrentMoveAnimation + ld b, BANK(PlayCurrentMoveAnimation) + jr nc, .asm_3baff + ld hl, AnimationTransformMon + ld b, BANK(AnimationTransformMon) +.asm_3baff + call Bankswitch + ld hl, Func_79771 + ld b, BANK(Func_79771) + pop af + call nz, Bankswitch + pop bc + ld a, [bc] + set Transformed, a + ld [bc], a + pop de + pop hl + push hl + ld a, [hl] + ld [de], a + ld bc, $5 + add hl, bc + inc de + inc de + inc de + inc de + inc de + inc bc + inc bc + call CopyData + ld a, [H_WHOSETURN] + and a + jr z, .asm_3bb32 + ld a, [de] + ld [wcceb], a + inc de + ld a, [de] + ld [wccec], a + dec de +.asm_3bb32 + ld a, [hli] + ld [de], a + inc de + ld a, [hli] + ld [de], a + inc de + inc hl + inc hl + inc hl + inc de + inc de + inc de + ld bc, $8 + call CopyData + ld bc, $ffef + add hl, bc + ld b, $4 +.asm_3bb4a + ld a, [hli] + and a + jr z, .asm_3bb57 + ld a, $5 + ld [de], a + inc de + dec b + jr nz, .asm_3bb4a + jr .asm_3bb5d +.asm_3bb57 + xor a + ld [de], a + inc de + dec b + jr nz, .asm_3bb57 +.asm_3bb5d + pop hl + ld a, [hl] + ld [wd11e], a + call GetMonName + ld hl, wEnemyMonUnmodifiedAttack + ld de, wPlayerMonUnmodifiedAttack + call .copyBasedOnTurn + ld hl, wEnemyMonStatMods + ld de, wPlayerMonStatMods + call .copyBasedOnTurn + ld hl, TransformedText + jp PrintText + +.copyBasedOnTurn + ld a, [H_WHOSETURN] + and a + jr z, .asm_3bb86 + push hl + ld h, d + ld l, e + pop de +.asm_3bb86 + ld bc, $8 + jp CopyData + +.failed + ld hl, PrintButItFailedText_ + jp BankswitchEtoF + +TransformedText: ; 3bb92 (e:7b92) + TX_FAR _TransformedText + db "@" diff --git a/engine/battle/scroll_draw_trainer_pic.asm b/engine/battle/scroll_draw_trainer_pic.asm new file mode 100644 index 00000000..18df86e0 --- /dev/null +++ b/engine/battle/scroll_draw_trainer_pic.asm @@ -0,0 +1,50 @@ +_ScrollTrainerPicAfterBattle: ; 396d3 (e:56d3) +; Load the enemy trainer's pic and scrolls it into +; the screen from the right. + xor a + ld [wEnemyMonSpecies2], a + ld b, $1 + call GoPAL_SET + callab _LoadTrainerPic + hlCoord 19, 0 + ld c, $0 +.scrollLoop + inc c + ld a, c + cp 7 + ret z + ld d, $0 + push bc + push hl +.drawTrainerPicLoop + call DrawTrainerPicColumn + inc hl + ld a, 7 + add d + ld d, a + dec c + jr nz, .drawTrainerPicLoop + ld c, 4 + call DelayFrames + pop hl + pop bc + dec hl + jr .scrollLoop + +; write one 7-tile column of the trainer pic to the tilemap +DrawTrainerPicColumn: ; 39707 (e:5707) + push hl + push de + push bc + ld e, 7 +.loop + ld [hl], d + ld bc, SCREEN_WIDTH + add hl, bc + inc d + dec e + jr nz, .loop + pop bc + pop de + pop hl + ret diff --git a/engine/battle/trainer_party_ai_misc.asm b/engine/battle/trainer_party_ai_misc.asm new file mode 100644 index 00000000..8cbb9329 --- /dev/null +++ b/engine/battle/trainer_party_ai_misc.asm @@ -0,0 +1,1263 @@ +; creates a set of moves that may be used and returns its address in hl +; unused slots are filled with 0, all used slots may be chosen with equal probability +AIEnemyTrainerChooseMoves: ; 39719 (e:5719) + ld a, $a + ld hl, wHPBarMaxHP ; init temporary move selection array. Only the moves with the lowest numbers are chosen in the end + ld [hli], a ; move 1 + ld [hli], a ; move 2 + ld [hli], a ; move 3 + ld [hl], a ; move 4 + ld a, [W_ENEMYDISABLEDMOVE] ; forbid disabled move (if any) + swap a + and $f + jr z, .noMoveDisabled + ld hl, wHPBarMaxHP + dec a + ld c, a + ld b, $0 + add hl, bc ; advance pointer to forbidden move + ld [hl], $50 ; forbid (highly discourage) disabled move +.noMoveDisabled + ld hl, TrainerClassMoveChoiceModifications ; 589B + ld a, [W_TRAINERCLASS] + ld b, a +.loopTrainerClasses + dec b + jr z, .readTrainerClassData +.loopTrainerClassData + ld a, [hli] + and a + jr nz, .loopTrainerClassData + jr .loopTrainerClasses +.readTrainerClassData + ld a, [hl] + and a + jp z, .useOriginalMoveSet + push hl +.nextMoveChoiceModification + pop hl + ld a, [hli] + and a + jr z, .loopFindMinimumEntries + push hl + ld hl, AIMoveChoiceModificationFunctionPointers ; $57a3 + dec a + add a + ld c, a + ld b, $0 + add hl, bc ; skip to pointer + ld a, [hli] ; read pointer into hl + ld h, [hl] + ld l, a + ld de, .nextMoveChoiceModification ; set return address + push de + jp [hl] ; execute modification function +.loopFindMinimumEntries ; all entries will be decremented sequentially until one of them is zero + ld hl, wHPBarMaxHP ; temp move selection array + ld de, wEnemyMonMoves ; enemy moves + ld c, $4 +.loopDecrementEntries + ld a, [de] + inc de + and a + jr z, .loopFindMinimumEntries + dec [hl] + jr z, .minimumEntriesFound + inc hl + dec c + jr z, .loopFindMinimumEntries + jr .loopDecrementEntries +.minimumEntriesFound + ld a, c +.loopUndoPartialIteration ; undo last (partial) loop iteration + inc [hl] + dec hl + inc a + cp $5 + jr nz, .loopUndoPartialIteration + ld hl, wHPBarMaxHP ; temp move selection array + ld de, wEnemyMonMoves ; enemy moves + ld c, $4 +.filterMinimalEntries ; all minimal entries now have value 1. All other slots will be disabled (move set to 0) + ld a, [de] + and a + jr nz, .moveExisting ; 0x3978a $1 + ld [hl], a +.moveExisting + ld a, [hl] + dec a + jr z, .slotWithMinimalValue + xor a + ld [hli], a ; disable move slot + jr .next +.slotWithMinimalValue + ld a, [de] + ld [hli], a ; enable move slot +.next + inc de + dec c + jr nz, .filterMinimalEntries + ld hl, wHPBarMaxHP ; use created temporary array as move set + ret +.useOriginalMoveSet + ld hl, wEnemyMonMoves ; use original move set + ret + +AIMoveChoiceModificationFunctionPointers: ; 397a3 (e:57a3) + dw AIMoveChoiceModification1 + dw AIMoveChoiceModification2 + dw AIMoveChoiceModification3 + dw AIMoveChoiceModification4 ; unused, does nothing + +; discourages moves that cause no damage but only a status ailment if player's mon already has one +AIMoveChoiceModification1: ; 397ab (e:57ab) + ld a, [wBattleMonStatus] + and a + ret z ; return if no status ailment on player's mon + ld hl, wBuffer - 1 ; temp move selection array (-1 byte offest) + ld de, wEnemyMonMoves ; enemy moves + ld b, NUM_MOVES + 1 +.nextMove + dec b + ret z ; processed all 4 moves + inc hl + ld a, [de] + and a + ret z ; no more moves in move set + inc de + call ReadMove + ld a, [W_ENEMYMOVEPOWER] + and a + jr nz, .nextMove + ld a, [W_ENEMYMOVEEFFECT] + push hl + push de + push bc + ld hl, StatusAilmentMoveEffects + ld de, $0001 + call IsInArray + pop bc + pop de + pop hl + jr nc, .nextMove + ld a, [hl] + add $5 ; heavily discourage move + ld [hl], a + jr .nextMove + +StatusAilmentMoveEffects ; 57e2 + db $01 ; unused sleep effect + db SLEEP_EFFECT + db POISON_EFFECT + db PARALYZE_EFFECT + db $FF + +; slightly encourage moves with specific effects. +; in particular, stat-modifying moves and other move effects +; that fall in-bewteen +AIMoveChoiceModification2: ; 397e7 (e:57e7) + ld a, [wAILayer2Encouragement] + cp $1 + ret nz + ld hl, wBuffer - 1 ; temp move selection array (-1 byte offset) + ld de, wEnemyMonMoves ; enemy moves + ld b, NUM_MOVES + 1 +.nextMove + dec b + ret z ; processed all 4 moves + inc hl + ld a, [de] + and a + ret z ; no more moves in move set + inc de + call ReadMove + ld a, [W_ENEMYMOVEEFFECT] + cp ATTACK_UP1_EFFECT + jr c, .nextMove + cp BIDE_EFFECT + jr c, .preferMove + cp ATTACK_UP2_EFFECT + jr c, .nextMove + cp POISON_EFFECT + jr c, .preferMove + jr .nextMove +.preferMove + dec [hl] ; sligthly encourage this move + jr .nextMove + +; encourages moves that are effective against the player's mon (even if non-damaging). +; discourage damaging moves that are ineffective or not very effective against the player's mon, +; unless there's no damaging move that deals at least neutral damage +AIMoveChoiceModification3: ; 39817 (e:5817) + ld hl, wBuffer - 1 ; temp move selection array (-1 byte offset) + ld de, wEnemyMonMoves ; enemy moves + ld b, $5 +.nextMove + dec b + ret z ; processed all 4 moves + inc hl + ld a, [de] + and a + ret z ; no more moves in move set + inc de + call ReadMove + push hl + push bc + push de + callab AIGetTypeEffectiveness + pop de + pop bc + pop hl + ld a, [wd11e] + cp $10 + jr z, .nextMove + jr c, .notEffectiveMove + dec [hl] ; sligthly encourage this move + jr .nextMove +.notEffectiveMove ; discourages non-effective moves if better moves are available + push hl + push de + push bc + ld a, [W_ENEMYMOVETYPE] + ld d, a + ld hl, wEnemyMonMoves ; enemy moves + ld b, NUM_MOVES + 1 + ld c, $0 +.loopMoves + dec b + jr z, .done + ld a, [hli] + and a + jr z, .done + call ReadMove + ld a, [W_ENEMYMOVEEFFECT] + cp SUPER_FANG_EFFECT + jr z, .betterMoveFound ; Super Fang is considered to be a better move + cp SPECIAL_DAMAGE_EFFECT + jr z, .betterMoveFound ; any special damage moves are considered to be better moves + cp FLY_EFFECT + jr z, .betterMoveFound ; Fly is considered to be a better move + ld a, [W_ENEMYMOVETYPE] + cp d + jr z, .loopMoves + ld a, [W_ENEMYMOVEPOWER] + and a + jr nz, .betterMoveFound ; damaging moves of a different type are considered to be better moves + jr .loopMoves +.betterMoveFound + ld c, a +.done + ld a, c + pop bc + pop de + pop hl + and a + jr z, .nextMove + inc [hl] ; sligthly discourage this move + jr .nextMove +AIMoveChoiceModification4: ; 39883 (e:5883) + ret + +ReadMove: ; 39884 (e:5884) + push hl + push de + push bc + dec a + ld hl,Moves + ld bc,6 + call AddNTimes + ld de,W_ENEMYMOVENUM + call CopyData + pop bc + pop de + pop hl + ret + +; move choice modification methods that are applied for each trainer class +; 0 is sentinel value +TrainerClassMoveChoiceModifications: ; 3989b (e:589b) + db 0 ; YOUNGSTER + db 1,0 ; BUG CATCHER + db 1,0 ; LASS + db 1,3,0 ; SAILOR + db 1,0 ; JR__TRAINER_M + db 1,0 ; JR__TRAINER_F + db 1,2,3,0; POKEMANIAC + db 1,2,0 ; SUPER_NERD + db 1,0 ; HIKER + db 1,0 ; BIKER + db 1,3,0 ; BURGLAR + db 1,0 ; ENGINEER + db 1,2,0 ; JUGGLER_X + db 1,3,0 ; FISHER + db 1,3,0 ; SWIMMER + db 0 ; CUE_BALL + db 1,0 ; GAMBLER + db 1,3,0 ; BEAUTY + db 1,2,0 ; PSYCHIC_TR + db 1,3,0 ; ROCKER + db 1,0 ; JUGGLER + db 1,0 ; TAMER + db 1,0 ; BIRD_KEEPER + db 1,0 ; BLACKBELT + db 1,0 ; SONY1 + db 1,3,0 ; PROF_OAK + db 1,2,0 ; CHIEF + db 1,2,0 ; SCIENTIST + db 1,3,0 ; GIOVANNI + db 1,0 ; ROCKET + db 1,3,0 ; COOLTRAINER_M + db 1,3,0 ; COOLTRAINER_F + db 1,0 ; BRUNO + db 1,0 ; BROCK + db 1,3,0 ; MISTY + db 1,3,0 ; LT__SURGE + db 1,3,0 ; ERIKA + db 1,3,0 ; KOGA + db 1,3,0 ; BLAINE + db 1,3,0 ; SABRINA + db 1,2,0 ; GENTLEMAN + db 1,3,0 ; SONY2 + db 1,3,0 ; SONY3 + db 1,2,3,0; LORELEI + db 1,0 ; CHANNELER + db 1,0 ; AGATHA + db 1,3,0 ; LANCE + +TrainerPicAndMoneyPointers: ; 39914 (e:5914) +; trainer pic pointers and base money. +; money received after battle = base money × level of highest-level enemy mon + dw YoungsterPic + money 1500 + + dw BugCatcherPic + money 1000 + + dw LassPic + money 1500 + + dw SailorPic + money 3000 + + dw JrTrainerMPic + money 2000 + + dw JrTrainerFPic + money 2000 + + dw PokemaniacPic + money 5000 + + dw SuperNerdPic + money 2500 + + dw HikerPic + money 3500 + + dw BikerPic + money 2000 + + dw BurglarPic + money 9000 + + dw EngineerPic + money 5000 + + dw JugglerPic + money 3500 + + dw FisherPic + money 3500 + + dw SwimmerPic + money 500 + + dw CueBallPic + money 2500 + + dw GamblerPic + money 7000 + + dw BeautyPic + money 7000 + + dw PsychicPic + money 1000 + + dw RockerPic + money 2500 + + dw JugglerPic + money 3500 + + dw TamerPic + money 4000 + + dw BirdKeeperPic + money 2500 + + dw BlackbeltPic + money 2500 + + dw Rival1Pic + money 3500 + + dw ProfOakPic + money 9900 + + dw ChiefPic + money 3000 + + dw ScientistPic + money 5000 + + dw GiovanniPic + money 9900 + + dw RocketPic + money 3000 + + dw CooltrainerMPic + money 3500 + + dw CooltrainerFPic + money 3500 + + dw BrunoPic + money 9900 + + dw BrockPic + money 9900 + + dw MistyPic + money 9900 + + dw LtSurgePic + money 9900 + + dw ErikaPic + money 9900 + + dw KogaPic + money 9900 + + dw BlainePic + money 9900 + + dw SabrinaPic + money 9900 + + dw GentlemanPic + money 7000 + + dw Rival2Pic + money 6500 + + dw Rival3Pic + money 9900 + + dw LoreleiPic + money 9900 + + dw ChannelerPic + money 3000 + + dw AgathaPic + money 9900 + + dw LancePic + money 9900 + +INCLUDE "text/trainer_names.asm" + +; formats a string at wMovesString that lists the moves at wMoves +FormatMovesString: ; 39b87 (e:5b87) + ld hl, wMoves + ld de, wMovesString + ld b, $0 +.printMoveNameLoop + ld a, [hli] + and a ; end of move list? + jr z, .printDashLoop ; print dashes when no moves are left + push hl + ld [wd0b5], a + ld a, BANK(MoveNames) + ld [wPredefBank], a + ld a, MOVE_NAME + ld [wNameListType], a + call GetName + ld hl, wcd6d +.copyNameLoop + ld a, [hli] + cp $50 + jr z, .doneCopyingName + ld [de], a + inc de + jr .copyNameLoop +.doneCopyingName + ld a, b + ld [wcd6c], a + inc b + ld a, $4e ; line break + ld [de], a + inc de + pop hl + ld a, b + cp NUM_MOVES + jr z, .done + jr .printMoveNameLoop +.printDashLoop + ld a, "-" + ld [de], a + inc de + inc b + ld a, b + cp NUM_MOVES + jr z, .done + ld a, $4e ; line break + ld [de], a + inc de + jr .printDashLoop +.done + ld a, "@" + ld [de], a + ret + +; XXX this is called in a few places, but it doesn't appear to do anything useful +Func_39bd5: ; 39bd5 (e:5bd5) + ld a, [wd11b] + cp $1 + jr nz, .asm_39be6 + ld hl, wEnemyPartyCount + ld de, wEnemyMonOT + ld a, ENEMYOT_NAME + jr .asm_39c18 +.asm_39be6 + cp $4 + jr nz, .calcAttackStat4 + ld hl, wPartyCount + ld de, wPartyMonOT + ld a, PLAYEROT_NAME + jr .asm_39c18 +.calcAttackStat4 + cp $5 + jr nz, .asm_39c02 + ld hl, wStringBuffer2 + 11 + ld de, MonsterNames + ld a, MONSTER_NAME + jr .asm_39c18 +.asm_39c02 + cp $2 + jr nz, .asm_39c10 + ld hl, wNumBagItems + ld de, ItemNames + ld a, ITEM_NAME + jr .asm_39c18 +.asm_39c10 + ld hl, wStringBuffer2 + 11 + ld de, ItemNames + ld a, ITEM_NAME +.asm_39c18 + ld [wNameListType], a + ld a, l + ld [wList], a + ld a, h + ld [wList + 1], a + ld a, e + ld [wcf8d], a + ld a, d + ld [wcf8e], a + ld bc, ItemPrices + ld a, c + ld [wItemPrices], a + ld a, b + ld [wItemPrices + 1], a + ret + +; get species of mon e in list [wcc49] for LoadMonData +GetMonSpecies: ; 39c37 (e:5c37) + ld hl, wPartySpecies + ld a, [wcc49] + and a + jr z, .getSpecies + dec a + jr z, .enemyParty + ld hl, wBoxSpecies + jr .getSpecies +.enemyParty + ld hl, wEnemyPartyMons +.getSpecies + ld d, 0 + add hl, de + ld a, [hl] + ld [wcf91], a + ret + +ReadTrainer: ; 39c53 (e:5c53) + +; don't change any moves in a link battle + ld a,[wLinkState] + and a + ret nz + +; set [wEnemyPartyCount] to 0, [wEnemyPartyMons] to FF +; XXX first is total enemy pokemon? +; XXX second is species of first pokemon? + ld hl,wEnemyPartyCount + xor a + ld [hli],a + dec a + ld [hl],a + +; get the pointer to trainer data for this class + ld a,[W_CUROPPONENT] + sub $C9 ; convert value from pokemon to trainer + add a,a + ld hl,TrainerDataPointers + ld c,a + ld b,0 + add hl,bc ; hl points to trainer class + ld a,[hli] + ld h,[hl] + ld l,a + ld a,[W_TRAINERNO] + ld b,a +; At this point b contains the trainer number, +; and hl points to the trainer class. +; Our next task is to iterate through the trainers, +; decrementing b each time, until we get to the right one. +.outer + dec b + jr z,.IterateTrainer +.inner + ld a,[hli] + and a + jr nz,.inner + jr .outer + +; if the first byte of trainer data is FF, +; - each pokemon has a specific level +; (as opposed to the whole team being of the same level) +; - if [W_LONEATTACKNO] != 0, one pokemon on the team has a special move +; else the first byte is the level of every pokemon on the team +.IterateTrainer + ld a,[hli] + cp $FF ; is the trainer special? + jr z,.SpecialTrainer ; if so, check for special moves + ld [W_CURENEMYLVL],a +.LoopTrainerData + ld a,[hli] + and a ; have we reached the end of the trainer data? + jr z,.FinishUp + ld [wcf91],a ; write species somewhere (XXX why?) + ld a,1 + ld [wcc49],a + push hl + call AddPartyMon + pop hl + jr .LoopTrainerData +.SpecialTrainer +; if this code is being run: +; - each pokemon has a specific level +; (as opposed to the whole team being of the same level) +; - if [W_LONEATTACKNO] != 0, one pokemon on the team has a special move + ld a,[hli] + and a ; have we reached the end of the trainer data? + jr z,.AddLoneMove + ld [W_CURENEMYLVL],a + ld a,[hli] + ld [wcf91],a + ld a,1 + ld [wcc49],a + push hl + call AddPartyMon + pop hl + jr .SpecialTrainer +.AddLoneMove +; does the trainer have a single monster with a different move + ld a,[W_LONEATTACKNO] ; Brock is 01, Misty is 02, Erika is 04, etc + and a + jr z,.AddTeamMove + dec a + add a,a + ld c,a + ld b,0 + ld hl,LoneMoves + add hl,bc + ld a,[hli] + ld d,[hl] + ld hl,wEnemyMon1Moves + 2 + ld bc,wEnemyMon2 - wEnemyMon1 + call AddNTimes + ld [hl],d + jr .FinishUp +.AddTeamMove +; check if our trainer's team has special moves + +; get trainer class number + ld a,[W_CUROPPONENT] + sub $C8 + ld b,a + ld hl,TeamMoves + +; iterate through entries in TeamMoves, checking each for our trainer class +.IterateTeamMoves + ld a,[hli] + cp b + jr z,.GiveTeamMoves ; is there a match? + inc hl ; if not, go to the next entry + inc a + jr nz,.IterateTeamMoves + + ; no matches found. is this trainer champion rival? + ld a,b + cp SONY3 + jr z,.ChampionRival + jr .FinishUp ; nope +.GiveTeamMoves + ld a,[hl] + ld [wEnemyMon5Moves + 2],a + jr .FinishUp +.ChampionRival ; give moves to his team + +; pidgeot + ld a,SKY_ATTACK + ld [wEnemyMon1Moves + 2],a + +; starter + ld a,[W_RIVALSTARTER] + cp STARTER3 + ld b,MEGA_DRAIN + jr z,.GiveStarterMove + cp STARTER1 + ld b,FIRE_BLAST + jr z,.GiveStarterMove + ld b,BLIZZARD ; must be squirtle +.GiveStarterMove + ld a,b + ld [wEnemyMon6Moves + 2],a +.FinishUp ; XXX this needs documenting + xor a ; clear D079-D07B + ld de,wd079 + ld [de],a + inc de + ld [de],a + inc de + ld [de],a + ld a,[W_CURENEMYLVL] + ld b,a +.LastLoop + ld hl,wd047 + ld c,2 + push bc + predef AddBCDPredef + pop bc + inc de + inc de + dec b + jr nz,.LastLoop + ret + +INCLUDE "data/trainer_moves.asm" + +INCLUDE "data/trainer_parties.asm" + +TrainerAI: ; 3a52e (e:652e) +;XXX called at 34964, 3c342, 3c398 + and a + ld a,[W_ISINBATTLE] + dec a + ret z ; if not a trainer, we're done here + ld a,[wLinkState] + cp LINK_STATE_BATTLING + ret z + ld a,[W_TRAINERCLASS] ; what trainer class is this? + dec a + ld c,a + ld b,0 + ld hl,TrainerAIPointers + add hl,bc + add hl,bc + add hl,bc + ld a,[wAICount] + and a + ret z ; if no AI uses left, we're done here + inc hl + inc a + jr nz,.getpointer + dec hl + ld a,[hli] + ld [wAICount],a +.getpointer + ld a,[hli] + ld h,[hl] + ld l,a + call Random + jp [hl] + +TrainerAIPointers: ; 3a55c (e:655c) +; one entry per trainer class +; first byte, number of times (per Pokémon) it can occur +; next two bytes, pointer to AI subroutine for trainer class + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,JugglerAI ; juggler_x + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,JugglerAI ; juggler + dbw 3,GenericAI + dbw 3,GenericAI + dbw 2,BlackbeltAI ; blackbelt + dbw 3,GenericAI + dbw 3,GenericAI + dbw 1,GenericAI ; chief + dbw 3,GenericAI + dbw 1,GiovanniAI ; giovanni + dbw 3,GenericAI + dbw 2,CooltrainerMAI ; cooltrainerm + dbw 1,CooltrainerFAI ; cooltrainerf + dbw 2,BrunoAI ; bruno + dbw 5,BrockAI ; brock + dbw 1,MistyAI ; misty + dbw 1,LtSurgeAI ; surge + dbw 1,ErikaAI ; erika + dbw 2,KogaAI ; koga + dbw 2,BlaineAI ; blaine + dbw 1,SabrinaAI ; sabrina + dbw 3,GenericAI + dbw 1,Sony2AI ; sony2 + dbw 1,Sony3AI ; sony3 + dbw 2,LoreleiAI ; lorelei + dbw 3,GenericAI + dbw 2,AgathaAI ; agatha + dbw 1,LanceAI ; lance + +JugglerAI: ; 3a5e9 (e:65e9) + cp $40 + ret nc + jp AISwitchIfEnoughMons + +BlackbeltAI: ; 3a5ef (e:65ef) + cp $20 + ret nc + jp AIUseXAttack + +GiovanniAI: ; 3a5f5 (e:65f5) + cp $40 + ret nc + jp AIUseGuardSpec + +CooltrainerMAI: ; 3a5fb (e:65fb) + cp $40 + ret nc + jp AIUseXAttack + +CooltrainerFAI: ; 3a601 (e:6601) + cp $40 + ld a,$A + call AICheckIfHPBelowFraction + jp c,AIUseHyperPotion + ld a,5 + call AICheckIfHPBelowFraction + ret nc + jp AISwitchIfEnoughMons + +BrockAI: ; 3a614 (e:6614) +; if his active monster has a status condition, use a full heal + ld a,[wEnemyMonStatus] + and a + ret z + jp AIUseFullHeal + +MistyAI: ; 3a61c (e:661c) + cp $40 + ret nc + jp AIUseXDefend + +LtSurgeAI: ; 3a622 (e:6622) + cp $40 + ret nc + jp AIUseXSpeed + +ErikaAI: ; 3a628 (e:6628) + cp $80 + ret nc + ld a,$A + call AICheckIfHPBelowFraction + ret nc + jp AIUseSuperPotion + +KogaAI: ; 3a634 (e:6634) + cp $40 + ret nc + jp AIUseXAttack + +BlaineAI: ; 3a63a (e:663a) + cp $40 + ret nc + jp AIUseSuperPotion + +SabrinaAI: ; 3a640 (e:6640) + cp $40 + ret nc + ld a,$A + call AICheckIfHPBelowFraction + ret nc + jp AIUseHyperPotion + +Sony2AI: ; 3a64c (e:664c) + cp $20 + ret nc + ld a,5 + call AICheckIfHPBelowFraction + ret nc + jp AIUsePotion + +Sony3AI: ; 3a658 (e:6658) + cp $20 + ret nc + ld a,5 + call AICheckIfHPBelowFraction + ret nc + jp AIUseFullRestore + +LoreleiAI: ; 3a664 (e:6664) + cp $80 + ret nc + ld a,5 + call AICheckIfHPBelowFraction + ret nc + jp AIUseSuperPotion + +BrunoAI: ; 3a670 (e:6670) + cp $40 + ret nc + jp AIUseXDefend + +AgathaAI: ; 3a676 (e:6676) + cp $14 + jp c,AISwitchIfEnoughMons + cp $80 + ret nc + ld a,4 + call AICheckIfHPBelowFraction + ret nc + jp AIUseSuperPotion + +LanceAI: ; 3a687 (e:6687) + cp $80 + ret nc + ld a,5 + call AICheckIfHPBelowFraction + ret nc + jp AIUseHyperPotion + +GenericAI: ; 3a693 (e:6693) + and a ; clear carry + ret + +; end of individual trainer AI routines + +DecrementAICount: ; 3a695 (e:6695) + ld hl,wAICount + dec [hl] + scf + ret + +Func_3a69b: ; 3a69b (e:669b) + ld a,(SFX_08_3e - SFX_Headers_08) / 3 + jp PlaySoundWaitForCurrent + +AIUseFullRestore: ; 3a6a0 (e:66a0) + call AICureStatus + ld a,FULL_RESTORE + ld [wcf05],a + ld de,wHPBarOldHP + ld hl,wEnemyMonHP + 1 + ld a,[hld] + ld [de],a + inc de + ld a,[hl] + ld [de],a + inc de + ld hl,wEnemyMonMaxHP + 1 + ld a,[hld] + ld [de],a + inc de + ld [wHPBarMaxHP],a + ld [wEnemyMonHP + 1],a + ld a,[hl] + ld [de],a + ld [wHPBarMaxHP+1],a + ld [wEnemyMonHP],a + jr AIPrintItemUseAndUpdateHPBar + +AIUsePotion: ; 3a6ca (e:66ca) +; enemy trainer heals his monster with a potion + ld a,POTION + ld b,20 + jr AIRecoverHP + +AIUseSuperPotion: ; 3a6d0 (e:66d0) +; enemy trainer heals his monster with a super potion + ld a,SUPER_POTION + ld b,50 + jr AIRecoverHP + +AIUseHyperPotion: ; 3a6d6 (e:66d6) +; enemy trainer heals his monster with a hyper potion + ld a,HYPER_POTION + ld b,200 + ; fallthrough + +AIRecoverHP: ; 3a6da (e:66da) +; heal b HP and print "trainer used $(a) on pokemon!" + ld [wcf05],a + ld hl,wEnemyMonHP + 1 + ld a,[hl] + ld [wHPBarOldHP],a + add b + ld [hld],a + ld [wHPBarNewHP],a + ld a,[hl] + ld [wHPBarOldHP+1],a + ld [wHPBarNewHP+1],a + jr nc,.next + inc a + ld [hl],a + ld [wHPBarNewHP+1],a +.next + inc hl + ld a,[hld] + ld b,a + ld de,wEnemyMonMaxHP + 1 + ld a,[de] + dec de + ld [wHPBarMaxHP],a + sub b + ld a,[hli] + ld b,a + ld a,[de] + ld [wHPBarMaxHP+1],a + sbc b + jr nc,AIPrintItemUseAndUpdateHPBar + inc de + ld a,[de] + dec de + ld [hld],a + ld [wHPBarNewHP],a + ld a,[de] + ld [hl],a + ld [wHPBarNewHP+1],a + ; fallthrough + +AIPrintItemUseAndUpdateHPBar: ; 3a718 (e:6718) + call AIPrintItemUse_ + hlCoord 2, 2 + xor a + ld [wHPBarType],a + predef UpdateHPBar2 + jp DecrementAICount + +AISwitchIfEnoughMons: ; 3a72a (e:672a) +; enemy trainer switches if there are 3 or more unfainted mons in party + ld a,[wEnemyPartyCount] + ld c,a + ld hl,wEnemyMon1HP + + ld d,0 ; keep count of unfainted monsters + + ; count how many monsters haven't fainted yet +.loop + ld a,[hli] + ld b,a + ld a,[hld] + or b + jr z,.Fainted ; has monster fainted? + inc d +.Fainted + push bc + ld bc,$2C + add hl,bc + pop bc + dec c + jr nz,.loop + + ld a,d ; how many available monsters are there? + cp 2 ; don't bother if only 1 or 2 + jp nc,SwitchEnemyMon + and a + ret + +SwitchEnemyMon: ; 3a74b (e:674b) + +; prepare to withdraw the active monster: copy hp, number, and status to roster + + ld a,[wEnemyMonPartyPos] + ld hl,wEnemyMon1HP + ld bc,wEnemyMon2 - wEnemyMon1 + call AddNTimes + ld d,h + ld e,l + ld hl,wEnemyMonHP + ld bc,4 + call CopyData + + ld hl, AIBattleWithdrawText + call PrintText + + ld a,1 + ld [wd11d],a + callab EnemySendOut + xor a + ld [wd11d],a + + ld a,[wLinkState] + cp LINK_STATE_BATTLING + ret z + scf + ret + +AIBattleWithdrawText: ; 3a781 (e:6781) + TX_FAR _AIBattleWithdrawText + db "@" + +AIUseFullHeal: ; 3a786 (e:6786) + call Func_3a69b + call AICureStatus + ld a,FULL_HEAL + jp AIPrintItemUse + +AICureStatus: ; 3a791 (e:6791) +; cures the status of enemy's active pokemon + ld a,[wEnemyMonPartyPos] + ld hl,wEnemyMon1Status + ld bc,wEnemyMon2 - wEnemyMon1 + call AddNTimes + xor a + ld [hl],a ; clear status in enemy team roster + ld [wEnemyMonStatus],a ; clear status of active enemy + ld hl,W_ENEMYBATTSTATUS3 + res 0,[hl] + ret + +AIUseXAccuracy: ; 0x3a7a8 unused + call Func_3a69b + ld hl,W_ENEMYBATTSTATUS2 + set 0,[hl] + ld a,X_ACCURACY + jp AIPrintItemUse + +AIUseGuardSpec: ; 3a7b5 (e:67b5) + call Func_3a69b + ld hl,W_ENEMYBATTSTATUS2 + set 1,[hl] + ld a,GUARD_SPEC_ + jp AIPrintItemUse + +AIUseDireHit: ; 0x3a7c2 unused + call Func_3a69b + ld hl,W_ENEMYBATTSTATUS2 + set 2,[hl] + ld a,DIRE_HIT + jp AIPrintItemUse + +AICheckIfHPBelowFraction: ; 3a7cf (e:67cf) +; return carry if enemy trainer's current HP is below 1 / a of the maximum + ld [H_DIVISOR],a + ld hl,wEnemyMonMaxHP + ld a,[hli] + ld [H_DIVIDEND],a + ld a,[hl] + ld [H_DIVIDEND + 1],a + ld b,2 + call Divide + ld a,[H_QUOTIENT + 3] + ld c,a + ld a,[H_QUOTIENT + 2] + ld b,a + ld hl,wEnemyMonHP + 1 + ld a,[hld] + ld e,a + ld a,[hl] + ld d,a + ld a,d + sub b + ret nz + ld a,e + sub c + ret + +AIUseXAttack: ; 3a7f2 (e:67f2) + ld b,$A + ld a,X_ATTACK + jr AIIncreaseStat + +AIUseXDefend: ; 3a7f8 (e:67f8) + ld b,$B + ld a,X_DEFEND + jr AIIncreaseStat + +AIUseXSpeed: ; 3a7fe (e:67fe) + ld b,$C + ld a,X_SPEED + jr AIIncreaseStat + +AIUseXSpecial: ; 3a804 (e:6804) + ld b,$D + ld a,X_SPECIAL + ; fallthrough + +AIIncreaseStat: ; 3a808 (e:6808) + ld [wcf05],a + push bc + call AIPrintItemUse_ + pop bc + ld hl,W_ENEMYMOVEEFFECT + ld a,[hld] + push af + ld a,[hl] + push af + push hl + ld a,$AF + ld [hli],a + ld [hl],b + callab StatModifierUpEffect + pop hl + pop af + ld [hli],a + pop af + ld [hl],a + jp DecrementAICount + +AIPrintItemUse: ; 3a82c (e:682c) + ld [wcf05],a + call AIPrintItemUse_ + jp DecrementAICount + +AIPrintItemUse_: ; 3a835 (e:6835) +; print "x used [wcf05] on z!" + ld a,[wcf05] + ld [wd11e],a + call GetItemName + ld hl, AIBattleUseItemText + jp PrintText + +AIBattleUseItemText: ; 3a844 (e:6844) + TX_FAR _AIBattleUseItemText + db "@" diff --git a/engine/battle/unused_stats_functions.asm b/engine/battle/unused_stats_functions.asm new file mode 100644 index 00000000..23ddbc20 --- /dev/null +++ b/engine/battle/unused_stats_functions.asm @@ -0,0 +1,62 @@ +; does nothing since no stats are ever selected (barring glitches) +DoubleSelectedStats: ; 39680 (e:5680) + ld a, [H_WHOSETURN] + and a + ld a, [wPlayerStatsToDouble] + ld hl, wBattleMonAttack + 1 + jr z, .notEnemyTurn + ld a, [wEnemyStatsToDouble] + ld hl, wEnemyMonAttack + 1 +.notEnemyTurn + ld c, 4 + ld b, a +.loop + srl b + call c, .doubleStat + inc hl + inc hl + dec c + ret z + jr .loop + +.doubleStat + ld a, [hl] + add a + ld [hld], a + ld a, [hl] + rl a + ld [hli], a + ret + +; does nothing since no stats are ever selected (barring glitches) +HalveSelectedStats: ; 396a7 (e:56a7) + ld a, [H_WHOSETURN] + and a + ld a, [wPlayerStatsToHalve] + ld hl, wBattleMonAttack + jr z, .notEnemyTurn + ld a, [wEnemyStatsToHalve] + ld hl, wEnemyMonAttack +.notEnemyTurn + ld c, 4 + ld b, a +.loop + srl b + call c, .halveStat + inc hl + inc hl + dec c + ret z + jr .loop + +.halveStat + ld a, [hl] + srl a + ld [hli], a + rr [hl] + or [hl] + jr nz, .nonzeroStat + ld [hl], 1 +.nonzeroStat + dec hl + ret diff --git a/main.asm b/main.asm index 838c4c39..9cc8b91f 100755 --- a/main.asm +++ b/main.asm @@ -5463,7 +5463,10 @@ SECTION "bankE",ROMX,BANK[$E] INCLUDE "data/moves.asm" BaseStats: INCLUDE "data/base_stats.asm" INCLUDE "data/cries.asm" -INCLUDE "engine/battle/e.asm" +INCLUDE "engine/battle/unused_stats_functions.asm" +INCLUDE "engine/battle/scroll_draw_trainer_pic.asm" +INCLUDE "engine/battle/trainer_party_ai_misc.asm" +INCLUDE "engine/battle/draw_hud_pokeball_gfx.asm" TradingAnimationGraphics: INCBIN "gfx/game_boy.norepeat.2bpp" @@ -5474,7 +5477,9 @@ TradingAnimationGraphics2: INCBIN "gfx/trade2.2bpp" INCLUDE "engine/evos_moves.asm" -INCLUDE "engine/battle/e_2.asm" +INCLUDE "engine/battle/moveEffects/heal_effect.asm" +INCLUDE "engine/battle/moveEffects/transform_effect.asm" +INCLUDE "engine/battle/moveEffects/reflect_light_screen_effect.asm" SECTION "bankF",ROMX,BANK[$F] @@ -5947,7 +5952,8 @@ INCLUDE "scripts/mansion4.asm" INCLUDE "data/mapObjects/mansion4.asm" Mansion4Blocks: INCBIN "maps/mansion4.blk" -INCLUDE "engine/battle/14.asm" +INCLUDE "engine/battle/init_battle_variables.asm" +INCLUDE "engine/battle/moveEffects/paralyze_effect.asm" INCLUDE "engine/overworld/card_key.asm" -- cgit v1.3.1-sl0p From 10211cc461b35140c815e18e95f7070eb0dcc586 Mon Sep 17 00:00:00 2001 From: xCrystal Date: Wed, 1 Apr 2015 17:03:05 +0200 Subject: Rename battle files and split move effects Part 5 15.asm, 16.asm, 1a.asm, 1c.asm --- engine/battle/15.asm | 372 -------------- engine/battle/16.asm | 238 --------- engine/battle/1a.asm | 43 -- engine/battle/1c.asm | 905 ----------------------------------- engine/battle/battle_transitions.asm | 815 +++++++++++++++++++++++++++++++ engine/battle/common_text.asm | 238 +++++++++ engine/battle/decrement_pp.asm | 43 ++ engine/battle/experience.asm | 372 ++++++++++++++ engine/battle/ghost_marowak_anim.asm | 89 ++++ main.asm | 9 +- 10 files changed, 1562 insertions(+), 1562 deletions(-) delete mode 100755 engine/battle/15.asm delete mode 100755 engine/battle/16.asm delete mode 100755 engine/battle/1a.asm delete mode 100755 engine/battle/1c.asm create mode 100644 engine/battle/battle_transitions.asm create mode 100644 engine/battle/common_text.asm create mode 100644 engine/battle/decrement_pp.asm create mode 100644 engine/battle/experience.asm create mode 100644 engine/battle/ghost_marowak_anim.asm (limited to 'main.asm') diff --git a/engine/battle/15.asm b/engine/battle/15.asm deleted file mode 100755 index 9bd67654..00000000 --- a/engine/battle/15.asm +++ /dev/null @@ -1,372 +0,0 @@ -GainExperience: ; 5524f (15:524f) - ld a, [wLinkState] - cp LINK_STATE_BATTLING - ret z ; return if link battle - call DivideExpDataByNumMonsGainingExp - ld hl, wPartyMon1 - xor a - ld [wWhichPokemon], a -.partyMonLoop ; loop over each mon and add gained exp - inc hl - ld a, [hli] - or [hl] ; is mon's HP 0? - jp z, .nextMon ; if so, go to next mon - push hl - ld hl, wPartyGainExpFlags - ld a, [wWhichPokemon] - ld c, a - ld b, $2 - predef FlagActionPredef - ld a, c - and a ; is mon's gain exp flag set? - pop hl - jp z, .nextMon ; if mon's gain exp flag not set, go to next mon - ld de, (wPartyMon1HPExp + 1) - (wPartyMon1HP + 1) - add hl, de - ld d, h - ld e, l - ld hl, wEnemyMonBaseStats - ld c, $5 -.gainStatExpLoop - ld a, [hli] - ld b, a ; enemy mon base stat - ld a, [de] ; stat exp - add b ; add enemy mon base state to stat exp - ld [de], a - jr nc, .nextBaseStat -; if there was a carry, increment the upper byte - dec de - ld a, [de] - inc a - jr z, .maxStatExp ; jump if the value overflowed - ld [de], a - inc de - jr .nextBaseStat -.maxStatExp ; if the upper byte also overflowed, then we have hit the max stat exp - ld a, $ff - ld [de], a - inc de - ld [de], a -.nextBaseStat - dec c - jr z, .asm_552a1 - inc de - inc de - jr .gainStatExpLoop -.asm_552a1 - xor a - ld [H_MULTIPLICAND], a - ld [H_MULTIPLICAND + 1], a - ld a, [wEnemyMonBaseExp] - ld [H_MULTIPLICAND + 2], a - ld a, [wEnemyMonLevel] - ld [H_MULTIPLIER], a - call Multiply - ld a, 7 - ld [H_DIVISOR], a - ld b, 4 - call Divide - ld hl, -((wPartyMon1HPExp + 1) - wPartyMon1OTID + 4 * 2) - add hl, de - ld b, [hl] ; party mon OTID - inc hl - ld a, [wPlayerID] - cp b - jr nz, .tradedMon - ld b, [hl] - ld a, [wPlayerID + 1] - cp b - ld a, $0 - jr z, .next -.tradedMon - call BoostExp ; traded mon exp boost - ld a, $1 -.next - ld [wGainBoostedExp], a - ld a, [W_ISINBATTLE] - dec a ; is it a trainer battle? - call nz, BoostExp ; if so, boost exp - inc hl - inc hl - inc hl -; add the gained exp to the party mon's exp - ld b, [hl] - ld a, [H_QUOTIENT + 3] - ld [wcf4c], a - add b - ld [hld], a - ld b, [hl] - ld a, [H_QUOTIENT + 2] - ld [wcf4b], a - adc b - ld [hl], a - jr nc, .noCarry - dec hl - inc [hl] - inc hl -.noCarry -; calculate exp for the mon at max level, and cap the exp at that value - inc hl - push hl - ld a, [wWhichPokemon] - ld c, a - ld b, 0 - ld hl, wPartySpecies - add hl, bc - ld a, [hl] ; species - ld [wd0b5], a - call GetMonHeader - ld d, MAX_LEVEL - callab CalcExperience ; get max exp -; compare max exp with current exp - ld a, [$ff96] - ld b, a - ld a, [$ff97] - ld c, a - ld a, [$ff98] - ld d, a - pop hl - ld a, [hld] - sub d - ld a, [hld] - sbc c - ld a, [hl] - sbc b - jr c, .next2 -; the mon's exp is greater than the max exp, so overwrite it with the max exp - ld a, b - ld [hli], a - ld a, c - ld [hli], a - ld a, d - ld [hld], a - dec hl -.next2 - push hl - ld a, [wWhichPokemon] - ld hl, wPartyMonNicks - call GetPartyMonName - ld hl, GainedText - call PrintText - xor a ; party mon data - ld [wcc49], a - call LoadMonData - pop hl - ld bc, wPartyMon1Level - wPartyMon1Exp - add hl, bc - push hl - callba CalcLevelFromExperience - pop hl - ld a, [hl] ; current level - cp d - jp z, .nextMon ; if level didn't change, go to next mon - ld a, [W_CURENEMYLVL] - push af - push hl - ld a, d - ld [W_CURENEMYLVL], a - ld [hl], a - ld bc, wPartyMon1Species - wPartyMon1Level - add hl, bc - ld a, [hl] ; species - ld [wd0b5], a - ld [wd11e], a - call GetMonHeader - ld bc, (wPartyMon1MaxHP + 1) - wPartyMon1Species - add hl, bc - push hl - ld a, [hld] - ld c, a - ld b, [hl] - push bc ; push max HP (from before levelling up) - ld d, h - ld e, l - ld bc, (wPartyMon1HPExp - 1) - wPartyMon1MaxHP - add hl, bc - ld b, $1 ; consider stat exp when calculating stats - call CalcStats - pop bc ; pop max HP (from before levelling up) - pop hl - ld a, [hld] - sub c - ld c, a - ld a, [hl] - sbc b - ld b, a ; bc = difference between old max HP and new max HP after levelling - ld de, (wPartyMon1HP + 1) - wPartyMon1MaxHP - add hl, de -; add to the current HP the amount of max HP gained when levelling - ld a, [hl] ; wPartyMon1HP + 1 - add c - ld [hld], a - ld a, [hl] ; wPartyMon1HP + 1 - adc b - ld [hl], a ; wPartyMon1HP - ld a, [wPlayerMonNumber] - ld b, a - ld a, [wWhichPokemon] - cp b ; is the current mon in battle? - jr nz, .printGrewLevelText -; current mon is in battle - ld de, wBattleMonHP -; copy party mon HP to battle mon HP - ld a, [hli] - ld [de], a - inc de - ld a, [hl] - ld [de], a -; copy other stats from party mon to battle mon - ld bc, wPartyMon1Level - (wPartyMon1HP + 1) - add hl, bc - push hl - ld de, wBattleMonLevel - ld bc, $b ; size of stats - call CopyData - pop hl - ld a, [W_PLAYERBATTSTATUS3] - bit 3, a ; is the mon transformed? - jr nz, .recalcStatChanges -; the mon is not transformed, so update the unmodified stats - ld de, wPlayerMonUnmodifiedLevel - ld bc, $b - call CopyData -.recalcStatChanges - xor a - ld [wd11e], a - callab CalculateModifiedStats - callab ApplyBurnAndParalysisPenaltiesToPlayer - callab ApplyBadgeStatBoosts - callab DrawPlayerHUDAndHPBar - callab PrintEmptyString - call SaveScreenTilesToBuffer1 -.printGrewLevelText - ld hl, GrewLevelText - call PrintText - xor a ; party mon data - ld [wcc49], a - call LoadMonData - ld d, $1 - callab PrintStatsBox - call WaitForTextScrollButtonPress - call LoadScreenTilesFromBuffer1 - xor a - ld [wcc49], a - ld a, [wd0b5] - ld [wd11e], a - predef LearnMoveFromLevelUp - ld hl, wccd3 - ld a, [wWhichPokemon] - ld c, a - ld b, $1 - predef FlagActionPredef - pop hl - pop af - ld [W_CURENEMYLVL], a - -.nextMon - ld a, [wPartyCount] - ld b, a - ld a, [wWhichPokemon] - inc a - cp b - jr z, .done - ld [wWhichPokemon], a - ld bc, wPartyMon2 - wPartyMon1 - ld hl, wPartyMon1 - call AddNTimes - jp .partyMonLoop -.done - ld hl, wPartyGainExpFlags - xor a - ld [hl], a ; clear gain exp flags - ld a, [wPlayerMonNumber] - ld c, a - ld b, $1 - push bc - predef FlagActionPredef ; set the gain exp flag for the mon that is currently out - ld hl, wPartyFoughtCurrentEnemyFlags - xor a - ld [hl], a - pop bc - predef_jump FlagActionPredef ; set the fought current enemy flag for the mon that is currently out - -; divide enemy base stats, catch rate, and base exp by the number of mons gaining exp -DivideExpDataByNumMonsGainingExp: ; 5546c (15:546c) - ld a, [wPartyGainExpFlags] - ld b, a - xor a - ld c, $8 - ld d, $0 -.countSetBitsLoop ; loop to count set bits in wPartyGainExpFlags - xor a - srl b - adc d - ld d, a - dec c - jr nz, .countSetBitsLoop - cp $2 - ret c ; return if only one mon is gaining exp - ld [wd11e], a ; store number of mons gaining exp - ld hl, wEnemyMonBaseStats - ld c, $7 -.divideLoop - xor a - ld [H_DIVIDEND], a - ld a, [hl] - ld [H_DIVIDEND + 1], a - ld a, [wd11e] - ld [H_DIVISOR], a - ld b, $2 - call Divide ; divide value by number of mons gaining exp - ld a, [H_QUOTIENT + 3] - ld [hli], a - dec c - jr nz, .divideLoop - ret - -; multiplies exp by 1.5 -BoostExp: ; 5549f (15:549f) - ld a, [H_QUOTIENT + 2] - ld b, a - ld a, [H_QUOTIENT + 3] - ld c, a - srl b - rr c - add c - ld [H_QUOTIENT + 3], a - ld a, [H_QUOTIENT + 2] - adc b - ld [H_QUOTIENT + 2], a - ret - -GainedText: ; 554b2 (15:54b2) - TX_FAR _GainedText - db $08 ; asm - ld a, [wBoostExpByExpAll] - ld hl, WithExpAllText - and a - ret nz - ld hl, ExpPointsText - ld a, [wGainBoostedExp] - and a - ret z - ld hl, BoostedText - ret - -WithExpAllText: ; 554cb (15:54cb) - TX_FAR _WithExpAllText - db $08 ; asm - ld hl, ExpPointsText - ret - -BoostedText: ; 554d4 (15:54d4) - TX_FAR _BoostedText - -ExpPointsText: ; 554d8 (15:54d8) - TX_FAR _ExpPointsText - db "@" - -GrewLevelText: ; 554dd (15:54dd) - TX_FAR _GrewLevelText - db $0b - db "@" diff --git a/engine/battle/16.asm b/engine/battle/16.asm deleted file mode 100755 index 9a00bd98..00000000 --- a/engine/battle/16.asm +++ /dev/null @@ -1,238 +0,0 @@ -PrintBeginningBattleText: ; 58d99 (16:4d99) - ld a, [W_ISINBATTLE] ; W_ISINBATTLE - dec a - jr nz, .trainerBattle - ld a, [W_CURMAP] ; W_CURMAP - cp POKEMONTOWER_3 - jr c, .notPokemonTower - cp LAVENDER_HOUSE_1 - jr c, .pokemonTower -.notPokemonTower - ld a, [wEnemyMonSpecies2] - call PlayCry - ld hl, WildMonAppearedText - ld a, [W_MOVEMISSED] ; W_MOVEMISSED - and a - jr z, .notFishing - ld hl, HookedMonAttackedText -.notFishing - jr .wildBattle -.trainerBattle - call .playSFX - ld c, $14 - call DelayFrames - ld hl, TrainerWantsToFightText -.wildBattle - push hl - callab DrawAllPokeballs - pop hl - call PrintText - jr .done -.pokemonTower - ld b, SILPH_SCOPE - call IsItemInBag - ld a, [wEnemyMonSpecies2] - ld [wcf91], a - cp MAROWAK - jr z, .isMarowak - ld a, b - and a - jr z, .noSilphScope - callab LoadEnemyMonData - jr .notPokemonTower -.noSilphScope - ld hl, EnemyAppearedText - call PrintText - ld hl, GhostCantBeIDdText - call PrintText - jr .done -.isMarowak - ld a, b - and a - jr z, .noSilphScope - ld hl, EnemyAppearedText - call PrintText - ld hl, UnveiledGhostText - call PrintText - callab LoadEnemyMonData - callab MarowakAnim - ld hl, WildMonAppearedText - call PrintText - -.playSFX - xor a - ld [wc0f1], a - ld a, $80 - ld [wc0f2], a - ld a, (SFX_08_77 - SFX_Headers_08) / 3 - call PlaySound - jp WaitForSoundToFinish -.done - ret - -WildMonAppearedText: ; 58e3b (16:4e3b) - TX_FAR _WildMonAppearedText - db "@" - -HookedMonAttackedText: ; 58e40 (16:4e40) - TX_FAR _HookedMonAttackedText - db "@" - -EnemyAppearedText: ; 58e45 (16:4e45) - TX_FAR _EnemyAppearedText - db "@" - -TrainerWantsToFightText: ; 58e4a (16:4e4a) - TX_FAR _TrainerWantsToFightText - db "@" - -UnveiledGhostText: ; 58e4f (16:4e4f) - TX_FAR _UnveiledGhostText - db "@" - -GhostCantBeIDdText: ; 58e54 (16:4e54) - TX_FAR _GhostCantBeIDdText - db "@" - -PrintSendOutMonMessage: ; 58e59 (16:4e59) - ld hl, wEnemyMonHP - ld a, [hli] - or [hl] - ld hl, GoText - jr z, .printText - xor a - ld [H_MULTIPLICAND], a - ld hl, wEnemyMonHP - ld a, [hli] - ld [wcce3], a - ld [H_MULTIPLICAND + 1], a - ld a, [hl] - ld [wcce4], a - ld [H_MULTIPLICAND + 2], a - ld a, 25 - ld [H_MULTIPLIER], a - call Multiply - ld hl, wEnemyMonMaxHP - ld a, [hli] - ld b, [hl] - srl a - rr b - srl a - rr b - ld a, b - ld b, $4 - ld [H_DIVISOR], a ; enemy mon max HP divided by 4 - call Divide - ld a, [H_QUOTIENT + 3] ; a = (enemy mon current HP * 25) / (enemy max HP / 4); this approximates the current percentage of max HP - ld hl, GoText ; 70% or greater - cp 70 - jr nc, .printText - ld hl, DoItText ; 40% - 69% - cp 40 - jr nc, .printText - ld hl, GetmText ; 10% - 39% - cp 10 - jr nc, .printText - ld hl, EnemysWeakText ; 0% - 9% -.printText - jp PrintText - -GoText: ; 58eae (16:4eae) - TX_FAR _GoText - db $08 ; asm - jr PrintPlayerMon1Text - -DoItText: ; 58eb5 (16:4eb5) - TX_FAR _DoItText - db $08 ; asm - jr PrintPlayerMon1Text - -GetmText: ; 58ebc (16:4ebc) - TX_FAR _GetmText - db $08 ; asm - jr PrintPlayerMon1Text - -EnemysWeakText: ; 58ec3 (16:4ec3) - TX_FAR _EnemysWeakText - db $08 ; asm - -PrintPlayerMon1Text: - ld hl, PlayerMon1Text - ret - -PlayerMon1Text: ; 58ecc (16:4ecc) - TX_FAR _PlayerMon1Text - db "@" - -RetreatMon: ; 58ed1 (16:4ed1) - ld hl, PlayerMon2Text - jp PrintText - -PlayerMon2Text: ; 58ed7 (16:4ed7) - TX_FAR _PlayerMon2Text - db $08 ; asm - push de - push bc - ld hl, wEnemyMonHP + 1 - ld de, wcce4 - ld b, [hl] - dec hl - ld a, [de] - sub b - ld [$ff98], a - dec de - ld b, [hl] - ld a, [de] - sbc b - ld [$ff97], a - ld a, $19 - ld [H_POWEROFTEN], a - call Multiply - ld hl, wEnemyMonMaxHP - ld a, [hli] - ld b, [hl] - srl a - rr b - srl a - rr b - ld a, b - ld b, $4 - ld [H_POWEROFTEN], a - call Divide - pop bc - pop de - ld a, [$ff98] - ld hl, EnoughText - and a - ret z - ld hl, ComeBackText - cp $1e - ret c - ld hl, OKExclamationText - cp $46 - ret c - ld hl, GoodText - ret - -EnoughText: ; 58f25 (16:4f25) - TX_FAR _EnoughText - db $08 ; asm - jr PrintComeBackText - -OKExclamationText: ; 58f2c (16:4f2c) - TX_FAR _OKExclamationText - db $08 ; asm - jr PrintComeBackText - -GoodText: ; 58f33 (16:4f33) - TX_FAR _GoodText - db $08 ; asm - jr PrintComeBackText - -PrintComeBackText: ; 58f3a (16:4f3a) - ld hl, ComeBackText - ret - -ComeBackText: ; 58f3e (16:4f3e) - TX_FAR _ComeBackText - db "@" diff --git a/engine/battle/1a.asm b/engine/battle/1a.asm deleted file mode 100755 index ecf5040b..00000000 --- a/engine/battle/1a.asm +++ /dev/null @@ -1,43 +0,0 @@ -DecrementPP: ; 68000 (1a:4000) -; after using a move, decrement pp in battle and (if not transformed?) in party - ld a, [de] - cp a, STRUGGLE - ret z ; if the pokemon is using "struggle", there's nothing to do - ; we don't decrement PP for "struggle" - ld hl, W_PLAYERBATTSTATUS1 - ld a, [hli] ; load the W_PLAYERBATTSTATUS1 pokemon status flags and increment hl to load the - ; W_PLAYERBATTSTATUS2 status flags later - and a, (1 << StoringEnergy) | (1 << ThrashingAbout) | (1 << AttackingMultipleTimes) - ret nz ; if any of these statuses are true, don't decrement PP - bit UsingRage, [hl] - ret nz ; don't decrement PP either if Pokemon is using Rage - ld hl, wBattleMonPP ; PP of first move (in battle) - -; decrement PP in the battle struct - call .DecrementPP - -; decrement PP in the party struct - ld a, [W_PLAYERBATTSTATUS3] - bit Transformed, a - ret nz ; Return if transformed. Pokemon Red stores the "current pokemon's" PP - ; separately from the "Pokemon in your party's" PP. This is - ; duplication -- in all cases *other* than Pokemon with Transform. - ; Normally, this means we have to go on and make the same - ; modification to the "party's pokemon" PP that we made to the - ; "current pokemon's" PP. But, if we're dealing with a Transformed - ; Pokemon, it has separate PP for the move set that it copied from - ; its opponent, which is *not* the same as its real PP as part of your - ; party. So we return, and don't do that part. - - ld hl, wPartyMon1PP ; PP of first move (in party) - ld a, [wPlayerMonNumber] ; which mon in party is active - ld bc, wPartyMon2 - wPartyMon1 - call AddNTimes ; calculate address of the mon to modify -.DecrementPP - ld a, [wPlayerMoveListIndex] ; which move (0, 1, 2, 3) did we use? - ld c, a - ld b, 0 - add hl ,bc ; calculate the address in memory of the PP we need to decrement - ; based on the move chosen. - dec [hl] ; Decrement PP - ret diff --git a/engine/battle/1c.asm b/engine/battle/1c.asm deleted file mode 100755 index ce0296f7..00000000 --- a/engine/battle/1c.asm +++ /dev/null @@ -1,905 +0,0 @@ -MarowakAnim: ; 708ca (1c:48ca) -; animate the ghost being unveiled as a Marowak - ld a, $e4 - ld [rOBP1], a - call CopyMonPicFromBGToSpriteVRAM ; cover the BG ghost pic with a sprite ghost pic that looks the same -; now that the ghost pic is being displayed using sprites, clear the ghost pic from the BG tilemap - hlCoord 12, 0 - ld bc, $707 - call ClearScreenArea - call Delay3 - xor a - ld [H_AUTOBGTRANSFERENABLED], a ; disable BG transfer so we don't see the Marowak too soon -; replace ghost pic with Marowak in BG - ld a, MAROWAK - ld [wHPBarMaxHP], a - ld a, $1 - ld [H_WHOSETURN], a - callab Func_79793 - ; alternate between black and light grey 8 times. - ; this makes the ghost's body appear to flash - ld d, $80 - call FlashSprite8Times -.fadeOutGhostLoop - ld c, 10 - call DelayFrames - ld a, [rOBP1] - sla a - sla a - ld [rOBP1], a - jr nz, .fadeOutGhostLoop - call ClearSprites - call CopyMonPicFromBGToSpriteVRAM ; copy Marowak pic from BG to sprite VRAM - ld b, $e4 -.fadeInMarowakLoop - ld c, 10 - call DelayFrames - ld a, [rOBP1] - srl b - rra - srl b - rra - ld [rOBP1], a - ld a, b - and a - jr nz, .fadeInMarowakLoop - ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a ; enable BG transfer so the BG Marowak pic will be visible after the sprite one is cleared - call Delay3 - jp ClearSprites - -; copies a mon pic's from background VRAM to sprite VRAM and sets up OAM -CopyMonPicFromBGToSpriteVRAM: ; 7092a (1c:492a) - ld de, vFrontPic - ld hl, vSprites - ld bc, 7 * 7 - call CopyVideoData - ld a, $10 - ld [W_BASECOORDY], a - ld a, $70 - ld [W_BASECOORDX], a - ld hl, wOAMBuffer - ld bc, $606 - ld d, $8 -.oamLoop - push bc - ld a, [W_BASECOORDY] - ld e, a -.oamInnerLoop - ld a, e - add $8 - ld e, a - ld [hli], a - ld a, [W_BASECOORDX] - ld [hli], a - ld a, d - ld [hli], a - ld a, $10 ; use OBP1 - ld [hli], a - inc d - dec c - jr nz, .oamInnerLoop - inc d - ld a, [W_BASECOORDX] - add $8 - ld [W_BASECOORDX], a - pop bc - dec b - jr nz, .oamLoop - ret - -BattleTransition: ; 7096d (1c:496d) - ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a - call Delay3 - xor a - ld [hWY], a - dec a - ld [wUpdateSpritesEnabled], a - call DelayFrame - ld hl, wSpriteStateData1 + 2 - ld a, [H_DOWNARROWBLINKCNT2] - ld c, a - ld b, $0 - ld de, $10 -.loop1 - ld a, [hl] - cp $ff - jr z, .skip1 - inc b -.skip1 - add hl, de - dec c - jr nz, .loop1 - ld hl, wOAMBuffer + $10 - ld c, $9 -.loop2 - ld a, b - swap a - cp l - jr z, .skip2 - push hl - push bc - ld bc, $10 - xor a - call FillMemory - pop bc - pop hl -.skip2 - ld de, $10 - add hl, de - dec c - jr nz, .loop2 - call Delay3 - call LoadBattleTransitionTile - ld bc, $0 - ld a, [wLinkState] - cp LINK_STATE_BATTLING - jr z, .linkBattle - call GetBattleTransitionID_WildOrTrainer - call GetBattleTransitionID_CompareLevels - call GetBattleTransitionID_IsDungeonMap -.linkBattle - ld hl, BattleTransitions - add hl, bc - add hl, bc - ld a, [hli] - ld h, [hl] - ld l, a - jp [hl] - -; the three GetBattleTransitionID functions set the first -; three bits of c, which determines what transition animation -; to play at the beginning of a battle -; bit 0: set if trainer battle -; bit 1: set if enemy is at least 3 levels higher than player -; bit 2: set if dungeon map -BattleTransitions: ; 709d2 (1c:49d2) - dw BattleTransition_DoubleCircle ; %000 - dw BattleTransition_Spiral ; %001 - dw BattleTransition_Circle ; %010 - dw BattleTransition_Spiral ; %011 - dw BattleTransition_HorizontalStripes ; %100 - dw BattleTransition_Shrink ; %101 - dw BattleTransition_VerticalStripes ; %110 - dw BattleTransition_Split ; %111 - -GetBattleTransitionID_WildOrTrainer: ; 709e2 (1c:49e2) - ld a, [W_CUROPPONENT] - cp $c8 - jr nc, .trainer - res 0, c - ret -.trainer - set 0, c - ret - -GetBattleTransitionID_CompareLevels: ; 709ef (1c:49ef) - ld hl, wPartyMon1HP -.faintedLoop - ld a, [hli] - or [hl] - jr nz, .notFainted - ld de, wPartyMon2 - (wPartyMon1 + 1) - add hl, de - jr .faintedLoop -.notFainted - ld de, wPartyMon1Level - (wPartyMon1HP + 1) - add hl, de - ld a, [hl] - add $3 - ld e, a - ld a, [W_CURENEMYLVL] - sub e - jr nc, .highLevelEnemy - res 1, c - ld a, $1 - ld [wcd47], a - ret -.highLevelEnemy - set 1, c - xor a - ld [wcd47], a - ret - -; fails to recognize VICTORY_ROAD_2, VICTORY_ROAD_3, all ROCKET_HIDEOUT maps, -; MANSION_1, SEAFOAM_ISLANDS_[2-5], POWER_PLANT, DIGLETTS_CAVE -; and SILPH_CO_[9-11]F as dungeon maps -GetBattleTransitionID_IsDungeonMap: ; 70a19 (1c:4a19) - ld a, [W_CURMAP] - ld e, a - ld hl, DungeonMaps1 -.loop1 - ld a, [hli] - cp $ff - jr z, .noMatch1 - cp e - jr nz, .loop1 -.match - set 2, c - ret -.noMatch1 - ld hl, DungeonMaps2 -.loop2 - ld a, [hli] - cp $ff - jr z, .noMatch2 - ld d, a - ld a, [hli] - cp e - jr c, .loop2 - ld a, e - cp d - jr nc, .match -.noMatch2 - res 2, c - ret - -; GetBattleTransitionID_IsDungeonMap checks if W_CURMAP -; is equal to one of these maps -DungeonMaps1: ; 70a3f (1c:4a3f) - db VIRIDIAN_FOREST - db ROCK_TUNNEL_1 - db SEAFOAM_ISLANDS_1 - db ROCK_TUNNEL_2 - db $FF - -; GetBattleTransitionID_IsDungeonMap checks if W_CURMAP -; is in between or equal to each pair of maps -DungeonMaps2: ; 70a44 (1c:4a44) - ; all MT_MOON maps - db MT_MOON_1 - db MT_MOON_3 - - ; all SS_ANNE maps, VICTORY_ROAD_1, LANCES_ROOM, and HALL_OF_FAME - db SS_ANNE_1 - db HALL_OF_FAME - - ; all POKEMONTOWER maps and Lavender Town buildings - db LAVENDER_POKECENTER - db LAVENDER_HOUSE_2 - - ; SILPH_CO_[2-8]F, MANSION[2-4], SAFARI_ZONE, and UNKNOWN_DUNGEON maps, - ; except for SILPH_CO_1F - db SILPH_CO_2F - db UNKNOWN_DUNGEON_1 - db $FF - -LoadBattleTransitionTile: ; 70a4d (1c:4a4d) - ld hl, vChars1 + $7f0 - ld de, BattleTransitionTile - ld bc, (BANK(BattleTransitionTile) << 8) + $01 - jp CopyVideoData - -BattleTransitionTile: ; 70a59 (1c:4a59) - INCBIN "gfx/battle_transition.2bpp" - -BattleTransition_BlackScreen: ; 70a69 (1c:4a69) - ld a, $ff - ld [rBGP], a - ld [rOBP0], a - ld [rOBP1], a - ret - -; for non-dungeon trainer battles -; called regardless of mon levels, but does an -; outward spiral if enemy is at least 3 levels -; higher than player and does an inward spiral otherwise -BattleTransition_Spiral: ; 70a72 (1c:4a72) - ld a, [wcd47] - and a - jr z, .outwardSpiral - call BattleTransition_InwardSpiral - jr .done -.outwardSpiral - hlCoord 10, 10 - ld a, $3 - ld [wd09f], a - ld a, l - ld [wd09b], a - ld a, h - ld [wd09a], a - ld b, $78 -.loop1 - ld c, $3 -.loop2 - push bc - call BattleTransition_OutwardSpiral_ - pop bc - dec c - jr nz, .loop2 - call DelayFrame - dec b - jr nz, .loop1 -.done - call BattleTransition_BlackScreen - xor a - ld [wd09b], a - ld [wd09a], a - ret - -BattleTransition_InwardSpiral: ; 70aaa (1c:4aaa) - ld a, $7 - ld [wWhichTrade], a - ld hl, wTileMap - ld c, $11 - ld de, $14 - call BattleTransition_InwardSpiral_ - inc c - jr .skip -.loop - ld de, $14 - call BattleTransition_InwardSpiral_ -.skip - inc c - ld de, $1 - call BattleTransition_InwardSpiral_ - dec c - dec c - ld de, $ffec - call BattleTransition_InwardSpiral_ - inc c - ld de, rIE - call BattleTransition_InwardSpiral_ - dec c - dec c - ld a, c - and a - jr nz, .loop - ret - -BattleTransition_InwardSpiral_: ; 70ae0 (1c:4ae0) - push bc -.loop - ld [hl], $ff - add hl, de - push bc - ld a, [wWhichTrade] - dec a - jr nz, .skip - call BattleTransition_TransferDelay3 - ld a, $7 -.skip - ld [wWhichTrade], a - pop bc - dec c - jr nz, .loop - pop bc - ret - -BattleTransition_OutwardSpiral_: ; 70af9 (1c:4af9) - ld bc, $ffec - ld de, $14 - ld a, [wd09b] - ld l, a - ld a, [wd09a] - ld h, a - ld a, [wd09f] - cp $0 - jr z, .zero - cp $1 - jr z, .one - cp $2 - jr z, .two - cp $3 - jr z, .three -.done1 - ld [hl], $ff -.done2_ - ld a, l - ld [wd09b], a - ld a, h - ld [wd09a], a - ret -.zero - dec hl - ld a, [hl] - cp $ff - jr nz, .done2 - inc hl - add hl, bc - jr .done1 -.one - add hl, de - ld a, [hl] - cp $ff - jr nz, .done2 - add hl, bc - dec hl - jr .done1 -.two - inc hl - ld a, [hl] - cp $ff - jr nz, .done2 - dec hl - add hl, de - jr .done1 -.three - add hl, bc - ld a, [hl] - cp $ff - jr nz, .done2 - add hl, de - inc hl - jr .done1 -.done2 - ld [hl], $ff - ld a, [wd09f] - inc a - cp $4 - jr nz, .skip - xor a -.skip - ld [wd09f], a - jr .done2_ - -FlashScreen: -BattleTransition_FlashScreen_: ; 70b5d (1c:4b5d) - ld hl, BattleTransition_FlashScreenPalettes -.loop - ld a, [hli] - cp $1 - jr z, .done - ld [rBGP], a - ld c, $2 - call DelayFrames - jr .loop -.done - dec b - jr nz, BattleTransition_FlashScreen_ - ret - -BattleTransition_FlashScreenPalettes: ; 70b72 (1c:4b72) - db $F9,$FE,$FF,$FE,$F9,$E4,$90,$40,$00,$40,$90,$E4 - db $01 ; terminator - -; used for low level trainer dungeon battles -BattleTransition_Shrink: ; 70b7f (1c:4b7f) - ld c, $9 -.loop - push bc - xor a - ld [H_AUTOBGTRANSFERENABLED], a - hlCoord 0, 7 - deCoord 0, 8 - ld bc, $ffd8 - call BattleTransition_CopyTiles1 - hlCoord 0, 10 - deCoord 0, 9 - ld bc, $28 - call BattleTransition_CopyTiles1 - hlCoord 8, 0 - deCoord 9, 0 - ld bc, $fffe - call BattleTransition_CopyTiles2 - hlCoord 11, 0 - deCoord 10, 0 - ld bc, $2 - call BattleTransition_CopyTiles2 - ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a - ld c, $6 - call DelayFrames - pop bc - dec c - jr nz, .loop - call BattleTransition_BlackScreen - ld c, $a - jp DelayFrames - -; used for high level trainer dungeon battles -BattleTransition_Split: ; 70bca (1c:4bca) - ld c, $9 - xor a - ld [H_AUTOBGTRANSFERENABLED], a -.loop - push bc - hlCoord 0, 16 - deCoord 0, 17 - ld bc, $ffd8 - call BattleTransition_CopyTiles1 - hlCoord 0, 1 - ld de, wTileMap - ld bc, $28 - call BattleTransition_CopyTiles1 - hlCoord 18, 0 - deCoord 19, 0 - ld bc, $fffe - call BattleTransition_CopyTiles2 - hlCoord 1, 0 - ld de, wTileMap - ld bc, $2 - call BattleTransition_CopyTiles2 - call BattleTransition_TransferDelay3 - call Delay3 - pop bc - dec c - jr nz, .loop - call BattleTransition_BlackScreen - ld c, $a - jp DelayFrames - -BattleTransition_CopyTiles1: ; 70c12 (1c:4c12) - ld a, c - ld [wWhichTrade], a - ld a, b - ld [wTrainerEngageDistance], a - ld c, $8 -.loop1 - push bc - push hl - push de - ld bc, $14 - call CopyData - pop hl - pop de - ld a, [wWhichTrade] - ld c, a - ld a, [wTrainerEngageDistance] - ld b, a - add hl, bc - pop bc - dec c - jr nz, .loop1 - ld l, e - ld h, d - ld a, $ff - ld c, $14 -.loop2 - ld [hli], a - dec c - jr nz, .loop2 - ret - -BattleTransition_CopyTiles2: ; 70c3f (1c:4c3f) - ld a, c - ld [wWhichTrade], a - ld a, b - ld [wTrainerEngageDistance], a - ld c, $9 -.loop1 - push bc - push hl - push de - ld c, $12 -.loop2 - ld a, [hl] - ld [de], a - ld a, e - add $14 - jr nc, .noCarry1 - inc d -.noCarry1 - ld e, a - ld a, l - add $14 - jr nc, .noCarry2 - inc h -.noCarry2 - ld l, a - dec c - jr nz, .loop2 - pop hl - pop de - ld a, [wWhichTrade] - ld c, a - ld a, [wTrainerEngageDistance] - ld b, a - add hl, bc - pop bc - dec c - jr nz, .loop1 - ld l, e - ld h, d - ld de, $14 - ld c, $12 -.loop3 - ld [hl], $ff - add hl, de - dec c - jr nz, .loop3 - ret - -; used for high level wild dungeon battles -BattleTransition_VerticalStripes: ; 70c7e (1c:4c7e) - ld c, $12 - ld hl, wTileMap - deCoord 1, 17 - xor a - ld [H_AUTOBGTRANSFERENABLED], a -.loop - push bc - push hl - push de - push de - call BattleTransition_VerticalStripes_ - pop hl - call BattleTransition_VerticalStripes_ - call BattleTransition_TransferDelay3 - pop hl - ld bc, $ffec - add hl, bc - ld e, l - ld d, h - pop hl - ld bc, $14 - add hl, bc - pop bc - dec c - jr nz, .loop - jp BattleTransition_BlackScreen - -BattleTransition_VerticalStripes_: ; 70caa (1c:4caa) - ld c, $a -.loop - ld [hl], $ff - inc hl - inc hl - dec c - jr nz, .loop - ret - -; used for low level wild dungeon battles -BattleTransition_HorizontalStripes: ; 70cb4 (1c:4cb4) - ld c, $14 - ld hl, wTileMap - deCoord 19, 1 - xor a - ld [H_AUTOBGTRANSFERENABLED], a -.loop - push bc - push hl - push de - push de - call BattleTransition_HorizontalStripes_ - pop hl - call BattleTransition_HorizontalStripes_ - call BattleTransition_TransferDelay3 - pop de - pop hl - pop bc - inc hl - dec de - dec c - jr nz, .loop - jp BattleTransition_BlackScreen - -BattleTransition_HorizontalStripes_: ; 70cd8 (1c:4cd8) - ld c, $9 - ld de, $28 -.loop - ld [hl], $ff - add hl, de - dec c - jr nz, .loop - ret - -; used for high level wild non-dungeon battles -; makes one full circle around the screen -; by animating each half circle one at a time -BattleTransition_Circle: ; 70ce4 (1c:4ce4) - call BattleTransition_FlashScreen - ld bc, $000a - ld hl, BattleTransition_HalfCircle1 - call BattleTransition_Circle_Sub1 - ld c, $a - ld b, $1 - ld hl, BattleTransition_HalfCircle2 - call BattleTransition_Circle_Sub1 - jp BattleTransition_BlackScreen - -BattleTransition_FlashScreen: ; 70cfd (1c:4cfd) - ld b, $3 - call BattleTransition_FlashScreen_ - xor a - ld [H_AUTOBGTRANSFERENABLED], a - ret - -BattleTransition_Circle_Sub1: ; 70d06 (1c:4d06) - push bc - push hl - ld a, b - call BattleTransition_Circle_Sub2 - pop hl - ld bc, $0005 - add hl, bc - call BattleTransition_TransferDelay3 - pop bc - dec c - jr nz, BattleTransition_Circle_Sub1 - ret - -BattleTransition_TransferDelay3: ; 70d19 (1c:4d19) - ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a - call Delay3 - xor a - ld [H_AUTOBGTRANSFERENABLED], a - ret - -; used for low level wild non-dungeon battles -; makes two half circles around the screen -; by animating both half circles at the same time -BattleTransition_DoubleCircle: ; 70d24 (1c:4d24) - call BattleTransition_FlashScreen - ld c, $a - ld hl, BattleTransition_HalfCircle1 - ld de, BattleTransition_HalfCircle2 -.loop - push bc - push hl - push de - push de - xor a - call BattleTransition_Circle_Sub2 - pop hl - ld a, $1 - call BattleTransition_Circle_Sub2 - pop hl - ld bc, $5 - add hl, bc - ld e, l - ld d, h - pop hl - add hl, bc - call BattleTransition_TransferDelay3 - pop bc - dec c - jr nz, .loop - jp BattleTransition_BlackScreen - -BattleTransition_Circle_Sub2: ; 70d50 (1c:4d50) - ld [wWhichTrade], a - ld a, [hli] - ld [wTrainerEngageDistance], a - ld a, [hli] - ld e, a - ld a, [hli] - ld d, a - ld a, [hli] - ld h, [hl] - ld l, a - jp BattleTransition_Circle_Sub3 - -BattleTransition_HalfCircle1: ; 70d61 (1c:4d61) - db $01 - dw BattleTransition_CircleData1 - dwCoord 18, 6 - - db $01 - dw BattleTransition_CircleData2 - dwCoord 19, 3 - - db $01 - dw BattleTransition_CircleData3 - dwCoord 18, 0 - - db $01 - dw BattleTransition_CircleData4 - dwCoord 14, 0 - - db $01 - dw BattleTransition_CircleData5 - dwCoord 10, 0 - - db $00 - dw BattleTransition_CircleData5 - dwCoord 9, 0 - - db $00 - dw BattleTransition_CircleData4 - dwCoord 5, 0 - - db $00 - dw BattleTransition_CircleData3 - dwCoord 1, 0 - - db $00 - dw BattleTransition_CircleData2 - dwCoord 0, 3 - - db $00 - dw BattleTransition_CircleData1 - dwCoord 1, 6 - -BattleTransition_HalfCircle2: ; 70d93 (1c:4d93) - db $00 - dw BattleTransition_CircleData1 - dwCoord 1, 11 - - db $00 - dw BattleTransition_CircleData2 - dwCoord 0, 14 - - db $00 - dw BattleTransition_CircleData3 - dwCoord 1, 17 - - db $00 - dw BattleTransition_CircleData4 - dwCoord 5, 17 - - db $00 - dw BattleTransition_CircleData5 - dwCoord 9, 17 - - db $01 - dw BattleTransition_CircleData5 - dwCoord 10, 17 - - db $01 - dw BattleTransition_CircleData4 - dwCoord 14, 17 - - db $01 - dw BattleTransition_CircleData3 - dwCoord 18, 17 - - db $01 - dw BattleTransition_CircleData2 - dwCoord 19, 14 - - db $01 - dw BattleTransition_CircleData1 - dwCoord 18, 11 - -BattleTransition_Circle_Sub3: ; 70dc5 (1c:4dc5) - push hl - ld a, [de] - ld c, a - inc de -.loop1 - ld [hl], $ff - ld a, [wTrainerEngageDistance] - and a - jr z, .skip1 - inc hl - jr .skip2 -.skip1 - dec hl -.skip2 - dec c - jr nz, .loop1 - pop hl - ld a, [wWhichTrade] - and a - ld bc, $14 - jr z, .skip3 - ld bc, $ffec -.skip3 - add hl, bc - ld a, [de] - inc de - cp $ff - ret z - and a - jr z, BattleTransition_Circle_Sub3 - ld c, a -.loop2 - ld a, [wTrainerEngageDistance] - and a - jr z, .skip4 - dec hl - jr .skip5 -.skip4 - inc hl -.skip5 - dec c - jr nz, .loop2 - jr BattleTransition_Circle_Sub3 - -BattleTransition_CircleData1: ; 70dfe (1c:4dfe) - db $02,$03,$05,$04,$09,$FF - -BattleTransition_CircleData2: ; 70e04 (1c:4e04) - db $01,$01,$02,$02,$04,$02,$04,$02,$03,$FF - -BattleTransition_CircleData3: ; 70e0e (1c:4e0e) - db $02,$01,$03,$01,$04,$01,$04,$01,$04,$01,$03,$01,$02,$01,$01,$01,$01,$FF - -BattleTransition_CircleData4: ; 70e20 (1c:4e20) - db $04,$01,$04,$00,$03,$01,$03,$00,$02,$01,$02,$00,$01,$FF - -BattleTransition_CircleData5: ; 70e2e (1c:4e2e) - db $04,$00,$03,$00,$03,$00,$02,$00,$02,$00,$01,$00,$01,$00,$01,$FF diff --git a/engine/battle/battle_transitions.asm b/engine/battle/battle_transitions.asm new file mode 100644 index 00000000..f1aa4161 --- /dev/null +++ b/engine/battle/battle_transitions.asm @@ -0,0 +1,815 @@ +BattleTransition: ; 7096d (1c:496d) + ld a, $1 + ld [H_AUTOBGTRANSFERENABLED], a + call Delay3 + xor a + ld [hWY], a + dec a + ld [wUpdateSpritesEnabled], a + call DelayFrame + ld hl, wSpriteStateData1 + 2 + ld a, [H_DOWNARROWBLINKCNT2] + ld c, a + ld b, $0 + ld de, $10 +.loop1 + ld a, [hl] + cp $ff + jr z, .skip1 + inc b +.skip1 + add hl, de + dec c + jr nz, .loop1 + ld hl, wOAMBuffer + $10 + ld c, $9 +.loop2 + ld a, b + swap a + cp l + jr z, .skip2 + push hl + push bc + ld bc, $10 + xor a + call FillMemory + pop bc + pop hl +.skip2 + ld de, $10 + add hl, de + dec c + jr nz, .loop2 + call Delay3 + call LoadBattleTransitionTile + ld bc, $0 + ld a, [wLinkState] + cp LINK_STATE_BATTLING + jr z, .linkBattle + call GetBattleTransitionID_WildOrTrainer + call GetBattleTransitionID_CompareLevels + call GetBattleTransitionID_IsDungeonMap +.linkBattle + ld hl, BattleTransitions + add hl, bc + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + jp [hl] + +; the three GetBattleTransitionID functions set the first +; three bits of c, which determines what transition animation +; to play at the beginning of a battle +; bit 0: set if trainer battle +; bit 1: set if enemy is at least 3 levels higher than player +; bit 2: set if dungeon map +BattleTransitions: ; 709d2 (1c:49d2) + dw BattleTransition_DoubleCircle ; %000 + dw BattleTransition_Spiral ; %001 + dw BattleTransition_Circle ; %010 + dw BattleTransition_Spiral ; %011 + dw BattleTransition_HorizontalStripes ; %100 + dw BattleTransition_Shrink ; %101 + dw BattleTransition_VerticalStripes ; %110 + dw BattleTransition_Split ; %111 + +GetBattleTransitionID_WildOrTrainer: ; 709e2 (1c:49e2) + ld a, [W_CUROPPONENT] + cp $c8 + jr nc, .trainer + res 0, c + ret +.trainer + set 0, c + ret + +GetBattleTransitionID_CompareLevels: ; 709ef (1c:49ef) + ld hl, wPartyMon1HP +.faintedLoop + ld a, [hli] + or [hl] + jr nz, .notFainted + ld de, wPartyMon2 - (wPartyMon1 + 1) + add hl, de + jr .faintedLoop +.notFainted + ld de, wPartyMon1Level - (wPartyMon1HP + 1) + add hl, de + ld a, [hl] + add $3 + ld e, a + ld a, [W_CURENEMYLVL] + sub e + jr nc, .highLevelEnemy + res 1, c + ld a, $1 + ld [wcd47], a + ret +.highLevelEnemy + set 1, c + xor a + ld [wcd47], a + ret + +; fails to recognize VICTORY_ROAD_2, VICTORY_ROAD_3, all ROCKET_HIDEOUT maps, +; MANSION_1, SEAFOAM_ISLANDS_[2-5], POWER_PLANT, DIGLETTS_CAVE +; and SILPH_CO_[9-11]F as dungeon maps +GetBattleTransitionID_IsDungeonMap: ; 70a19 (1c:4a19) + ld a, [W_CURMAP] + ld e, a + ld hl, DungeonMaps1 +.loop1 + ld a, [hli] + cp $ff + jr z, .noMatch1 + cp e + jr nz, .loop1 +.match + set 2, c + ret +.noMatch1 + ld hl, DungeonMaps2 +.loop2 + ld a, [hli] + cp $ff + jr z, .noMatch2 + ld d, a + ld a, [hli] + cp e + jr c, .loop2 + ld a, e + cp d + jr nc, .match +.noMatch2 + res 2, c + ret + +; GetBattleTransitionID_IsDungeonMap checks if W_CURMAP +; is equal to one of these maps +DungeonMaps1: ; 70a3f (1c:4a3f) + db VIRIDIAN_FOREST + db ROCK_TUNNEL_1 + db SEAFOAM_ISLANDS_1 + db ROCK_TUNNEL_2 + db $FF + +; GetBattleTransitionID_IsDungeonMap checks if W_CURMAP +; is in between or equal to each pair of maps +DungeonMaps2: ; 70a44 (1c:4a44) + ; all MT_MOON maps + db MT_MOON_1 + db MT_MOON_3 + + ; all SS_ANNE maps, VICTORY_ROAD_1, LANCES_ROOM, and HALL_OF_FAME + db SS_ANNE_1 + db HALL_OF_FAME + + ; all POKEMONTOWER maps and Lavender Town buildings + db LAVENDER_POKECENTER + db LAVENDER_HOUSE_2 + + ; SILPH_CO_[2-8]F, MANSION[2-4], SAFARI_ZONE, and UNKNOWN_DUNGEON maps, + ; except for SILPH_CO_1F + db SILPH_CO_2F + db UNKNOWN_DUNGEON_1 + db $FF + +LoadBattleTransitionTile: ; 70a4d (1c:4a4d) + ld hl, vChars1 + $7f0 + ld de, BattleTransitionTile + ld bc, (BANK(BattleTransitionTile) << 8) + $01 + jp CopyVideoData + +BattleTransitionTile: ; 70a59 (1c:4a59) + INCBIN "gfx/battle_transition.2bpp" + +BattleTransition_BlackScreen: ; 70a69 (1c:4a69) + ld a, $ff + ld [rBGP], a + ld [rOBP0], a + ld [rOBP1], a + ret + +; for non-dungeon trainer battles +; called regardless of mon levels, but does an +; outward spiral if enemy is at least 3 levels +; higher than player and does an inward spiral otherwise +BattleTransition_Spiral: ; 70a72 (1c:4a72) + ld a, [wcd47] + and a + jr z, .outwardSpiral + call BattleTransition_InwardSpiral + jr .done +.outwardSpiral + hlCoord 10, 10 + ld a, $3 + ld [wd09f], a + ld a, l + ld [wd09b], a + ld a, h + ld [wd09a], a + ld b, $78 +.loop1 + ld c, $3 +.loop2 + push bc + call BattleTransition_OutwardSpiral_ + pop bc + dec c + jr nz, .loop2 + call DelayFrame + dec b + jr nz, .loop1 +.done + call BattleTransition_BlackScreen + xor a + ld [wd09b], a + ld [wd09a], a + ret + +BattleTransition_InwardSpiral: ; 70aaa (1c:4aaa) + ld a, $7 + ld [wWhichTrade], a + ld hl, wTileMap + ld c, $11 + ld de, $14 + call BattleTransition_InwardSpiral_ + inc c + jr .skip +.loop + ld de, $14 + call BattleTransition_InwardSpiral_ +.skip + inc c + ld de, $1 + call BattleTransition_InwardSpiral_ + dec c + dec c + ld de, $ffec + call BattleTransition_InwardSpiral_ + inc c + ld de, rIE + call BattleTransition_InwardSpiral_ + dec c + dec c + ld a, c + and a + jr nz, .loop + ret + +BattleTransition_InwardSpiral_: ; 70ae0 (1c:4ae0) + push bc +.loop + ld [hl], $ff + add hl, de + push bc + ld a, [wWhichTrade] + dec a + jr nz, .skip + call BattleTransition_TransferDelay3 + ld a, $7 +.skip + ld [wWhichTrade], a + pop bc + dec c + jr nz, .loop + pop bc + ret + +BattleTransition_OutwardSpiral_: ; 70af9 (1c:4af9) + ld bc, $ffec + ld de, $14 + ld a, [wd09b] + ld l, a + ld a, [wd09a] + ld h, a + ld a, [wd09f] + cp $0 + jr z, .zero + cp $1 + jr z, .one + cp $2 + jr z, .two + cp $3 + jr z, .three +.done1 + ld [hl], $ff +.done2_ + ld a, l + ld [wd09b], a + ld a, h + ld [wd09a], a + ret +.zero + dec hl + ld a, [hl] + cp $ff + jr nz, .done2 + inc hl + add hl, bc + jr .done1 +.one + add hl, de + ld a, [hl] + cp $ff + jr nz, .done2 + add hl, bc + dec hl + jr .done1 +.two + inc hl + ld a, [hl] + cp $ff + jr nz, .done2 + dec hl + add hl, de + jr .done1 +.three + add hl, bc + ld a, [hl] + cp $ff + jr nz, .done2 + add hl, de + inc hl + jr .done1 +.done2 + ld [hl], $ff + ld a, [wd09f] + inc a + cp $4 + jr nz, .skip + xor a +.skip + ld [wd09f], a + jr .done2_ + +FlashScreen: +BattleTransition_FlashScreen_: ; 70b5d (1c:4b5d) + ld hl, BattleTransition_FlashScreenPalettes +.loop + ld a, [hli] + cp $1 + jr z, .done + ld [rBGP], a + ld c, $2 + call DelayFrames + jr .loop +.done + dec b + jr nz, BattleTransition_FlashScreen_ + ret + +BattleTransition_FlashScreenPalettes: ; 70b72 (1c:4b72) + db $F9,$FE,$FF,$FE,$F9,$E4,$90,$40,$00,$40,$90,$E4 + db $01 ; terminator + +; used for low level trainer dungeon battles +BattleTransition_Shrink: ; 70b7f (1c:4b7f) + ld c, $9 +.loop + push bc + xor a + ld [H_AUTOBGTRANSFERENABLED], a + hlCoord 0, 7 + deCoord 0, 8 + ld bc, $ffd8 + call BattleTransition_CopyTiles1 + hlCoord 0, 10 + deCoord 0, 9 + ld bc, $28 + call BattleTransition_CopyTiles1 + hlCoord 8, 0 + deCoord 9, 0 + ld bc, $fffe + call BattleTransition_CopyTiles2 + hlCoord 11, 0 + deCoord 10, 0 + ld bc, $2 + call BattleTransition_CopyTiles2 + ld a, $1 + ld [H_AUTOBGTRANSFERENABLED], a + ld c, $6 + call DelayFrames + pop bc + dec c + jr nz, .loop + call BattleTransition_BlackScreen + ld c, $a + jp DelayFrames + +; used for high level trainer dungeon battles +BattleTransition_Split: ; 70bca (1c:4bca) + ld c, $9 + xor a + ld [H_AUTOBGTRANSFERENABLED], a +.loop + push bc + hlCoord 0, 16 + deCoord 0, 17 + ld bc, $ffd8 + call BattleTransition_CopyTiles1 + hlCoord 0, 1 + ld de, wTileMap + ld bc, $28 + call BattleTransition_CopyTiles1 + hlCoord 18, 0 + deCoord 19, 0 + ld bc, $fffe + call BattleTransition_CopyTiles2 + hlCoord 1, 0 + ld de, wTileMap + ld bc, $2 + call BattleTransition_CopyTiles2 + call BattleTransition_TransferDelay3 + call Delay3 + pop bc + dec c + jr nz, .loop + call BattleTransition_BlackScreen + ld c, $a + jp DelayFrames + +BattleTransition_CopyTiles1: ; 70c12 (1c:4c12) + ld a, c + ld [wWhichTrade], a + ld a, b + ld [wTrainerEngageDistance], a + ld c, $8 +.loop1 + push bc + push hl + push de + ld bc, $14 + call CopyData + pop hl + pop de + ld a, [wWhichTrade] + ld c, a + ld a, [wTrainerEngageDistance] + ld b, a + add hl, bc + pop bc + dec c + jr nz, .loop1 + ld l, e + ld h, d + ld a, $ff + ld c, $14 +.loop2 + ld [hli], a + dec c + jr nz, .loop2 + ret + +BattleTransition_CopyTiles2: ; 70c3f (1c:4c3f) + ld a, c + ld [wWhichTrade], a + ld a, b + ld [wTrainerEngageDistance], a + ld c, $9 +.loop1 + push bc + push hl + push de + ld c, $12 +.loop2 + ld a, [hl] + ld [de], a + ld a, e + add $14 + jr nc, .noCarry1 + inc d +.noCarry1 + ld e, a + ld a, l + add $14 + jr nc, .noCarry2 + inc h +.noCarry2 + ld l, a + dec c + jr nz, .loop2 + pop hl + pop de + ld a, [wWhichTrade] + ld c, a + ld a, [wTrainerEngageDistance] + ld b, a + add hl, bc + pop bc + dec c + jr nz, .loop1 + ld l, e + ld h, d + ld de, $14 + ld c, $12 +.loop3 + ld [hl], $ff + add hl, de + dec c + jr nz, .loop3 + ret + +; used for high level wild dungeon battles +BattleTransition_VerticalStripes: ; 70c7e (1c:4c7e) + ld c, $12 + ld hl, wTileMap + deCoord 1, 17 + xor a + ld [H_AUTOBGTRANSFERENABLED], a +.loop + push bc + push hl + push de + push de + call BattleTransition_VerticalStripes_ + pop hl + call BattleTransition_VerticalStripes_ + call BattleTransition_TransferDelay3 + pop hl + ld bc, $ffec + add hl, bc + ld e, l + ld d, h + pop hl + ld bc, $14 + add hl, bc + pop bc + dec c + jr nz, .loop + jp BattleTransition_BlackScreen + +BattleTransition_VerticalStripes_: ; 70caa (1c:4caa) + ld c, $a +.loop + ld [hl], $ff + inc hl + inc hl + dec c + jr nz, .loop + ret + +; used for low level wild dungeon battles +BattleTransition_HorizontalStripes: ; 70cb4 (1c:4cb4) + ld c, $14 + ld hl, wTileMap + deCoord 19, 1 + xor a + ld [H_AUTOBGTRANSFERENABLED], a +.loop + push bc + push hl + push de + push de + call BattleTransition_HorizontalStripes_ + pop hl + call BattleTransition_HorizontalStripes_ + call BattleTransition_TransferDelay3 + pop de + pop hl + pop bc + inc hl + dec de + dec c + jr nz, .loop + jp BattleTransition_BlackScreen + +BattleTransition_HorizontalStripes_: ; 70cd8 (1c:4cd8) + ld c, $9 + ld de, $28 +.loop + ld [hl], $ff + add hl, de + dec c + jr nz, .loop + ret + +; used for high level wild non-dungeon battles +; makes one full circle around the screen +; by animating each half circle one at a time +BattleTransition_Circle: ; 70ce4 (1c:4ce4) + call BattleTransition_FlashScreen + ld bc, $000a + ld hl, BattleTransition_HalfCircle1 + call BattleTransition_Circle_Sub1 + ld c, $a + ld b, $1 + ld hl, BattleTransition_HalfCircle2 + call BattleTransition_Circle_Sub1 + jp BattleTransition_BlackScreen + +BattleTransition_FlashScreen: ; 70cfd (1c:4cfd) + ld b, $3 + call BattleTransition_FlashScreen_ + xor a + ld [H_AUTOBGTRANSFERENABLED], a + ret + +BattleTransition_Circle_Sub1: ; 70d06 (1c:4d06) + push bc + push hl + ld a, b + call BattleTransition_Circle_Sub2 + pop hl + ld bc, $0005 + add hl, bc + call BattleTransition_TransferDelay3 + pop bc + dec c + jr nz, BattleTransition_Circle_Sub1 + ret + +BattleTransition_TransferDelay3: ; 70d19 (1c:4d19) + ld a, $1 + ld [H_AUTOBGTRANSFERENABLED], a + call Delay3 + xor a + ld [H_AUTOBGTRANSFERENABLED], a + ret + +; used for low level wild non-dungeon battles +; makes two half circles around the screen +; by animating both half circles at the same time +BattleTransition_DoubleCircle: ; 70d24 (1c:4d24) + call BattleTransition_FlashScreen + ld c, $a + ld hl, BattleTransition_HalfCircle1 + ld de, BattleTransition_HalfCircle2 +.loop + push bc + push hl + push de + push de + xor a + call BattleTransition_Circle_Sub2 + pop hl + ld a, $1 + call BattleTransition_Circle_Sub2 + pop hl + ld bc, $5 + add hl, bc + ld e, l + ld d, h + pop hl + add hl, bc + call BattleTransition_TransferDelay3 + pop bc + dec c + jr nz, .loop + jp BattleTransition_BlackScreen + +BattleTransition_Circle_Sub2: ; 70d50 (1c:4d50) + ld [wWhichTrade], a + ld a, [hli] + ld [wTrainerEngageDistance], a + ld a, [hli] + ld e, a + ld a, [hli] + ld d, a + ld a, [hli] + ld h, [hl] + ld l, a + jp BattleTransition_Circle_Sub3 + +BattleTransition_HalfCircle1: ; 70d61 (1c:4d61) + db $01 + dw BattleTransition_CircleData1 + dwCoord 18, 6 + + db $01 + dw BattleTransition_CircleData2 + dwCoord 19, 3 + + db $01 + dw BattleTransition_CircleData3 + dwCoord 18, 0 + + db $01 + dw BattleTransition_CircleData4 + dwCoord 14, 0 + + db $01 + dw BattleTransition_CircleData5 + dwCoord 10, 0 + + db $00 + dw BattleTransition_CircleData5 + dwCoord 9, 0 + + db $00 + dw BattleTransition_CircleData4 + dwCoord 5, 0 + + db $00 + dw BattleTransition_CircleData3 + dwCoord 1, 0 + + db $00 + dw BattleTransition_CircleData2 + dwCoord 0, 3 + + db $00 + dw BattleTransition_CircleData1 + dwCoord 1, 6 + +BattleTransition_HalfCircle2: ; 70d93 (1c:4d93) + db $00 + dw BattleTransition_CircleData1 + dwCoord 1, 11 + + db $00 + dw BattleTransition_CircleData2 + dwCoord 0, 14 + + db $00 + dw BattleTransition_CircleData3 + dwCoord 1, 17 + + db $00 + dw BattleTransition_CircleData4 + dwCoord 5, 17 + + db $00 + dw BattleTransition_CircleData5 + dwCoord 9, 17 + + db $01 + dw BattleTransition_CircleData5 + dwCoord 10, 17 + + db $01 + dw BattleTransition_CircleData4 + dwCoord 14, 17 + + db $01 + dw BattleTransition_CircleData3 + dwCoord 18, 17 + + db $01 + dw BattleTransition_CircleData2 + dwCoord 19, 14 + + db $01 + dw BattleTransition_CircleData1 + dwCoord 18, 11 + +BattleTransition_Circle_Sub3: ; 70dc5 (1c:4dc5) + push hl + ld a, [de] + ld c, a + inc de +.loop1 + ld [hl], $ff + ld a, [wTrainerEngageDistance] + and a + jr z, .skip1 + inc hl + jr .skip2 +.skip1 + dec hl +.skip2 + dec c + jr nz, .loop1 + pop hl + ld a, [wWhichTrade] + and a + ld bc, $14 + jr z, .skip3 + ld bc, $ffec +.skip3 + add hl, bc + ld a, [de] + inc de + cp $ff + ret z + and a + jr z, BattleTransition_Circle_Sub3 + ld c, a +.loop2 + ld a, [wTrainerEngageDistance] + and a + jr z, .skip4 + dec hl + jr .skip5 +.skip4 + inc hl +.skip5 + dec c + jr nz, .loop2 + jr BattleTransition_Circle_Sub3 + +BattleTransition_CircleData1: ; 70dfe (1c:4dfe) + db $02,$03,$05,$04,$09,$FF + +BattleTransition_CircleData2: ; 70e04 (1c:4e04) + db $01,$01,$02,$02,$04,$02,$04,$02,$03,$FF + +BattleTransition_CircleData3: ; 70e0e (1c:4e0e) + db $02,$01,$03,$01,$04,$01,$04,$01,$04,$01,$03,$01,$02,$01,$01,$01,$01,$FF + +BattleTransition_CircleData4: ; 70e20 (1c:4e20) + db $04,$01,$04,$00,$03,$01,$03,$00,$02,$01,$02,$00,$01,$FF + +BattleTransition_CircleData5: ; 70e2e (1c:4e2e) + db $04,$00,$03,$00,$03,$00,$02,$00,$02,$00,$01,$00,$01,$00,$01,$FF diff --git a/engine/battle/common_text.asm b/engine/battle/common_text.asm new file mode 100644 index 00000000..9a00bd98 --- /dev/null +++ b/engine/battle/common_text.asm @@ -0,0 +1,238 @@ +PrintBeginningBattleText: ; 58d99 (16:4d99) + ld a, [W_ISINBATTLE] ; W_ISINBATTLE + dec a + jr nz, .trainerBattle + ld a, [W_CURMAP] ; W_CURMAP + cp POKEMONTOWER_3 + jr c, .notPokemonTower + cp LAVENDER_HOUSE_1 + jr c, .pokemonTower +.notPokemonTower + ld a, [wEnemyMonSpecies2] + call PlayCry + ld hl, WildMonAppearedText + ld a, [W_MOVEMISSED] ; W_MOVEMISSED + and a + jr z, .notFishing + ld hl, HookedMonAttackedText +.notFishing + jr .wildBattle +.trainerBattle + call .playSFX + ld c, $14 + call DelayFrames + ld hl, TrainerWantsToFightText +.wildBattle + push hl + callab DrawAllPokeballs + pop hl + call PrintText + jr .done +.pokemonTower + ld b, SILPH_SCOPE + call IsItemInBag + ld a, [wEnemyMonSpecies2] + ld [wcf91], a + cp MAROWAK + jr z, .isMarowak + ld a, b + and a + jr z, .noSilphScope + callab LoadEnemyMonData + jr .notPokemonTower +.noSilphScope + ld hl, EnemyAppearedText + call PrintText + ld hl, GhostCantBeIDdText + call PrintText + jr .done +.isMarowak + ld a, b + and a + jr z, .noSilphScope + ld hl, EnemyAppearedText + call PrintText + ld hl, UnveiledGhostText + call PrintText + callab LoadEnemyMonData + callab MarowakAnim + ld hl, WildMonAppearedText + call PrintText + +.playSFX + xor a + ld [wc0f1], a + ld a, $80 + ld [wc0f2], a + ld a, (SFX_08_77 - SFX_Headers_08) / 3 + call PlaySound + jp WaitForSoundToFinish +.done + ret + +WildMonAppearedText: ; 58e3b (16:4e3b) + TX_FAR _WildMonAppearedText + db "@" + +HookedMonAttackedText: ; 58e40 (16:4e40) + TX_FAR _HookedMonAttackedText + db "@" + +EnemyAppearedText: ; 58e45 (16:4e45) + TX_FAR _EnemyAppearedText + db "@" + +TrainerWantsToFightText: ; 58e4a (16:4e4a) + TX_FAR _TrainerWantsToFightText + db "@" + +UnveiledGhostText: ; 58e4f (16:4e4f) + TX_FAR _UnveiledGhostText + db "@" + +GhostCantBeIDdText: ; 58e54 (16:4e54) + TX_FAR _GhostCantBeIDdText + db "@" + +PrintSendOutMonMessage: ; 58e59 (16:4e59) + ld hl, wEnemyMonHP + ld a, [hli] + or [hl] + ld hl, GoText + jr z, .printText + xor a + ld [H_MULTIPLICAND], a + ld hl, wEnemyMonHP + ld a, [hli] + ld [wcce3], a + ld [H_MULTIPLICAND + 1], a + ld a, [hl] + ld [wcce4], a + ld [H_MULTIPLICAND + 2], a + ld a, 25 + ld [H_MULTIPLIER], a + call Multiply + ld hl, wEnemyMonMaxHP + ld a, [hli] + ld b, [hl] + srl a + rr b + srl a + rr b + ld a, b + ld b, $4 + ld [H_DIVISOR], a ; enemy mon max HP divided by 4 + call Divide + ld a, [H_QUOTIENT + 3] ; a = (enemy mon current HP * 25) / (enemy max HP / 4); this approximates the current percentage of max HP + ld hl, GoText ; 70% or greater + cp 70 + jr nc, .printText + ld hl, DoItText ; 40% - 69% + cp 40 + jr nc, .printText + ld hl, GetmText ; 10% - 39% + cp 10 + jr nc, .printText + ld hl, EnemysWeakText ; 0% - 9% +.printText + jp PrintText + +GoText: ; 58eae (16:4eae) + TX_FAR _GoText + db $08 ; asm + jr PrintPlayerMon1Text + +DoItText: ; 58eb5 (16:4eb5) + TX_FAR _DoItText + db $08 ; asm + jr PrintPlayerMon1Text + +GetmText: ; 58ebc (16:4ebc) + TX_FAR _GetmText + db $08 ; asm + jr PrintPlayerMon1Text + +EnemysWeakText: ; 58ec3 (16:4ec3) + TX_FAR _EnemysWeakText + db $08 ; asm + +PrintPlayerMon1Text: + ld hl, PlayerMon1Text + ret + +PlayerMon1Text: ; 58ecc (16:4ecc) + TX_FAR _PlayerMon1Text + db "@" + +RetreatMon: ; 58ed1 (16:4ed1) + ld hl, PlayerMon2Text + jp PrintText + +PlayerMon2Text: ; 58ed7 (16:4ed7) + TX_FAR _PlayerMon2Text + db $08 ; asm + push de + push bc + ld hl, wEnemyMonHP + 1 + ld de, wcce4 + ld b, [hl] + dec hl + ld a, [de] + sub b + ld [$ff98], a + dec de + ld b, [hl] + ld a, [de] + sbc b + ld [$ff97], a + ld a, $19 + ld [H_POWEROFTEN], a + call Multiply + ld hl, wEnemyMonMaxHP + ld a, [hli] + ld b, [hl] + srl a + rr b + srl a + rr b + ld a, b + ld b, $4 + ld [H_POWEROFTEN], a + call Divide + pop bc + pop de + ld a, [$ff98] + ld hl, EnoughText + and a + ret z + ld hl, ComeBackText + cp $1e + ret c + ld hl, OKExclamationText + cp $46 + ret c + ld hl, GoodText + ret + +EnoughText: ; 58f25 (16:4f25) + TX_FAR _EnoughText + db $08 ; asm + jr PrintComeBackText + +OKExclamationText: ; 58f2c (16:4f2c) + TX_FAR _OKExclamationText + db $08 ; asm + jr PrintComeBackText + +GoodText: ; 58f33 (16:4f33) + TX_FAR _GoodText + db $08 ; asm + jr PrintComeBackText + +PrintComeBackText: ; 58f3a (16:4f3a) + ld hl, ComeBackText + ret + +ComeBackText: ; 58f3e (16:4f3e) + TX_FAR _ComeBackText + db "@" diff --git a/engine/battle/decrement_pp.asm b/engine/battle/decrement_pp.asm new file mode 100644 index 00000000..ecf5040b --- /dev/null +++ b/engine/battle/decrement_pp.asm @@ -0,0 +1,43 @@ +DecrementPP: ; 68000 (1a:4000) +; after using a move, decrement pp in battle and (if not transformed?) in party + ld a, [de] + cp a, STRUGGLE + ret z ; if the pokemon is using "struggle", there's nothing to do + ; we don't decrement PP for "struggle" + ld hl, W_PLAYERBATTSTATUS1 + ld a, [hli] ; load the W_PLAYERBATTSTATUS1 pokemon status flags and increment hl to load the + ; W_PLAYERBATTSTATUS2 status flags later + and a, (1 << StoringEnergy) | (1 << ThrashingAbout) | (1 << AttackingMultipleTimes) + ret nz ; if any of these statuses are true, don't decrement PP + bit UsingRage, [hl] + ret nz ; don't decrement PP either if Pokemon is using Rage + ld hl, wBattleMonPP ; PP of first move (in battle) + +; decrement PP in the battle struct + call .DecrementPP + +; decrement PP in the party struct + ld a, [W_PLAYERBATTSTATUS3] + bit Transformed, a + ret nz ; Return if transformed. Pokemon Red stores the "current pokemon's" PP + ; separately from the "Pokemon in your party's" PP. This is + ; duplication -- in all cases *other* than Pokemon with Transform. + ; Normally, this means we have to go on and make the same + ; modification to the "party's pokemon" PP that we made to the + ; "current pokemon's" PP. But, if we're dealing with a Transformed + ; Pokemon, it has separate PP for the move set that it copied from + ; its opponent, which is *not* the same as its real PP as part of your + ; party. So we return, and don't do that part. + + ld hl, wPartyMon1PP ; PP of first move (in party) + ld a, [wPlayerMonNumber] ; which mon in party is active + ld bc, wPartyMon2 - wPartyMon1 + call AddNTimes ; calculate address of the mon to modify +.DecrementPP + ld a, [wPlayerMoveListIndex] ; which move (0, 1, 2, 3) did we use? + ld c, a + ld b, 0 + add hl ,bc ; calculate the address in memory of the PP we need to decrement + ; based on the move chosen. + dec [hl] ; Decrement PP + ret diff --git a/engine/battle/experience.asm b/engine/battle/experience.asm new file mode 100644 index 00000000..9bd67654 --- /dev/null +++ b/engine/battle/experience.asm @@ -0,0 +1,372 @@ +GainExperience: ; 5524f (15:524f) + ld a, [wLinkState] + cp LINK_STATE_BATTLING + ret z ; return if link battle + call DivideExpDataByNumMonsGainingExp + ld hl, wPartyMon1 + xor a + ld [wWhichPokemon], a +.partyMonLoop ; loop over each mon and add gained exp + inc hl + ld a, [hli] + or [hl] ; is mon's HP 0? + jp z, .nextMon ; if so, go to next mon + push hl + ld hl, wPartyGainExpFlags + ld a, [wWhichPokemon] + ld c, a + ld b, $2 + predef FlagActionPredef + ld a, c + and a ; is mon's gain exp flag set? + pop hl + jp z, .nextMon ; if mon's gain exp flag not set, go to next mon + ld de, (wPartyMon1HPExp + 1) - (wPartyMon1HP + 1) + add hl, de + ld d, h + ld e, l + ld hl, wEnemyMonBaseStats + ld c, $5 +.gainStatExpLoop + ld a, [hli] + ld b, a ; enemy mon base stat + ld a, [de] ; stat exp + add b ; add enemy mon base state to stat exp + ld [de], a + jr nc, .nextBaseStat +; if there was a carry, increment the upper byte + dec de + ld a, [de] + inc a + jr z, .maxStatExp ; jump if the value overflowed + ld [de], a + inc de + jr .nextBaseStat +.maxStatExp ; if the upper byte also overflowed, then we have hit the max stat exp + ld a, $ff + ld [de], a + inc de + ld [de], a +.nextBaseStat + dec c + jr z, .asm_552a1 + inc de + inc de + jr .gainStatExpLoop +.asm_552a1 + xor a + ld [H_MULTIPLICAND], a + ld [H_MULTIPLICAND + 1], a + ld a, [wEnemyMonBaseExp] + ld [H_MULTIPLICAND + 2], a + ld a, [wEnemyMonLevel] + ld [H_MULTIPLIER], a + call Multiply + ld a, 7 + ld [H_DIVISOR], a + ld b, 4 + call Divide + ld hl, -((wPartyMon1HPExp + 1) - wPartyMon1OTID + 4 * 2) + add hl, de + ld b, [hl] ; party mon OTID + inc hl + ld a, [wPlayerID] + cp b + jr nz, .tradedMon + ld b, [hl] + ld a, [wPlayerID + 1] + cp b + ld a, $0 + jr z, .next +.tradedMon + call BoostExp ; traded mon exp boost + ld a, $1 +.next + ld [wGainBoostedExp], a + ld a, [W_ISINBATTLE] + dec a ; is it a trainer battle? + call nz, BoostExp ; if so, boost exp + inc hl + inc hl + inc hl +; add the gained exp to the party mon's exp + ld b, [hl] + ld a, [H_QUOTIENT + 3] + ld [wcf4c], a + add b + ld [hld], a + ld b, [hl] + ld a, [H_QUOTIENT + 2] + ld [wcf4b], a + adc b + ld [hl], a + jr nc, .noCarry + dec hl + inc [hl] + inc hl +.noCarry +; calculate exp for the mon at max level, and cap the exp at that value + inc hl + push hl + ld a, [wWhichPokemon] + ld c, a + ld b, 0 + ld hl, wPartySpecies + add hl, bc + ld a, [hl] ; species + ld [wd0b5], a + call GetMonHeader + ld d, MAX_LEVEL + callab CalcExperience ; get max exp +; compare max exp with current exp + ld a, [$ff96] + ld b, a + ld a, [$ff97] + ld c, a + ld a, [$ff98] + ld d, a + pop hl + ld a, [hld] + sub d + ld a, [hld] + sbc c + ld a, [hl] + sbc b + jr c, .next2 +; the mon's exp is greater than the max exp, so overwrite it with the max exp + ld a, b + ld [hli], a + ld a, c + ld [hli], a + ld a, d + ld [hld], a + dec hl +.next2 + push hl + ld a, [wWhichPokemon] + ld hl, wPartyMonNicks + call GetPartyMonName + ld hl, GainedText + call PrintText + xor a ; party mon data + ld [wcc49], a + call LoadMonData + pop hl + ld bc, wPartyMon1Level - wPartyMon1Exp + add hl, bc + push hl + callba CalcLevelFromExperience + pop hl + ld a, [hl] ; current level + cp d + jp z, .nextMon ; if level didn't change, go to next mon + ld a, [W_CURENEMYLVL] + push af + push hl + ld a, d + ld [W_CURENEMYLVL], a + ld [hl], a + ld bc, wPartyMon1Species - wPartyMon1Level + add hl, bc + ld a, [hl] ; species + ld [wd0b5], a + ld [wd11e], a + call GetMonHeader + ld bc, (wPartyMon1MaxHP + 1) - wPartyMon1Species + add hl, bc + push hl + ld a, [hld] + ld c, a + ld b, [hl] + push bc ; push max HP (from before levelling up) + ld d, h + ld e, l + ld bc, (wPartyMon1HPExp - 1) - wPartyMon1MaxHP + add hl, bc + ld b, $1 ; consider stat exp when calculating stats + call CalcStats + pop bc ; pop max HP (from before levelling up) + pop hl + ld a, [hld] + sub c + ld c, a + ld a, [hl] + sbc b + ld b, a ; bc = difference between old max HP and new max HP after levelling + ld de, (wPartyMon1HP + 1) - wPartyMon1MaxHP + add hl, de +; add to the current HP the amount of max HP gained when levelling + ld a, [hl] ; wPartyMon1HP + 1 + add c + ld [hld], a + ld a, [hl] ; wPartyMon1HP + 1 + adc b + ld [hl], a ; wPartyMon1HP + ld a, [wPlayerMonNumber] + ld b, a + ld a, [wWhichPokemon] + cp b ; is the current mon in battle? + jr nz, .printGrewLevelText +; current mon is in battle + ld de, wBattleMonHP +; copy party mon HP to battle mon HP + ld a, [hli] + ld [de], a + inc de + ld a, [hl] + ld [de], a +; copy other stats from party mon to battle mon + ld bc, wPartyMon1Level - (wPartyMon1HP + 1) + add hl, bc + push hl + ld de, wBattleMonLevel + ld bc, $b ; size of stats + call CopyData + pop hl + ld a, [W_PLAYERBATTSTATUS3] + bit 3, a ; is the mon transformed? + jr nz, .recalcStatChanges +; the mon is not transformed, so update the unmodified stats + ld de, wPlayerMonUnmodifiedLevel + ld bc, $b + call CopyData +.recalcStatChanges + xor a + ld [wd11e], a + callab CalculateModifiedStats + callab ApplyBurnAndParalysisPenaltiesToPlayer + callab ApplyBadgeStatBoosts + callab DrawPlayerHUDAndHPBar + callab PrintEmptyString + call SaveScreenTilesToBuffer1 +.printGrewLevelText + ld hl, GrewLevelText + call PrintText + xor a ; party mon data + ld [wcc49], a + call LoadMonData + ld d, $1 + callab PrintStatsBox + call WaitForTextScrollButtonPress + call LoadScreenTilesFromBuffer1 + xor a + ld [wcc49], a + ld a, [wd0b5] + ld [wd11e], a + predef LearnMoveFromLevelUp + ld hl, wccd3 + ld a, [wWhichPokemon] + ld c, a + ld b, $1 + predef FlagActionPredef + pop hl + pop af + ld [W_CURENEMYLVL], a + +.nextMon + ld a, [wPartyCount] + ld b, a + ld a, [wWhichPokemon] + inc a + cp b + jr z, .done + ld [wWhichPokemon], a + ld bc, wPartyMon2 - wPartyMon1 + ld hl, wPartyMon1 + call AddNTimes + jp .partyMonLoop +.done + ld hl, wPartyGainExpFlags + xor a + ld [hl], a ; clear gain exp flags + ld a, [wPlayerMonNumber] + ld c, a + ld b, $1 + push bc + predef FlagActionPredef ; set the gain exp flag for the mon that is currently out + ld hl, wPartyFoughtCurrentEnemyFlags + xor a + ld [hl], a + pop bc + predef_jump FlagActionPredef ; set the fought current enemy flag for the mon that is currently out + +; divide enemy base stats, catch rate, and base exp by the number of mons gaining exp +DivideExpDataByNumMonsGainingExp: ; 5546c (15:546c) + ld a, [wPartyGainExpFlags] + ld b, a + xor a + ld c, $8 + ld d, $0 +.countSetBitsLoop ; loop to count set bits in wPartyGainExpFlags + xor a + srl b + adc d + ld d, a + dec c + jr nz, .countSetBitsLoop + cp $2 + ret c ; return if only one mon is gaining exp + ld [wd11e], a ; store number of mons gaining exp + ld hl, wEnemyMonBaseStats + ld c, $7 +.divideLoop + xor a + ld [H_DIVIDEND], a + ld a, [hl] + ld [H_DIVIDEND + 1], a + ld a, [wd11e] + ld [H_DIVISOR], a + ld b, $2 + call Divide ; divide value by number of mons gaining exp + ld a, [H_QUOTIENT + 3] + ld [hli], a + dec c + jr nz, .divideLoop + ret + +; multiplies exp by 1.5 +BoostExp: ; 5549f (15:549f) + ld a, [H_QUOTIENT + 2] + ld b, a + ld a, [H_QUOTIENT + 3] + ld c, a + srl b + rr c + add c + ld [H_QUOTIENT + 3], a + ld a, [H_QUOTIENT + 2] + adc b + ld [H_QUOTIENT + 2], a + ret + +GainedText: ; 554b2 (15:54b2) + TX_FAR _GainedText + db $08 ; asm + ld a, [wBoostExpByExpAll] + ld hl, WithExpAllText + and a + ret nz + ld hl, ExpPointsText + ld a, [wGainBoostedExp] + and a + ret z + ld hl, BoostedText + ret + +WithExpAllText: ; 554cb (15:54cb) + TX_FAR _WithExpAllText + db $08 ; asm + ld hl, ExpPointsText + ret + +BoostedText: ; 554d4 (15:54d4) + TX_FAR _BoostedText + +ExpPointsText: ; 554d8 (15:54d8) + TX_FAR _ExpPointsText + db "@" + +GrewLevelText: ; 554dd (15:54dd) + TX_FAR _GrewLevelText + db $0b + db "@" diff --git a/engine/battle/ghost_marowak_anim.asm b/engine/battle/ghost_marowak_anim.asm new file mode 100644 index 00000000..73d3bcc2 --- /dev/null +++ b/engine/battle/ghost_marowak_anim.asm @@ -0,0 +1,89 @@ +MarowakAnim: ; 708ca (1c:48ca) +; animate the ghost being unveiled as a Marowak + ld a, $e4 + ld [rOBP1], a + call CopyMonPicFromBGToSpriteVRAM ; cover the BG ghost pic with a sprite ghost pic that looks the same +; now that the ghost pic is being displayed using sprites, clear the ghost pic from the BG tilemap + hlCoord 12, 0 + ld bc, $707 + call ClearScreenArea + call Delay3 + xor a + ld [H_AUTOBGTRANSFERENABLED], a ; disable BG transfer so we don't see the Marowak too soon +; replace ghost pic with Marowak in BG + ld a, MAROWAK + ld [wHPBarMaxHP], a + ld a, $1 + ld [H_WHOSETURN], a + callab Func_79793 + ; alternate between black and light grey 8 times. + ; this makes the ghost's body appear to flash + ld d, $80 + call FlashSprite8Times +.fadeOutGhostLoop + ld c, 10 + call DelayFrames + ld a, [rOBP1] + sla a + sla a + ld [rOBP1], a + jr nz, .fadeOutGhostLoop + call ClearSprites + call CopyMonPicFromBGToSpriteVRAM ; copy Marowak pic from BG to sprite VRAM + ld b, $e4 +.fadeInMarowakLoop + ld c, 10 + call DelayFrames + ld a, [rOBP1] + srl b + rra + srl b + rra + ld [rOBP1], a + ld a, b + and a + jr nz, .fadeInMarowakLoop + ld a, $1 + ld [H_AUTOBGTRANSFERENABLED], a ; enable BG transfer so the BG Marowak pic will be visible after the sprite one is cleared + call Delay3 + jp ClearSprites + +; copies a mon pic's from background VRAM to sprite VRAM and sets up OAM +CopyMonPicFromBGToSpriteVRAM: ; 7092a (1c:492a) + ld de, vFrontPic + ld hl, vSprites + ld bc, 7 * 7 + call CopyVideoData + ld a, $10 + ld [W_BASECOORDY], a + ld a, $70 + ld [W_BASECOORDX], a + ld hl, wOAMBuffer + ld bc, $606 + ld d, $8 +.oamLoop + push bc + ld a, [W_BASECOORDY] + ld e, a +.oamInnerLoop + ld a, e + add $8 + ld e, a + ld [hli], a + ld a, [W_BASECOORDX] + ld [hli], a + ld a, d + ld [hli], a + ld a, $10 ; use OBP1 + ld [hli], a + inc d + dec c + jr nz, .oamInnerLoop + inc d + ld a, [W_BASECOORDX] + add $8 + ld [W_BASECOORDX], a + pop bc + dec b + jr nz, .oamLoop + ret diff --git a/main.asm b/main.asm index 9cc8b91f..62d5940b 100755 --- a/main.asm +++ b/main.asm @@ -6014,7 +6014,7 @@ DayCareMBlocks: INCBIN "maps/daycarem.blk" FuchsiaHouse3Blocks: INCBIN "maps/fuchsiahouse3.blk" -INCLUDE "engine/battle/15.asm" +INCLUDE "engine/battle/experience.asm" INCLUDE "scripts/route2.asm" INCLUDE "scripts/route3.asm" @@ -6094,7 +6094,7 @@ Route18Blocks: INCBIN "maps/route18.blk" INCBIN "maps/unusedblocks58d7d.blk" -INCLUDE "engine/battle/16.asm" +INCLUDE "engine/battle/common_text.asm" INCLUDE "engine/experience.asm" @@ -6451,7 +6451,7 @@ Plateau_Block: INCBIN "gfx/blocksets/plateau.bst" SECTION "bank1A",ROMX,BANK[$1A] -INCLUDE "engine/battle/1a.asm" +INCLUDE "engine/battle/decrement_pp.asm" Version_GFX: IF DEF(_RED) @@ -6508,7 +6508,8 @@ INCLUDE "engine/gamefreak.asm" INCLUDE "engine/hall_of_fame.asm" INCLUDE "engine/overworld/healing_machine.asm" INCLUDE "engine/overworld/player_animations.asm" -INCLUDE "engine/battle/1c.asm" +INCLUDE "engine/battle/ghost_marowak_anim.asm" +INCLUDE "engine/battle/battle_transitions.asm" INCLUDE "engine/town_map.asm" INCLUDE "engine/mon_party_sprites.asm" INCLUDE "engine/in_game_trades.asm" -- cgit v1.3.1-sl0p From ce9940a2eb89caa9f53507a6d6071f8eaf85ee48 Mon Sep 17 00:00:00 2001 From: xCrystal Date: Wed, 1 Apr 2015 17:27:51 +0200 Subject: Further split bank e stuff --- engine/battle/bank_e_misc.asm | 122 +++ engine/battle/read_trainer_party.asm | 164 ++++ engine/battle/trainer_ai.asm | 837 +++++++++++++++++ engine/battle/trainer_party_ai_misc.asm | 1263 -------------------------- engine/battle/trainer_pic_money_pointers.asm | 143 +++ main.asm | 2 +- 6 files changed, 1267 insertions(+), 1264 deletions(-) create mode 100644 engine/battle/bank_e_misc.asm create mode 100644 engine/battle/read_trainer_party.asm create mode 100644 engine/battle/trainer_ai.asm delete mode 100644 engine/battle/trainer_party_ai_misc.asm create mode 100644 engine/battle/trainer_pic_money_pointers.asm (limited to 'main.asm') diff --git a/engine/battle/bank_e_misc.asm b/engine/battle/bank_e_misc.asm new file mode 100644 index 00000000..78b27108 --- /dev/null +++ b/engine/battle/bank_e_misc.asm @@ -0,0 +1,122 @@ +; formats a string at wMovesString that lists the moves at wMoves +FormatMovesString: ; 39b87 (e:5b87) + ld hl, wMoves + ld de, wMovesString + ld b, $0 +.printMoveNameLoop + ld a, [hli] + and a ; end of move list? + jr z, .printDashLoop ; print dashes when no moves are left + push hl + ld [wd0b5], a + ld a, BANK(MoveNames) + ld [wPredefBank], a + ld a, MOVE_NAME + ld [wNameListType], a + call GetName + ld hl, wcd6d +.copyNameLoop + ld a, [hli] + cp $50 + jr z, .doneCopyingName + ld [de], a + inc de + jr .copyNameLoop +.doneCopyingName + ld a, b + ld [wcd6c], a + inc b + ld a, $4e ; line break + ld [de], a + inc de + pop hl + ld a, b + cp NUM_MOVES + jr z, .done + jr .printMoveNameLoop +.printDashLoop + ld a, "-" + ld [de], a + inc de + inc b + ld a, b + cp NUM_MOVES + jr z, .done + ld a, $4e ; line break + ld [de], a + inc de + jr .printDashLoop +.done + ld a, "@" + ld [de], a + ret + +; XXX this is called in a few places, but it doesn't appear to do anything useful +Func_39bd5: ; 39bd5 (e:5bd5) + ld a, [wd11b] + cp $1 + jr nz, .asm_39be6 + ld hl, wEnemyPartyCount + ld de, wEnemyMonOT + ld a, ENEMYOT_NAME + jr .asm_39c18 +.asm_39be6 + cp $4 + jr nz, .calcAttackStat4 + ld hl, wPartyCount + ld de, wPartyMonOT + ld a, PLAYEROT_NAME + jr .asm_39c18 +.calcAttackStat4 + cp $5 + jr nz, .asm_39c02 + ld hl, wStringBuffer2 + 11 + ld de, MonsterNames + ld a, MONSTER_NAME + jr .asm_39c18 +.asm_39c02 + cp $2 + jr nz, .asm_39c10 + ld hl, wNumBagItems + ld de, ItemNames + ld a, ITEM_NAME + jr .asm_39c18 +.asm_39c10 + ld hl, wStringBuffer2 + 11 + ld de, ItemNames + ld a, ITEM_NAME +.asm_39c18 + ld [wNameListType], a + ld a, l + ld [wList], a + ld a, h + ld [wList + 1], a + ld a, e + ld [wcf8d], a + ld a, d + ld [wcf8e], a + ld bc, ItemPrices + ld a, c + ld [wItemPrices], a + ld a, b + ld [wItemPrices + 1], a + ret + +; get species of mon e in list [wcc49] for LoadMonData +GetMonSpecies: ; 39c37 (e:5c37) + ld hl, wPartySpecies + ld a, [wcc49] + and a + jr z, .getSpecies + dec a + jr z, .enemyParty + ld hl, wBoxSpecies + jr .getSpecies +.enemyParty + ld hl, wEnemyPartyMons +.getSpecies + ld d, 0 + add hl, de + ld a, [hl] + ld [wcf91], a + ret \ No newline at end of file diff --git a/engine/battle/read_trainer_party.asm b/engine/battle/read_trainer_party.asm new file mode 100644 index 00000000..f1e3aaf1 --- /dev/null +++ b/engine/battle/read_trainer_party.asm @@ -0,0 +1,164 @@ +ReadTrainer: ; 39c53 (e:5c53) + +; don't change any moves in a link battle + ld a,[wLinkState] + and a + ret nz + +; set [wEnemyPartyCount] to 0, [wEnemyPartyMons] to FF +; XXX first is total enemy pokemon? +; XXX second is species of first pokemon? + ld hl,wEnemyPartyCount + xor a + ld [hli],a + dec a + ld [hl],a + +; get the pointer to trainer data for this class + ld a,[W_CUROPPONENT] + sub $C9 ; convert value from pokemon to trainer + add a,a + ld hl,TrainerDataPointers + ld c,a + ld b,0 + add hl,bc ; hl points to trainer class + ld a,[hli] + ld h,[hl] + ld l,a + ld a,[W_TRAINERNO] + ld b,a +; At this point b contains the trainer number, +; and hl points to the trainer class. +; Our next task is to iterate through the trainers, +; decrementing b each time, until we get to the right one. +.outer + dec b + jr z,.IterateTrainer +.inner + ld a,[hli] + and a + jr nz,.inner + jr .outer + +; if the first byte of trainer data is FF, +; - each pokemon has a specific level +; (as opposed to the whole team being of the same level) +; - if [W_LONEATTACKNO] != 0, one pokemon on the team has a special move +; else the first byte is the level of every pokemon on the team +.IterateTrainer + ld a,[hli] + cp $FF ; is the trainer special? + jr z,.SpecialTrainer ; if so, check for special moves + ld [W_CURENEMYLVL],a +.LoopTrainerData + ld a,[hli] + and a ; have we reached the end of the trainer data? + jr z,.FinishUp + ld [wcf91],a ; write species somewhere (XXX why?) + ld a,1 + ld [wcc49],a + push hl + call AddPartyMon + pop hl + jr .LoopTrainerData +.SpecialTrainer +; if this code is being run: +; - each pokemon has a specific level +; (as opposed to the whole team being of the same level) +; - if [W_LONEATTACKNO] != 0, one pokemon on the team has a special move + ld a,[hli] + and a ; have we reached the end of the trainer data? + jr z,.AddLoneMove + ld [W_CURENEMYLVL],a + ld a,[hli] + ld [wcf91],a + ld a,1 + ld [wcc49],a + push hl + call AddPartyMon + pop hl + jr .SpecialTrainer +.AddLoneMove +; does the trainer have a single monster with a different move + ld a,[W_LONEATTACKNO] ; Brock is 01, Misty is 02, Erika is 04, etc + and a + jr z,.AddTeamMove + dec a + add a,a + ld c,a + ld b,0 + ld hl,LoneMoves + add hl,bc + ld a,[hli] + ld d,[hl] + ld hl,wEnemyMon1Moves + 2 + ld bc,wEnemyMon2 - wEnemyMon1 + call AddNTimes + ld [hl],d + jr .FinishUp +.AddTeamMove +; check if our trainer's team has special moves + +; get trainer class number + ld a,[W_CUROPPONENT] + sub $C8 + ld b,a + ld hl,TeamMoves + +; iterate through entries in TeamMoves, checking each for our trainer class +.IterateTeamMoves + ld a,[hli] + cp b + jr z,.GiveTeamMoves ; is there a match? + inc hl ; if not, go to the next entry + inc a + jr nz,.IterateTeamMoves + +; no matches found. is this trainer champion rival? + ld a,b + cp SONY3 + jr z,.ChampionRival + jr .FinishUp ; nope +.GiveTeamMoves + ld a,[hl] + ld [wEnemyMon5Moves + 2],a + jr .FinishUp +.ChampionRival ; give moves to his team + +; pidgeot + ld a,SKY_ATTACK + ld [wEnemyMon1Moves + 2],a + +; starter + ld a,[W_RIVALSTARTER] + cp STARTER3 + ld b,MEGA_DRAIN + jr z,.GiveStarterMove + cp STARTER1 + ld b,FIRE_BLAST + jr z,.GiveStarterMove + ld b,BLIZZARD ; must be squirtle +.GiveStarterMove + ld a,b + ld [wEnemyMon6Moves + 2],a +.FinishUp ; XXX this needs documenting + xor a ; clear D079-D07B + ld de,wd079 + ld [de],a + inc de + ld [de],a + inc de + ld [de],a + ld a,[W_CURENEMYLVL] + ld b,a +.LastLoop + ld hl,wd047 + ld c,2 + push bc + predef AddBCDPredef + pop bc + inc de + inc de + dec b + jr nz,.LastLoop + ret \ No newline at end of file diff --git a/engine/battle/trainer_ai.asm b/engine/battle/trainer_ai.asm new file mode 100644 index 00000000..191cfd5e --- /dev/null +++ b/engine/battle/trainer_ai.asm @@ -0,0 +1,837 @@ +; creates a set of moves that may be used and returns its address in hl +; unused slots are filled with 0, all used slots may be chosen with equal probability +AIEnemyTrainerChooseMoves: ; 39719 (e:5719) + ld a, $a + ld hl, wHPBarMaxHP ; init temporary move selection array. Only the moves with the lowest numbers are chosen in the end + ld [hli], a ; move 1 + ld [hli], a ; move 2 + ld [hli], a ; move 3 + ld [hl], a ; move 4 + ld a, [W_ENEMYDISABLEDMOVE] ; forbid disabled move (if any) + swap a + and $f + jr z, .noMoveDisabled + ld hl, wHPBarMaxHP + dec a + ld c, a + ld b, $0 + add hl, bc ; advance pointer to forbidden move + ld [hl], $50 ; forbid (highly discourage) disabled move +.noMoveDisabled + ld hl, TrainerClassMoveChoiceModifications ; 589B + ld a, [W_TRAINERCLASS] + ld b, a +.loopTrainerClasses + dec b + jr z, .readTrainerClassData +.loopTrainerClassData + ld a, [hli] + and a + jr nz, .loopTrainerClassData + jr .loopTrainerClasses +.readTrainerClassData + ld a, [hl] + and a + jp z, .useOriginalMoveSet + push hl +.nextMoveChoiceModification + pop hl + ld a, [hli] + and a + jr z, .loopFindMinimumEntries + push hl + ld hl, AIMoveChoiceModificationFunctionPointers ; $57a3 + dec a + add a + ld c, a + ld b, $0 + add hl, bc ; skip to pointer + ld a, [hli] ; read pointer into hl + ld h, [hl] + ld l, a + ld de, .nextMoveChoiceModification ; set return address + push de + jp [hl] ; execute modification function +.loopFindMinimumEntries ; all entries will be decremented sequentially until one of them is zero + ld hl, wHPBarMaxHP ; temp move selection array + ld de, wEnemyMonMoves ; enemy moves + ld c, $4 +.loopDecrementEntries + ld a, [de] + inc de + and a + jr z, .loopFindMinimumEntries + dec [hl] + jr z, .minimumEntriesFound + inc hl + dec c + jr z, .loopFindMinimumEntries + jr .loopDecrementEntries +.minimumEntriesFound + ld a, c +.loopUndoPartialIteration ; undo last (partial) loop iteration + inc [hl] + dec hl + inc a + cp $5 + jr nz, .loopUndoPartialIteration + ld hl, wHPBarMaxHP ; temp move selection array + ld de, wEnemyMonMoves ; enemy moves + ld c, $4 +.filterMinimalEntries ; all minimal entries now have value 1. All other slots will be disabled (move set to 0) + ld a, [de] + and a + jr nz, .moveExisting ; 0x3978a $1 + ld [hl], a +.moveExisting + ld a, [hl] + dec a + jr z, .slotWithMinimalValue + xor a + ld [hli], a ; disable move slot + jr .next +.slotWithMinimalValue + ld a, [de] + ld [hli], a ; enable move slot +.next + inc de + dec c + jr nz, .filterMinimalEntries + ld hl, wHPBarMaxHP ; use created temporary array as move set + ret +.useOriginalMoveSet + ld hl, wEnemyMonMoves ; use original move set + ret + +AIMoveChoiceModificationFunctionPointers: ; 397a3 (e:57a3) + dw AIMoveChoiceModification1 + dw AIMoveChoiceModification2 + dw AIMoveChoiceModification3 + dw AIMoveChoiceModification4 ; unused, does nothing + +; discourages moves that cause no damage but only a status ailment if player's mon already has one +AIMoveChoiceModification1: ; 397ab (e:57ab) + ld a, [wBattleMonStatus] + and a + ret z ; return if no status ailment on player's mon + ld hl, wBuffer - 1 ; temp move selection array (-1 byte offest) + ld de, wEnemyMonMoves ; enemy moves + ld b, NUM_MOVES + 1 +.nextMove + dec b + ret z ; processed all 4 moves + inc hl + ld a, [de] + and a + ret z ; no more moves in move set + inc de + call ReadMove + ld a, [W_ENEMYMOVEPOWER] + and a + jr nz, .nextMove + ld a, [W_ENEMYMOVEEFFECT] + push hl + push de + push bc + ld hl, StatusAilmentMoveEffects + ld de, $0001 + call IsInArray + pop bc + pop de + pop hl + jr nc, .nextMove + ld a, [hl] + add $5 ; heavily discourage move + ld [hl], a + jr .nextMove + +StatusAilmentMoveEffects ; 57e2 + db $01 ; unused sleep effect + db SLEEP_EFFECT + db POISON_EFFECT + db PARALYZE_EFFECT + db $FF + +; slightly encourage moves with specific effects. +; in particular, stat-modifying moves and other move effects +; that fall in-bewteen +AIMoveChoiceModification2: ; 397e7 (e:57e7) + ld a, [wAILayer2Encouragement] + cp $1 + ret nz + ld hl, wBuffer - 1 ; temp move selection array (-1 byte offset) + ld de, wEnemyMonMoves ; enemy moves + ld b, NUM_MOVES + 1 +.nextMove + dec b + ret z ; processed all 4 moves + inc hl + ld a, [de] + and a + ret z ; no more moves in move set + inc de + call ReadMove + ld a, [W_ENEMYMOVEEFFECT] + cp ATTACK_UP1_EFFECT + jr c, .nextMove + cp BIDE_EFFECT + jr c, .preferMove + cp ATTACK_UP2_EFFECT + jr c, .nextMove + cp POISON_EFFECT + jr c, .preferMove + jr .nextMove +.preferMove + dec [hl] ; sligthly encourage this move + jr .nextMove + +; encourages moves that are effective against the player's mon (even if non-damaging). +; discourage damaging moves that are ineffective or not very effective against the player's mon, +; unless there's no damaging move that deals at least neutral damage +AIMoveChoiceModification3: ; 39817 (e:5817) + ld hl, wBuffer - 1 ; temp move selection array (-1 byte offset) + ld de, wEnemyMonMoves ; enemy moves + ld b, $5 +.nextMove + dec b + ret z ; processed all 4 moves + inc hl + ld a, [de] + and a + ret z ; no more moves in move set + inc de + call ReadMove + push hl + push bc + push de + callab AIGetTypeEffectiveness + pop de + pop bc + pop hl + ld a, [wd11e] + cp $10 + jr z, .nextMove + jr c, .notEffectiveMove + dec [hl] ; sligthly encourage this move + jr .nextMove +.notEffectiveMove ; discourages non-effective moves if better moves are available + push hl + push de + push bc + ld a, [W_ENEMYMOVETYPE] + ld d, a + ld hl, wEnemyMonMoves ; enemy moves + ld b, NUM_MOVES + 1 + ld c, $0 +.loopMoves + dec b + jr z, .done + ld a, [hli] + and a + jr z, .done + call ReadMove + ld a, [W_ENEMYMOVEEFFECT] + cp SUPER_FANG_EFFECT + jr z, .betterMoveFound ; Super Fang is considered to be a better move + cp SPECIAL_DAMAGE_EFFECT + jr z, .betterMoveFound ; any special damage moves are considered to be better moves + cp FLY_EFFECT + jr z, .betterMoveFound ; Fly is considered to be a better move + ld a, [W_ENEMYMOVETYPE] + cp d + jr z, .loopMoves + ld a, [W_ENEMYMOVEPOWER] + and a + jr nz, .betterMoveFound ; damaging moves of a different type are considered to be better moves + jr .loopMoves +.betterMoveFound + ld c, a +.done + ld a, c + pop bc + pop de + pop hl + and a + jr z, .nextMove + inc [hl] ; sligthly discourage this move + jr .nextMove +AIMoveChoiceModification4: ; 39883 (e:5883) + ret + +ReadMove: ; 39884 (e:5884) + push hl + push de + push bc + dec a + ld hl,Moves + ld bc,6 + call AddNTimes + ld de,W_ENEMYMOVENUM + call CopyData + pop bc + pop de + pop hl + ret + +; move choice modification methods that are applied for each trainer class +; 0 is sentinel value +TrainerClassMoveChoiceModifications: ; 3989b (e:589b) + db 0 ; YOUNGSTER + db 1,0 ; BUG CATCHER + db 1,0 ; LASS + db 1,3,0 ; SAILOR + db 1,0 ; JR__TRAINER_M + db 1,0 ; JR__TRAINER_F + db 1,2,3,0; POKEMANIAC + db 1,2,0 ; SUPER_NERD + db 1,0 ; HIKER + db 1,0 ; BIKER + db 1,3,0 ; BURGLAR + db 1,0 ; ENGINEER + db 1,2,0 ; JUGGLER_X + db 1,3,0 ; FISHER + db 1,3,0 ; SWIMMER + db 0 ; CUE_BALL + db 1,0 ; GAMBLER + db 1,3,0 ; BEAUTY + db 1,2,0 ; PSYCHIC_TR + db 1,3,0 ; ROCKER + db 1,0 ; JUGGLER + db 1,0 ; TAMER + db 1,0 ; BIRD_KEEPER + db 1,0 ; BLACKBELT + db 1,0 ; SONY1 + db 1,3,0 ; PROF_OAK + db 1,2,0 ; CHIEF + db 1,2,0 ; SCIENTIST + db 1,3,0 ; GIOVANNI + db 1,0 ; ROCKET + db 1,3,0 ; COOLTRAINER_M + db 1,3,0 ; COOLTRAINER_F + db 1,0 ; BRUNO + db 1,0 ; BROCK + db 1,3,0 ; MISTY + db 1,3,0 ; LT__SURGE + db 1,3,0 ; ERIKA + db 1,3,0 ; KOGA + db 1,3,0 ; BLAINE + db 1,3,0 ; SABRINA + db 1,2,0 ; GENTLEMAN + db 1,3,0 ; SONY2 + db 1,3,0 ; SONY3 + db 1,2,3,0; LORELEI + db 1,0 ; CHANNELER + db 1,0 ; AGATHA + db 1,3,0 ; LANCE + +INCLUDE "engine/battle/trainer_pic_money_pointers.asm" + +INCLUDE "text/trainer_names.asm" + +INCLUDE "engine/battle/bank_e_misc.asm" + +INCLUDE "engine/battle/read_trainer_party.asm" + +INCLUDE "data/trainer_moves.asm" + +INCLUDE "data/trainer_parties.asm" + +TrainerAI: ; 3a52e (e:652e) +;XXX called at 34964, 3c342, 3c398 + and a + ld a,[W_ISINBATTLE] + dec a + ret z ; if not a trainer, we're done here + ld a,[wLinkState] + cp LINK_STATE_BATTLING + ret z + ld a,[W_TRAINERCLASS] ; what trainer class is this? + dec a + ld c,a + ld b,0 + ld hl,TrainerAIPointers + add hl,bc + add hl,bc + add hl,bc + ld a,[wAICount] + and a + ret z ; if no AI uses left, we're done here + inc hl + inc a + jr nz,.getpointer + dec hl + ld a,[hli] + ld [wAICount],a +.getpointer + ld a,[hli] + ld h,[hl] + ld l,a + call Random + jp [hl] + +TrainerAIPointers: ; 3a55c (e:655c) +; one entry per trainer class +; first byte, number of times (per Pokémon) it can occur +; next two bytes, pointer to AI subroutine for trainer class + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,JugglerAI ; juggler_x + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,GenericAI + dbw 3,JugglerAI ; juggler + dbw 3,GenericAI + dbw 3,GenericAI + dbw 2,BlackbeltAI ; blackbelt + dbw 3,GenericAI + dbw 3,GenericAI + dbw 1,GenericAI ; chief + dbw 3,GenericAI + dbw 1,GiovanniAI ; giovanni + dbw 3,GenericAI + dbw 2,CooltrainerMAI ; cooltrainerm + dbw 1,CooltrainerFAI ; cooltrainerf + dbw 2,BrunoAI ; bruno + dbw 5,BrockAI ; brock + dbw 1,MistyAI ; misty + dbw 1,LtSurgeAI ; surge + dbw 1,ErikaAI ; erika + dbw 2,KogaAI ; koga + dbw 2,BlaineAI ; blaine + dbw 1,SabrinaAI ; sabrina + dbw 3,GenericAI + dbw 1,Sony2AI ; sony2 + dbw 1,Sony3AI ; sony3 + dbw 2,LoreleiAI ; lorelei + dbw 3,GenericAI + dbw 2,AgathaAI ; agatha + dbw 1,LanceAI ; lance + +JugglerAI: ; 3a5e9 (e:65e9) + cp $40 + ret nc + jp AISwitchIfEnoughMons + +BlackbeltAI: ; 3a5ef (e:65ef) + cp $20 + ret nc + jp AIUseXAttack + +GiovanniAI: ; 3a5f5 (e:65f5) + cp $40 + ret nc + jp AIUseGuardSpec + +CooltrainerMAI: ; 3a5fb (e:65fb) + cp $40 + ret nc + jp AIUseXAttack + +CooltrainerFAI: ; 3a601 (e:6601) + cp $40 + ld a,$A + call AICheckIfHPBelowFraction + jp c,AIUseHyperPotion + ld a,5 + call AICheckIfHPBelowFraction + ret nc + jp AISwitchIfEnoughMons + +BrockAI: ; 3a614 (e:6614) +; if his active monster has a status condition, use a full heal + ld a,[wEnemyMonStatus] + and a + ret z + jp AIUseFullHeal + +MistyAI: ; 3a61c (e:661c) + cp $40 + ret nc + jp AIUseXDefend + +LtSurgeAI: ; 3a622 (e:6622) + cp $40 + ret nc + jp AIUseXSpeed + +ErikaAI: ; 3a628 (e:6628) + cp $80 + ret nc + ld a,$A + call AICheckIfHPBelowFraction + ret nc + jp AIUseSuperPotion + +KogaAI: ; 3a634 (e:6634) + cp $40 + ret nc + jp AIUseXAttack + +BlaineAI: ; 3a63a (e:663a) + cp $40 + ret nc + jp AIUseSuperPotion + +SabrinaAI: ; 3a640 (e:6640) + cp $40 + ret nc + ld a,$A + call AICheckIfHPBelowFraction + ret nc + jp AIUseHyperPotion + +Sony2AI: ; 3a64c (e:664c) + cp $20 + ret nc + ld a,5 + call AICheckIfHPBelowFraction + ret nc + jp AIUsePotion + +Sony3AI: ; 3a658 (e:6658) + cp $20 + ret nc + ld a,5 + call AICheckIfHPBelowFraction + ret nc + jp AIUseFullRestore + +LoreleiAI: ; 3a664 (e:6664) + cp $80 + ret nc + ld a,5 + call AICheckIfHPBelowFraction + ret nc + jp AIUseSuperPotion + +BrunoAI: ; 3a670 (e:6670) + cp $40 + ret nc + jp AIUseXDefend + +AgathaAI: ; 3a676 (e:6676) + cp $14 + jp c,AISwitchIfEnoughMons + cp $80 + ret nc + ld a,4 + call AICheckIfHPBelowFraction + ret nc + jp AIUseSuperPotion + +LanceAI: ; 3a687 (e:6687) + cp $80 + ret nc + ld a,5 + call AICheckIfHPBelowFraction + ret nc + jp AIUseHyperPotion + +GenericAI: ; 3a693 (e:6693) + and a ; clear carry + ret + +; end of individual trainer AI routines + +DecrementAICount: ; 3a695 (e:6695) + ld hl,wAICount + dec [hl] + scf + ret + +Func_3a69b: ; 3a69b (e:669b) + ld a,(SFX_08_3e - SFX_Headers_08) / 3 + jp PlaySoundWaitForCurrent + +AIUseFullRestore: ; 3a6a0 (e:66a0) + call AICureStatus + ld a,FULL_RESTORE + ld [wcf05],a + ld de,wHPBarOldHP + ld hl,wEnemyMonHP + 1 + ld a,[hld] + ld [de],a + inc de + ld a,[hl] + ld [de],a + inc de + ld hl,wEnemyMonMaxHP + 1 + ld a,[hld] + ld [de],a + inc de + ld [wHPBarMaxHP],a + ld [wEnemyMonHP + 1],a + ld a,[hl] + ld [de],a + ld [wHPBarMaxHP+1],a + ld [wEnemyMonHP],a + jr AIPrintItemUseAndUpdateHPBar + +AIUsePotion: ; 3a6ca (e:66ca) +; enemy trainer heals his monster with a potion + ld a,POTION + ld b,20 + jr AIRecoverHP + +AIUseSuperPotion: ; 3a6d0 (e:66d0) +; enemy trainer heals his monster with a super potion + ld a,SUPER_POTION + ld b,50 + jr AIRecoverHP + +AIUseHyperPotion: ; 3a6d6 (e:66d6) +; enemy trainer heals his monster with a hyper potion + ld a,HYPER_POTION + ld b,200 + ; fallthrough + +AIRecoverHP: ; 3a6da (e:66da) +; heal b HP and print "trainer used $(a) on pokemon!" + ld [wcf05],a + ld hl,wEnemyMonHP + 1 + ld a,[hl] + ld [wHPBarOldHP],a + add b + ld [hld],a + ld [wHPBarNewHP],a + ld a,[hl] + ld [wHPBarOldHP+1],a + ld [wHPBarNewHP+1],a + jr nc,.next + inc a + ld [hl],a + ld [wHPBarNewHP+1],a +.next + inc hl + ld a,[hld] + ld b,a + ld de,wEnemyMonMaxHP + 1 + ld a,[de] + dec de + ld [wHPBarMaxHP],a + sub b + ld a,[hli] + ld b,a + ld a,[de] + ld [wHPBarMaxHP+1],a + sbc b + jr nc,AIPrintItemUseAndUpdateHPBar + inc de + ld a,[de] + dec de + ld [hld],a + ld [wHPBarNewHP],a + ld a,[de] + ld [hl],a + ld [wHPBarNewHP+1],a + ; fallthrough + +AIPrintItemUseAndUpdateHPBar: ; 3a718 (e:6718) + call AIPrintItemUse_ + hlCoord 2, 2 + xor a + ld [wHPBarType],a + predef UpdateHPBar2 + jp DecrementAICount + +AISwitchIfEnoughMons: ; 3a72a (e:672a) +; enemy trainer switches if there are 3 or more unfainted mons in party + ld a,[wEnemyPartyCount] + ld c,a + ld hl,wEnemyMon1HP + + ld d,0 ; keep count of unfainted monsters + + ; count how many monsters haven't fainted yet +.loop + ld a,[hli] + ld b,a + ld a,[hld] + or b + jr z,.Fainted ; has monster fainted? + inc d +.Fainted + push bc + ld bc,$2C + add hl,bc + pop bc + dec c + jr nz,.loop + + ld a,d ; how many available monsters are there? + cp 2 ; don't bother if only 1 or 2 + jp nc,SwitchEnemyMon + and a + ret + +SwitchEnemyMon: ; 3a74b (e:674b) + +; prepare to withdraw the active monster: copy hp, number, and status to roster + + ld a,[wEnemyMonPartyPos] + ld hl,wEnemyMon1HP + ld bc,wEnemyMon2 - wEnemyMon1 + call AddNTimes + ld d,h + ld e,l + ld hl,wEnemyMonHP + ld bc,4 + call CopyData + + ld hl, AIBattleWithdrawText + call PrintText + + ld a,1 + ld [wd11d],a + callab EnemySendOut + xor a + ld [wd11d],a + + ld a,[wLinkState] + cp LINK_STATE_BATTLING + ret z + scf + ret + +AIBattleWithdrawText: ; 3a781 (e:6781) + TX_FAR _AIBattleWithdrawText + db "@" + +AIUseFullHeal: ; 3a786 (e:6786) + call Func_3a69b + call AICureStatus + ld a,FULL_HEAL + jp AIPrintItemUse + +AICureStatus: ; 3a791 (e:6791) +; cures the status of enemy's active pokemon + ld a,[wEnemyMonPartyPos] + ld hl,wEnemyMon1Status + ld bc,wEnemyMon2 - wEnemyMon1 + call AddNTimes + xor a + ld [hl],a ; clear status in enemy team roster + ld [wEnemyMonStatus],a ; clear status of active enemy + ld hl,W_ENEMYBATTSTATUS3 + res 0,[hl] + ret + +AIUseXAccuracy: ; 0x3a7a8 unused + call Func_3a69b + ld hl,W_ENEMYBATTSTATUS2 + set 0,[hl] + ld a,X_ACCURACY + jp AIPrintItemUse + +AIUseGuardSpec: ; 3a7b5 (e:67b5) + call Func_3a69b + ld hl,W_ENEMYBATTSTATUS2 + set 1,[hl] + ld a,GUARD_SPEC_ + jp AIPrintItemUse + +AIUseDireHit: ; 0x3a7c2 unused + call Func_3a69b + ld hl,W_ENEMYBATTSTATUS2 + set 2,[hl] + ld a,DIRE_HIT + jp AIPrintItemUse + +AICheckIfHPBelowFraction: ; 3a7cf (e:67cf) +; return carry if enemy trainer's current HP is below 1 / a of the maximum + ld [H_DIVISOR],a + ld hl,wEnemyMonMaxHP + ld a,[hli] + ld [H_DIVIDEND],a + ld a,[hl] + ld [H_DIVIDEND + 1],a + ld b,2 + call Divide + ld a,[H_QUOTIENT + 3] + ld c,a + ld a,[H_QUOTIENT + 2] + ld b,a + ld hl,wEnemyMonHP + 1 + ld a,[hld] + ld e,a + ld a,[hl] + ld d,a + ld a,d + sub b + ret nz + ld a,e + sub c + ret + +AIUseXAttack: ; 3a7f2 (e:67f2) + ld b,$A + ld a,X_ATTACK + jr AIIncreaseStat + +AIUseXDefend: ; 3a7f8 (e:67f8) + ld b,$B + ld a,X_DEFEND + jr AIIncreaseStat + +AIUseXSpeed: ; 3a7fe (e:67fe) + ld b,$C + ld a,X_SPEED + jr AIIncreaseStat + +AIUseXSpecial: ; 3a804 (e:6804) + ld b,$D + ld a,X_SPECIAL + ; fallthrough + +AIIncreaseStat: ; 3a808 (e:6808) + ld [wcf05],a + push bc + call AIPrintItemUse_ + pop bc + ld hl,W_ENEMYMOVEEFFECT + ld a,[hld] + push af + ld a,[hl] + push af + push hl + ld a,$AF + ld [hli],a + ld [hl],b + callab StatModifierUpEffect + pop hl + pop af + ld [hli],a + pop af + ld [hl],a + jp DecrementAICount + +AIPrintItemUse: ; 3a82c (e:682c) + ld [wcf05],a + call AIPrintItemUse_ + jp DecrementAICount + +AIPrintItemUse_: ; 3a835 (e:6835) +; print "x used [wcf05] on z!" + ld a,[wcf05] + ld [wd11e],a + call GetItemName + ld hl, AIBattleUseItemText + jp PrintText + +AIBattleUseItemText: ; 3a844 (e:6844) + TX_FAR _AIBattleUseItemText + db "@" diff --git a/engine/battle/trainer_party_ai_misc.asm b/engine/battle/trainer_party_ai_misc.asm deleted file mode 100644 index 8cbb9329..00000000 --- a/engine/battle/trainer_party_ai_misc.asm +++ /dev/null @@ -1,1263 +0,0 @@ -; creates a set of moves that may be used and returns its address in hl -; unused slots are filled with 0, all used slots may be chosen with equal probability -AIEnemyTrainerChooseMoves: ; 39719 (e:5719) - ld a, $a - ld hl, wHPBarMaxHP ; init temporary move selection array. Only the moves with the lowest numbers are chosen in the end - ld [hli], a ; move 1 - ld [hli], a ; move 2 - ld [hli], a ; move 3 - ld [hl], a ; move 4 - ld a, [W_ENEMYDISABLEDMOVE] ; forbid disabled move (if any) - swap a - and $f - jr z, .noMoveDisabled - ld hl, wHPBarMaxHP - dec a - ld c, a - ld b, $0 - add hl, bc ; advance pointer to forbidden move - ld [hl], $50 ; forbid (highly discourage) disabled move -.noMoveDisabled - ld hl, TrainerClassMoveChoiceModifications ; 589B - ld a, [W_TRAINERCLASS] - ld b, a -.loopTrainerClasses - dec b - jr z, .readTrainerClassData -.loopTrainerClassData - ld a, [hli] - and a - jr nz, .loopTrainerClassData - jr .loopTrainerClasses -.readTrainerClassData - ld a, [hl] - and a - jp z, .useOriginalMoveSet - push hl -.nextMoveChoiceModification - pop hl - ld a, [hli] - and a - jr z, .loopFindMinimumEntries - push hl - ld hl, AIMoveChoiceModificationFunctionPointers ; $57a3 - dec a - add a - ld c, a - ld b, $0 - add hl, bc ; skip to pointer - ld a, [hli] ; read pointer into hl - ld h, [hl] - ld l, a - ld de, .nextMoveChoiceModification ; set return address - push de - jp [hl] ; execute modification function -.loopFindMinimumEntries ; all entries will be decremented sequentially until one of them is zero - ld hl, wHPBarMaxHP ; temp move selection array - ld de, wEnemyMonMoves ; enemy moves - ld c, $4 -.loopDecrementEntries - ld a, [de] - inc de - and a - jr z, .loopFindMinimumEntries - dec [hl] - jr z, .minimumEntriesFound - inc hl - dec c - jr z, .loopFindMinimumEntries - jr .loopDecrementEntries -.minimumEntriesFound - ld a, c -.loopUndoPartialIteration ; undo last (partial) loop iteration - inc [hl] - dec hl - inc a - cp $5 - jr nz, .loopUndoPartialIteration - ld hl, wHPBarMaxHP ; temp move selection array - ld de, wEnemyMonMoves ; enemy moves - ld c, $4 -.filterMinimalEntries ; all minimal entries now have value 1. All other slots will be disabled (move set to 0) - ld a, [de] - and a - jr nz, .moveExisting ; 0x3978a $1 - ld [hl], a -.moveExisting - ld a, [hl] - dec a - jr z, .slotWithMinimalValue - xor a - ld [hli], a ; disable move slot - jr .next -.slotWithMinimalValue - ld a, [de] - ld [hli], a ; enable move slot -.next - inc de - dec c - jr nz, .filterMinimalEntries - ld hl, wHPBarMaxHP ; use created temporary array as move set - ret -.useOriginalMoveSet - ld hl, wEnemyMonMoves ; use original move set - ret - -AIMoveChoiceModificationFunctionPointers: ; 397a3 (e:57a3) - dw AIMoveChoiceModification1 - dw AIMoveChoiceModification2 - dw AIMoveChoiceModification3 - dw AIMoveChoiceModification4 ; unused, does nothing - -; discourages moves that cause no damage but only a status ailment if player's mon already has one -AIMoveChoiceModification1: ; 397ab (e:57ab) - ld a, [wBattleMonStatus] - and a - ret z ; return if no status ailment on player's mon - ld hl, wBuffer - 1 ; temp move selection array (-1 byte offest) - ld de, wEnemyMonMoves ; enemy moves - ld b, NUM_MOVES + 1 -.nextMove - dec b - ret z ; processed all 4 moves - inc hl - ld a, [de] - and a - ret z ; no more moves in move set - inc de - call ReadMove - ld a, [W_ENEMYMOVEPOWER] - and a - jr nz, .nextMove - ld a, [W_ENEMYMOVEEFFECT] - push hl - push de - push bc - ld hl, StatusAilmentMoveEffects - ld de, $0001 - call IsInArray - pop bc - pop de - pop hl - jr nc, .nextMove - ld a, [hl] - add $5 ; heavily discourage move - ld [hl], a - jr .nextMove - -StatusAilmentMoveEffects ; 57e2 - db $01 ; unused sleep effect - db SLEEP_EFFECT - db POISON_EFFECT - db PARALYZE_EFFECT - db $FF - -; slightly encourage moves with specific effects. -; in particular, stat-modifying moves and other move effects -; that fall in-bewteen -AIMoveChoiceModification2: ; 397e7 (e:57e7) - ld a, [wAILayer2Encouragement] - cp $1 - ret nz - ld hl, wBuffer - 1 ; temp move selection array (-1 byte offset) - ld de, wEnemyMonMoves ; enemy moves - ld b, NUM_MOVES + 1 -.nextMove - dec b - ret z ; processed all 4 moves - inc hl - ld a, [de] - and a - ret z ; no more moves in move set - inc de - call ReadMove - ld a, [W_ENEMYMOVEEFFECT] - cp ATTACK_UP1_EFFECT - jr c, .nextMove - cp BIDE_EFFECT - jr c, .preferMove - cp ATTACK_UP2_EFFECT - jr c, .nextMove - cp POISON_EFFECT - jr c, .preferMove - jr .nextMove -.preferMove - dec [hl] ; sligthly encourage this move - jr .nextMove - -; encourages moves that are effective against the player's mon (even if non-damaging). -; discourage damaging moves that are ineffective or not very effective against the player's mon, -; unless there's no damaging move that deals at least neutral damage -AIMoveChoiceModification3: ; 39817 (e:5817) - ld hl, wBuffer - 1 ; temp move selection array (-1 byte offset) - ld de, wEnemyMonMoves ; enemy moves - ld b, $5 -.nextMove - dec b - ret z ; processed all 4 moves - inc hl - ld a, [de] - and a - ret z ; no more moves in move set - inc de - call ReadMove - push hl - push bc - push de - callab AIGetTypeEffectiveness - pop de - pop bc - pop hl - ld a, [wd11e] - cp $10 - jr z, .nextMove - jr c, .notEffectiveMove - dec [hl] ; sligthly encourage this move - jr .nextMove -.notEffectiveMove ; discourages non-effective moves if better moves are available - push hl - push de - push bc - ld a, [W_ENEMYMOVETYPE] - ld d, a - ld hl, wEnemyMonMoves ; enemy moves - ld b, NUM_MOVES + 1 - ld c, $0 -.loopMoves - dec b - jr z, .done - ld a, [hli] - and a - jr z, .done - call ReadMove - ld a, [W_ENEMYMOVEEFFECT] - cp SUPER_FANG_EFFECT - jr z, .betterMoveFound ; Super Fang is considered to be a better move - cp SPECIAL_DAMAGE_EFFECT - jr z, .betterMoveFound ; any special damage moves are considered to be better moves - cp FLY_EFFECT - jr z, .betterMoveFound ; Fly is considered to be a better move - ld a, [W_ENEMYMOVETYPE] - cp d - jr z, .loopMoves - ld a, [W_ENEMYMOVEPOWER] - and a - jr nz, .betterMoveFound ; damaging moves of a different type are considered to be better moves - jr .loopMoves -.betterMoveFound - ld c, a -.done - ld a, c - pop bc - pop de - pop hl - and a - jr z, .nextMove - inc [hl] ; sligthly discourage this move - jr .nextMove -AIMoveChoiceModification4: ; 39883 (e:5883) - ret - -ReadMove: ; 39884 (e:5884) - push hl - push de - push bc - dec a - ld hl,Moves - ld bc,6 - call AddNTimes - ld de,W_ENEMYMOVENUM - call CopyData - pop bc - pop de - pop hl - ret - -; move choice modification methods that are applied for each trainer class -; 0 is sentinel value -TrainerClassMoveChoiceModifications: ; 3989b (e:589b) - db 0 ; YOUNGSTER - db 1,0 ; BUG CATCHER - db 1,0 ; LASS - db 1,3,0 ; SAILOR - db 1,0 ; JR__TRAINER_M - db 1,0 ; JR__TRAINER_F - db 1,2,3,0; POKEMANIAC - db 1,2,0 ; SUPER_NERD - db 1,0 ; HIKER - db 1,0 ; BIKER - db 1,3,0 ; BURGLAR - db 1,0 ; ENGINEER - db 1,2,0 ; JUGGLER_X - db 1,3,0 ; FISHER - db 1,3,0 ; SWIMMER - db 0 ; CUE_BALL - db 1,0 ; GAMBLER - db 1,3,0 ; BEAUTY - db 1,2,0 ; PSYCHIC_TR - db 1,3,0 ; ROCKER - db 1,0 ; JUGGLER - db 1,0 ; TAMER - db 1,0 ; BIRD_KEEPER - db 1,0 ; BLACKBELT - db 1,0 ; SONY1 - db 1,3,0 ; PROF_OAK - db 1,2,0 ; CHIEF - db 1,2,0 ; SCIENTIST - db 1,3,0 ; GIOVANNI - db 1,0 ; ROCKET - db 1,3,0 ; COOLTRAINER_M - db 1,3,0 ; COOLTRAINER_F - db 1,0 ; BRUNO - db 1,0 ; BROCK - db 1,3,0 ; MISTY - db 1,3,0 ; LT__SURGE - db 1,3,0 ; ERIKA - db 1,3,0 ; KOGA - db 1,3,0 ; BLAINE - db 1,3,0 ; SABRINA - db 1,2,0 ; GENTLEMAN - db 1,3,0 ; SONY2 - db 1,3,0 ; SONY3 - db 1,2,3,0; LORELEI - db 1,0 ; CHANNELER - db 1,0 ; AGATHA - db 1,3,0 ; LANCE - -TrainerPicAndMoneyPointers: ; 39914 (e:5914) -; trainer pic pointers and base money. -; money received after battle = base money × level of highest-level enemy mon - dw YoungsterPic - money 1500 - - dw BugCatcherPic - money 1000 - - dw LassPic - money 1500 - - dw SailorPic - money 3000 - - dw JrTrainerMPic - money 2000 - - dw JrTrainerFPic - money 2000 - - dw PokemaniacPic - money 5000 - - dw SuperNerdPic - money 2500 - - dw HikerPic - money 3500 - - dw BikerPic - money 2000 - - dw BurglarPic - money 9000 - - dw EngineerPic - money 5000 - - dw JugglerPic - money 3500 - - dw FisherPic - money 3500 - - dw SwimmerPic - money 500 - - dw CueBallPic - money 2500 - - dw GamblerPic - money 7000 - - dw BeautyPic - money 7000 - - dw PsychicPic - money 1000 - - dw RockerPic - money 2500 - - dw JugglerPic - money 3500 - - dw TamerPic - money 4000 - - dw BirdKeeperPic - money 2500 - - dw BlackbeltPic - money 2500 - - dw Rival1Pic - money 3500 - - dw ProfOakPic - money 9900 - - dw ChiefPic - money 3000 - - dw ScientistPic - money 5000 - - dw GiovanniPic - money 9900 - - dw RocketPic - money 3000 - - dw CooltrainerMPic - money 3500 - - dw CooltrainerFPic - money 3500 - - dw BrunoPic - money 9900 - - dw BrockPic - money 9900 - - dw MistyPic - money 9900 - - dw LtSurgePic - money 9900 - - dw ErikaPic - money 9900 - - dw KogaPic - money 9900 - - dw BlainePic - money 9900 - - dw SabrinaPic - money 9900 - - dw GentlemanPic - money 7000 - - dw Rival2Pic - money 6500 - - dw Rival3Pic - money 9900 - - dw LoreleiPic - money 9900 - - dw ChannelerPic - money 3000 - - dw AgathaPic - money 9900 - - dw LancePic - money 9900 - -INCLUDE "text/trainer_names.asm" - -; formats a string at wMovesString that lists the moves at wMoves -FormatMovesString: ; 39b87 (e:5b87) - ld hl, wMoves - ld de, wMovesString - ld b, $0 -.printMoveNameLoop - ld a, [hli] - and a ; end of move list? - jr z, .printDashLoop ; print dashes when no moves are left - push hl - ld [wd0b5], a - ld a, BANK(MoveNames) - ld [wPredefBank], a - ld a, MOVE_NAME - ld [wNameListType], a - call GetName - ld hl, wcd6d -.copyNameLoop - ld a, [hli] - cp $50 - jr z, .doneCopyingName - ld [de], a - inc de - jr .copyNameLoop -.doneCopyingName - ld a, b - ld [wcd6c], a - inc b - ld a, $4e ; line break - ld [de], a - inc de - pop hl - ld a, b - cp NUM_MOVES - jr z, .done - jr .printMoveNameLoop -.printDashLoop - ld a, "-" - ld [de], a - inc de - inc b - ld a, b - cp NUM_MOVES - jr z, .done - ld a, $4e ; line break - ld [de], a - inc de - jr .printDashLoop -.done - ld a, "@" - ld [de], a - ret - -; XXX this is called in a few places, but it doesn't appear to do anything useful -Func_39bd5: ; 39bd5 (e:5bd5) - ld a, [wd11b] - cp $1 - jr nz, .asm_39be6 - ld hl, wEnemyPartyCount - ld de, wEnemyMonOT - ld a, ENEMYOT_NAME - jr .asm_39c18 -.asm_39be6 - cp $4 - jr nz, .calcAttackStat4 - ld hl, wPartyCount - ld de, wPartyMonOT - ld a, PLAYEROT_NAME - jr .asm_39c18 -.calcAttackStat4 - cp $5 - jr nz, .asm_39c02 - ld hl, wStringBuffer2 + 11 - ld de, MonsterNames - ld a, MONSTER_NAME - jr .asm_39c18 -.asm_39c02 - cp $2 - jr nz, .asm_39c10 - ld hl, wNumBagItems - ld de, ItemNames - ld a, ITEM_NAME - jr .asm_39c18 -.asm_39c10 - ld hl, wStringBuffer2 + 11 - ld de, ItemNames - ld a, ITEM_NAME -.asm_39c18 - ld [wNameListType], a - ld a, l - ld [wList], a - ld a, h - ld [wList + 1], a - ld a, e - ld [wcf8d], a - ld a, d - ld [wcf8e], a - ld bc, ItemPrices - ld a, c - ld [wItemPrices], a - ld a, b - ld [wItemPrices + 1], a - ret - -; get species of mon e in list [wcc49] for LoadMonData -GetMonSpecies: ; 39c37 (e:5c37) - ld hl, wPartySpecies - ld a, [wcc49] - and a - jr z, .getSpecies - dec a - jr z, .enemyParty - ld hl, wBoxSpecies - jr .getSpecies -.enemyParty - ld hl, wEnemyPartyMons -.getSpecies - ld d, 0 - add hl, de - ld a, [hl] - ld [wcf91], a - ret - -ReadTrainer: ; 39c53 (e:5c53) - -; don't change any moves in a link battle - ld a,[wLinkState] - and a - ret nz - -; set [wEnemyPartyCount] to 0, [wEnemyPartyMons] to FF -; XXX first is total enemy pokemon? -; XXX second is species of first pokemon? - ld hl,wEnemyPartyCount - xor a - ld [hli],a - dec a - ld [hl],a - -; get the pointer to trainer data for this class - ld a,[W_CUROPPONENT] - sub $C9 ; convert value from pokemon to trainer - add a,a - ld hl,TrainerDataPointers - ld c,a - ld b,0 - add hl,bc ; hl points to trainer class - ld a,[hli] - ld h,[hl] - ld l,a - ld a,[W_TRAINERNO] - ld b,a -; At this point b contains the trainer number, -; and hl points to the trainer class. -; Our next task is to iterate through the trainers, -; decrementing b each time, until we get to the right one. -.outer - dec b - jr z,.IterateTrainer -.inner - ld a,[hli] - and a - jr nz,.inner - jr .outer - -; if the first byte of trainer data is FF, -; - each pokemon has a specific level -; (as opposed to the whole team being of the same level) -; - if [W_LONEATTACKNO] != 0, one pokemon on the team has a special move -; else the first byte is the level of every pokemon on the team -.IterateTrainer - ld a,[hli] - cp $FF ; is the trainer special? - jr z,.SpecialTrainer ; if so, check for special moves - ld [W_CURENEMYLVL],a -.LoopTrainerData - ld a,[hli] - and a ; have we reached the end of the trainer data? - jr z,.FinishUp - ld [wcf91],a ; write species somewhere (XXX why?) - ld a,1 - ld [wcc49],a - push hl - call AddPartyMon - pop hl - jr .LoopTrainerData -.SpecialTrainer -; if this code is being run: -; - each pokemon has a specific level -; (as opposed to the whole team being of the same level) -; - if [W_LONEATTACKNO] != 0, one pokemon on the team has a special move - ld a,[hli] - and a ; have we reached the end of the trainer data? - jr z,.AddLoneMove - ld [W_CURENEMYLVL],a - ld a,[hli] - ld [wcf91],a - ld a,1 - ld [wcc49],a - push hl - call AddPartyMon - pop hl - jr .SpecialTrainer -.AddLoneMove -; does the trainer have a single monster with a different move - ld a,[W_LONEATTACKNO] ; Brock is 01, Misty is 02, Erika is 04, etc - and a - jr z,.AddTeamMove - dec a - add a,a - ld c,a - ld b,0 - ld hl,LoneMoves - add hl,bc - ld a,[hli] - ld d,[hl] - ld hl,wEnemyMon1Moves + 2 - ld bc,wEnemyMon2 - wEnemyMon1 - call AddNTimes - ld [hl],d - jr .FinishUp -.AddTeamMove -; check if our trainer's team has special moves - -; get trainer class number - ld a,[W_CUROPPONENT] - sub $C8 - ld b,a - ld hl,TeamMoves - -; iterate through entries in TeamMoves, checking each for our trainer class -.IterateTeamMoves - ld a,[hli] - cp b - jr z,.GiveTeamMoves ; is there a match? - inc hl ; if not, go to the next entry - inc a - jr nz,.IterateTeamMoves - - ; no matches found. is this trainer champion rival? - ld a,b - cp SONY3 - jr z,.ChampionRival - jr .FinishUp ; nope -.GiveTeamMoves - ld a,[hl] - ld [wEnemyMon5Moves + 2],a - jr .FinishUp -.ChampionRival ; give moves to his team - -; pidgeot - ld a,SKY_ATTACK - ld [wEnemyMon1Moves + 2],a - -; starter - ld a,[W_RIVALSTARTER] - cp STARTER3 - ld b,MEGA_DRAIN - jr z,.GiveStarterMove - cp STARTER1 - ld b,FIRE_BLAST - jr z,.GiveStarterMove - ld b,BLIZZARD ; must be squirtle -.GiveStarterMove - ld a,b - ld [wEnemyMon6Moves + 2],a -.FinishUp ; XXX this needs documenting - xor a ; clear D079-D07B - ld de,wd079 - ld [de],a - inc de - ld [de],a - inc de - ld [de],a - ld a,[W_CURENEMYLVL] - ld b,a -.LastLoop - ld hl,wd047 - ld c,2 - push bc - predef AddBCDPredef - pop bc - inc de - inc de - dec b - jr nz,.LastLoop - ret - -INCLUDE "data/trainer_moves.asm" - -INCLUDE "data/trainer_parties.asm" - -TrainerAI: ; 3a52e (e:652e) -;XXX called at 34964, 3c342, 3c398 - and a - ld a,[W_ISINBATTLE] - dec a - ret z ; if not a trainer, we're done here - ld a,[wLinkState] - cp LINK_STATE_BATTLING - ret z - ld a,[W_TRAINERCLASS] ; what trainer class is this? - dec a - ld c,a - ld b,0 - ld hl,TrainerAIPointers - add hl,bc - add hl,bc - add hl,bc - ld a,[wAICount] - and a - ret z ; if no AI uses left, we're done here - inc hl - inc a - jr nz,.getpointer - dec hl - ld a,[hli] - ld [wAICount],a -.getpointer - ld a,[hli] - ld h,[hl] - ld l,a - call Random - jp [hl] - -TrainerAIPointers: ; 3a55c (e:655c) -; one entry per trainer class -; first byte, number of times (per Pokémon) it can occur -; next two bytes, pointer to AI subroutine for trainer class - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,JugglerAI ; juggler_x - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,JugglerAI ; juggler - dbw 3,GenericAI - dbw 3,GenericAI - dbw 2,BlackbeltAI ; blackbelt - dbw 3,GenericAI - dbw 3,GenericAI - dbw 1,GenericAI ; chief - dbw 3,GenericAI - dbw 1,GiovanniAI ; giovanni - dbw 3,GenericAI - dbw 2,CooltrainerMAI ; cooltrainerm - dbw 1,CooltrainerFAI ; cooltrainerf - dbw 2,BrunoAI ; bruno - dbw 5,BrockAI ; brock - dbw 1,MistyAI ; misty - dbw 1,LtSurgeAI ; surge - dbw 1,ErikaAI ; erika - dbw 2,KogaAI ; koga - dbw 2,BlaineAI ; blaine - dbw 1,SabrinaAI ; sabrina - dbw 3,GenericAI - dbw 1,Sony2AI ; sony2 - dbw 1,Sony3AI ; sony3 - dbw 2,LoreleiAI ; lorelei - dbw 3,GenericAI - dbw 2,AgathaAI ; agatha - dbw 1,LanceAI ; lance - -JugglerAI: ; 3a5e9 (e:65e9) - cp $40 - ret nc - jp AISwitchIfEnoughMons - -BlackbeltAI: ; 3a5ef (e:65ef) - cp $20 - ret nc - jp AIUseXAttack - -GiovanniAI: ; 3a5f5 (e:65f5) - cp $40 - ret nc - jp AIUseGuardSpec - -CooltrainerMAI: ; 3a5fb (e:65fb) - cp $40 - ret nc - jp AIUseXAttack - -CooltrainerFAI: ; 3a601 (e:6601) - cp $40 - ld a,$A - call AICheckIfHPBelowFraction - jp c,AIUseHyperPotion - ld a,5 - call AICheckIfHPBelowFraction - ret nc - jp AISwitchIfEnoughMons - -BrockAI: ; 3a614 (e:6614) -; if his active monster has a status condition, use a full heal - ld a,[wEnemyMonStatus] - and a - ret z - jp AIUseFullHeal - -MistyAI: ; 3a61c (e:661c) - cp $40 - ret nc - jp AIUseXDefend - -LtSurgeAI: ; 3a622 (e:6622) - cp $40 - ret nc - jp AIUseXSpeed - -ErikaAI: ; 3a628 (e:6628) - cp $80 - ret nc - ld a,$A - call AICheckIfHPBelowFraction - ret nc - jp AIUseSuperPotion - -KogaAI: ; 3a634 (e:6634) - cp $40 - ret nc - jp AIUseXAttack - -BlaineAI: ; 3a63a (e:663a) - cp $40 - ret nc - jp AIUseSuperPotion - -SabrinaAI: ; 3a640 (e:6640) - cp $40 - ret nc - ld a,$A - call AICheckIfHPBelowFraction - ret nc - jp AIUseHyperPotion - -Sony2AI: ; 3a64c (e:664c) - cp $20 - ret nc - ld a,5 - call AICheckIfHPBelowFraction - ret nc - jp AIUsePotion - -Sony3AI: ; 3a658 (e:6658) - cp $20 - ret nc - ld a,5 - call AICheckIfHPBelowFraction - ret nc - jp AIUseFullRestore - -LoreleiAI: ; 3a664 (e:6664) - cp $80 - ret nc - ld a,5 - call AICheckIfHPBelowFraction - ret nc - jp AIUseSuperPotion - -BrunoAI: ; 3a670 (e:6670) - cp $40 - ret nc - jp AIUseXDefend - -AgathaAI: ; 3a676 (e:6676) - cp $14 - jp c,AISwitchIfEnoughMons - cp $80 - ret nc - ld a,4 - call AICheckIfHPBelowFraction - ret nc - jp AIUseSuperPotion - -LanceAI: ; 3a687 (e:6687) - cp $80 - ret nc - ld a,5 - call AICheckIfHPBelowFraction - ret nc - jp AIUseHyperPotion - -GenericAI: ; 3a693 (e:6693) - and a ; clear carry - ret - -; end of individual trainer AI routines - -DecrementAICount: ; 3a695 (e:6695) - ld hl,wAICount - dec [hl] - scf - ret - -Func_3a69b: ; 3a69b (e:669b) - ld a,(SFX_08_3e - SFX_Headers_08) / 3 - jp PlaySoundWaitForCurrent - -AIUseFullRestore: ; 3a6a0 (e:66a0) - call AICureStatus - ld a,FULL_RESTORE - ld [wcf05],a - ld de,wHPBarOldHP - ld hl,wEnemyMonHP + 1 - ld a,[hld] - ld [de],a - inc de - ld a,[hl] - ld [de],a - inc de - ld hl,wEnemyMonMaxHP + 1 - ld a,[hld] - ld [de],a - inc de - ld [wHPBarMaxHP],a - ld [wEnemyMonHP + 1],a - ld a,[hl] - ld [de],a - ld [wHPBarMaxHP+1],a - ld [wEnemyMonHP],a - jr AIPrintItemUseAndUpdateHPBar - -AIUsePotion: ; 3a6ca (e:66ca) -; enemy trainer heals his monster with a potion - ld a,POTION - ld b,20 - jr AIRecoverHP - -AIUseSuperPotion: ; 3a6d0 (e:66d0) -; enemy trainer heals his monster with a super potion - ld a,SUPER_POTION - ld b,50 - jr AIRecoverHP - -AIUseHyperPotion: ; 3a6d6 (e:66d6) -; enemy trainer heals his monster with a hyper potion - ld a,HYPER_POTION - ld b,200 - ; fallthrough - -AIRecoverHP: ; 3a6da (e:66da) -; heal b HP and print "trainer used $(a) on pokemon!" - ld [wcf05],a - ld hl,wEnemyMonHP + 1 - ld a,[hl] - ld [wHPBarOldHP],a - add b - ld [hld],a - ld [wHPBarNewHP],a - ld a,[hl] - ld [wHPBarOldHP+1],a - ld [wHPBarNewHP+1],a - jr nc,.next - inc a - ld [hl],a - ld [wHPBarNewHP+1],a -.next - inc hl - ld a,[hld] - ld b,a - ld de,wEnemyMonMaxHP + 1 - ld a,[de] - dec de - ld [wHPBarMaxHP],a - sub b - ld a,[hli] - ld b,a - ld a,[de] - ld [wHPBarMaxHP+1],a - sbc b - jr nc,AIPrintItemUseAndUpdateHPBar - inc de - ld a,[de] - dec de - ld [hld],a - ld [wHPBarNewHP],a - ld a,[de] - ld [hl],a - ld [wHPBarNewHP+1],a - ; fallthrough - -AIPrintItemUseAndUpdateHPBar: ; 3a718 (e:6718) - call AIPrintItemUse_ - hlCoord 2, 2 - xor a - ld [wHPBarType],a - predef UpdateHPBar2 - jp DecrementAICount - -AISwitchIfEnoughMons: ; 3a72a (e:672a) -; enemy trainer switches if there are 3 or more unfainted mons in party - ld a,[wEnemyPartyCount] - ld c,a - ld hl,wEnemyMon1HP - - ld d,0 ; keep count of unfainted monsters - - ; count how many monsters haven't fainted yet -.loop - ld a,[hli] - ld b,a - ld a,[hld] - or b - jr z,.Fainted ; has monster fainted? - inc d -.Fainted - push bc - ld bc,$2C - add hl,bc - pop bc - dec c - jr nz,.loop - - ld a,d ; how many available monsters are there? - cp 2 ; don't bother if only 1 or 2 - jp nc,SwitchEnemyMon - and a - ret - -SwitchEnemyMon: ; 3a74b (e:674b) - -; prepare to withdraw the active monster: copy hp, number, and status to roster - - ld a,[wEnemyMonPartyPos] - ld hl,wEnemyMon1HP - ld bc,wEnemyMon2 - wEnemyMon1 - call AddNTimes - ld d,h - ld e,l - ld hl,wEnemyMonHP - ld bc,4 - call CopyData - - ld hl, AIBattleWithdrawText - call PrintText - - ld a,1 - ld [wd11d],a - callab EnemySendOut - xor a - ld [wd11d],a - - ld a,[wLinkState] - cp LINK_STATE_BATTLING - ret z - scf - ret - -AIBattleWithdrawText: ; 3a781 (e:6781) - TX_FAR _AIBattleWithdrawText - db "@" - -AIUseFullHeal: ; 3a786 (e:6786) - call Func_3a69b - call AICureStatus - ld a,FULL_HEAL - jp AIPrintItemUse - -AICureStatus: ; 3a791 (e:6791) -; cures the status of enemy's active pokemon - ld a,[wEnemyMonPartyPos] - ld hl,wEnemyMon1Status - ld bc,wEnemyMon2 - wEnemyMon1 - call AddNTimes - xor a - ld [hl],a ; clear status in enemy team roster - ld [wEnemyMonStatus],a ; clear status of active enemy - ld hl,W_ENEMYBATTSTATUS3 - res 0,[hl] - ret - -AIUseXAccuracy: ; 0x3a7a8 unused - call Func_3a69b - ld hl,W_ENEMYBATTSTATUS2 - set 0,[hl] - ld a,X_ACCURACY - jp AIPrintItemUse - -AIUseGuardSpec: ; 3a7b5 (e:67b5) - call Func_3a69b - ld hl,W_ENEMYBATTSTATUS2 - set 1,[hl] - ld a,GUARD_SPEC_ - jp AIPrintItemUse - -AIUseDireHit: ; 0x3a7c2 unused - call Func_3a69b - ld hl,W_ENEMYBATTSTATUS2 - set 2,[hl] - ld a,DIRE_HIT - jp AIPrintItemUse - -AICheckIfHPBelowFraction: ; 3a7cf (e:67cf) -; return carry if enemy trainer's current HP is below 1 / a of the maximum - ld [H_DIVISOR],a - ld hl,wEnemyMonMaxHP - ld a,[hli] - ld [H_DIVIDEND],a - ld a,[hl] - ld [H_DIVIDEND + 1],a - ld b,2 - call Divide - ld a,[H_QUOTIENT + 3] - ld c,a - ld a,[H_QUOTIENT + 2] - ld b,a - ld hl,wEnemyMonHP + 1 - ld a,[hld] - ld e,a - ld a,[hl] - ld d,a - ld a,d - sub b - ret nz - ld a,e - sub c - ret - -AIUseXAttack: ; 3a7f2 (e:67f2) - ld b,$A - ld a,X_ATTACK - jr AIIncreaseStat - -AIUseXDefend: ; 3a7f8 (e:67f8) - ld b,$B - ld a,X_DEFEND - jr AIIncreaseStat - -AIUseXSpeed: ; 3a7fe (e:67fe) - ld b,$C - ld a,X_SPEED - jr AIIncreaseStat - -AIUseXSpecial: ; 3a804 (e:6804) - ld b,$D - ld a,X_SPECIAL - ; fallthrough - -AIIncreaseStat: ; 3a808 (e:6808) - ld [wcf05],a - push bc - call AIPrintItemUse_ - pop bc - ld hl,W_ENEMYMOVEEFFECT - ld a,[hld] - push af - ld a,[hl] - push af - push hl - ld a,$AF - ld [hli],a - ld [hl],b - callab StatModifierUpEffect - pop hl - pop af - ld [hli],a - pop af - ld [hl],a - jp DecrementAICount - -AIPrintItemUse: ; 3a82c (e:682c) - ld [wcf05],a - call AIPrintItemUse_ - jp DecrementAICount - -AIPrintItemUse_: ; 3a835 (e:6835) -; print "x used [wcf05] on z!" - ld a,[wcf05] - ld [wd11e],a - call GetItemName - ld hl, AIBattleUseItemText - jp PrintText - -AIBattleUseItemText: ; 3a844 (e:6844) - TX_FAR _AIBattleUseItemText - db "@" diff --git a/engine/battle/trainer_pic_money_pointers.asm b/engine/battle/trainer_pic_money_pointers.asm new file mode 100644 index 00000000..3d32eb00 --- /dev/null +++ b/engine/battle/trainer_pic_money_pointers.asm @@ -0,0 +1,143 @@ +TrainerPicAndMoneyPointers: ; 39914 (e:5914) +; trainer pic pointers and base money. +; money received after battle = base money × level of highest-level enemy mon + dw YoungsterPic + money 1500 + + dw BugCatcherPic + money 1000 + + dw LassPic + money 1500 + + dw SailorPic + money 3000 + + dw JrTrainerMPic + money 2000 + + dw JrTrainerFPic + money 2000 + + dw PokemaniacPic + money 5000 + + dw SuperNerdPic + money 2500 + + dw HikerPic + money 3500 + + dw BikerPic + money 2000 + + dw BurglarPic + money 9000 + + dw EngineerPic + money 5000 + + dw JugglerPic + money 3500 + + dw FisherPic + money 3500 + + dw SwimmerPic + money 500 + + dw CueBallPic + money 2500 + + dw GamblerPic + money 7000 + + dw BeautyPic + money 7000 + + dw PsychicPic + money 1000 + + dw RockerPic + money 2500 + + dw JugglerPic + money 3500 + + dw TamerPic + money 4000 + + dw BirdKeeperPic + money 2500 + + dw BlackbeltPic + money 2500 + + dw Rival1Pic + money 3500 + + dw ProfOakPic + money 9900 + + dw ChiefPic + money 3000 + + dw ScientistPic + money 5000 + + dw GiovanniPic + money 9900 + + dw RocketPic + money 3000 + + dw CooltrainerMPic + money 3500 + + dw CooltrainerFPic + money 3500 + + dw BrunoPic + money 9900 + + dw BrockPic + money 9900 + + dw MistyPic + money 9900 + + dw LtSurgePic + money 9900 + + dw ErikaPic + money 9900 + + dw KogaPic + money 9900 + + dw BlainePic + money 9900 + + dw SabrinaPic + money 9900 + + dw GentlemanPic + money 7000 + + dw Rival2Pic + money 6500 + + dw Rival3Pic + money 9900 + + dw LoreleiPic + money 9900 + + dw ChannelerPic + money 3000 + + dw AgathaPic + money 9900 + + dw LancePic + money 9900 \ No newline at end of file diff --git a/main.asm b/main.asm index 62d5940b..a3088c40 100755 --- a/main.asm +++ b/main.asm @@ -5465,7 +5465,7 @@ BaseStats: INCLUDE "data/base_stats.asm" INCLUDE "data/cries.asm" INCLUDE "engine/battle/unused_stats_functions.asm" INCLUDE "engine/battle/scroll_draw_trainer_pic.asm" -INCLUDE "engine/battle/trainer_party_ai_misc.asm" +INCLUDE "engine/battle/trainer_ai.asm" INCLUDE "engine/battle/draw_hud_pokeball_gfx.asm" TradingAnimationGraphics: -- cgit v1.3.1-sl0p