ref: e74dce24b4bbb0d0d23a1724932b289050b66d4a
parent: 9d93b5b630eaabd57f213c9dc5761223ff7445ec
author: xCrystal <rgr.crystal@gmail.com>
date: Wed Apr 1 07:23:27 EDT 2015
Rename battle files and split move effects Part 1 1.asm, 4.asm, and 4_2.asm
--- a/engine/battle/1.asm
+++ /dev/null
@@ -1,104 +1,0 @@
-DrainHPEffect_: ; 783f (1:783f)
- ld hl, W_DAMAGE
- ld a, [hl]
- srl a ; divide damage by 2
- ld [hli], a
- ld a, [hl]
- rr a
- ld [hld], a
- or [hl] ; is damage 0?
- jr nz, .getAttackerHP
-; if damage is 0, increase to 1 so that the attacker gains at least 1 HP
- inc hl
- inc [hl]
-.getAttackerHP
- ld hl, wBattleMonHP
- ld de, wBattleMonMaxHP
- ld a, [H_WHOSETURN]
- and a
- jp z, .addDamageToAttackerHP
- ld hl, wEnemyMonHP
- ld de, wEnemyMonMaxHP
-.addDamageToAttackerHP
- ld bc, wHPBarOldHP+1
-; copy current HP to wHPBarOldHP
- ld a, [hli]
- ld [bc], a
- ld a, [hl]
- dec bc
- ld [bc], a
-; copy max HP to wHPBarMaxHP
- ld a, [de]
- dec bc
- ld [bc], a
- inc de
- ld a, [de]
- dec bc
- ld [bc], a
-; add damage to attacker's HP and copy new HP to wHPBarNewHP
- ld a, [W_DAMAGE + 1]
- ld b, [hl]
- add b
- ld [hld], a
- ld [wHPBarNewHP], a
- ld a, [W_DAMAGE]
- ld b, [hl]
- adc b
- ld [hli], a
- ld [wHPBarNewHP+1], a
- jr c, .capToMaxHP ; if HP > 65,535, cap to max HP
-; compare HP with max HP
- ld a, [hld]
- ld b, a
- ld a, [de]
- dec de
- sub b
- ld a, [hli]
- ld b, a
- ld a, [de]
- inc de
- sbc b
- jr nc, .next
-.capToMaxHP
- ld a, [de]
- ld [hld], a
- ld [wHPBarNewHP], a
- dec de
- ld a, [de]
- ld [hli], a
- ld [wHPBarNewHP+1], a
- inc de
-.next
- ld a, [H_WHOSETURN]
- and a
- hlCoord 10, 9
- ld a, $1
- jr z, .next2
- hlCoord 2, 2
- xor a
-.next2
- ld [wHPBarType], a
- predef UpdateHPBar2
- predef DrawPlayerHUDAndHPBar
- predef DrawEnemyHUDAndHPBar
- callab ReadPlayerMonCurHPAndStatus
- ld hl, SuckedHealthText
- ld a, [H_WHOSETURN]
- and a
- ld a, [W_PLAYERMOVEEFFECT]
- jr z, .next3
- ld a, [W_ENEMYMOVEEFFECT]
-.next3
- cp DREAM_EATER_EFFECT
- jr nz, .printText
- ld hl, DreamWasEatenText
-.printText
- jp PrintText
-
-SuckedHealthText: ; 78dc (1:78dc)
- TX_FAR _SuckedHealthText
- db "@"
-
-DreamWasEatenText: ; 78e1 (1:78e1)
- TX_FAR _DreamWasEatenText
- db "@"
--- a/engine/battle/4.asm
+++ /dev/null
@@ -1,77 +1,0 @@
-; returns whether the player is one tile outside the map in Z
-IsPlayerJustOutsideMap: ; 128d8 (4:68d8)
- ld a, [W_YCOORD]
- ld b, a
- ld a, [W_CURMAPHEIGHT]
- call .compareCoordWithMapDimension
- ret z
- ld a, [W_XCOORD]
- ld b, a
- ld a, [W_CURMAPWIDTH]
-.compareCoordWithMapDimension
- add a
- cp b
- ret z
- inc b
- ret
-
-DrawHP: ; 128ef (4:68ef)
- call GetPredefRegisters
- ld a, $1
- jr DrawHP_
-
-DrawHP2: ; 128f6 (4:68f6)
- call GetPredefRegisters
- ld a, $2
-
-DrawHP_: ; 128fb (4:68fb)
- ld [wHPBarType], a
- push hl
- ld a, [wLoadedMonHP]
- ld b, a
- ld a, [wLoadedMonHP + 1]
- ld c, a
- or b
- jr nz, .nonzeroHP
- xor a
- ld c, a
- ld e, a
- ld a, $6
- ld d, a
- jp .drawHPBarAndPrintFraction
-.nonzeroHP
- ld a, [wLoadedMonMaxHP]
- ld d, a
- ld a, [wLoadedMonMaxHP + 1]
- ld e, a
- predef HPBarLength
- ld a, $6
- ld d, a
- ld c, a
-.drawHPBarAndPrintFraction
- pop hl
- push de
- push hl
- push hl
- call DrawHPBar
- pop hl
- ld a, [hFlags_0xFFF6]
- bit 0, a
- jr z, .printFractionBelowBar
- ld bc, $9 ; right of bar
- jr .printFraction
-.printFractionBelowBar
- ld bc, SCREEN_WIDTH + 1 ; below bar
-.printFraction
- add hl, bc
- ld de, wLoadedMonHP
- ld bc, $203
- call PrintNumber
- ld a, "/"
- ld [hli], a
- ld de, wLoadedMonMaxHP
- ld bc, $203
- call PrintNumber
- pop hl
- pop de
- ret
--- a/engine/battle/4_2.asm
+++ /dev/null
@@ -1,413 +1,0 @@
-EndOfBattle: ; 137aa (4:77aa)
- ld a, [wLinkState]
- cp LINK_STATE_BATTLING
- jr nz, .notLinkBattle
-; link battle
- ld a, [wEnemyMonPartyPos]
- ld hl, wEnemyMon1Status
- ld bc, wEnemyMon2 - wEnemyMon1
- call AddNTimes
- ld a, [wEnemyMonStatus]
- ld [hl], a
- call ClearScreen
- callab DisplayLinkBattleVersusTextBox
- ld a, [wBattleResult]
- cp $1
- ld de, YouWinText
- jr c, .placeWinOrLoseString
- ld de, YouLoseText
- jr z, .placeWinOrLoseString
- ld de, DrawText
-.placeWinOrLoseString
- hlCoord 6, 8
- call PlaceString
- ld c, $c8
- call DelayFrames
- jr .evolution
-.notLinkBattle
- ld a, [wBattleResult]
- and a
- jr nz, .resetVariables
- ld hl, wTotalPayDayMoney
- ld a, [hli]
- or [hl]
- inc hl
- or [hl]
- jr z, .evolution ; if pay day money is 0, jump
- ld de, wPlayerMoney + 2
- ld c, $3
- predef AddBCDPredef
- ld hl, PickUpPayDayMoneyText
- call PrintText
-.evolution
- xor a
- ld [wccd4], a
- predef EvolutionAfterBattle
-.resetVariables
- xor a
- ld [wLowHealthAlarm], a ;disable low health alarm
- ld [wc02a], a
- ld [W_ISINBATTLE], a
- ld [W_BATTLETYPE], a
- ld [W_MOVEMISSED], a
- ld [W_CUROPPONENT], a
- ld [wd11f], a
- ld [wNumRunAttempts], a
- ld [wEscapedFromBattle], a
- ld hl, wcc2b
- ld [hli], a
- ld [hli], a
- ld [hli], a
- ld [hl], a
- ld [wListScrollOffset], a
- ld hl, wPlayerStatsToDouble
- ld b, $18
-.loop
- ld [hli], a
- dec b
- jr nz, .loop
- ld hl, wd72c
- set 0, [hl]
- call WaitForSoundToFinish
- call GBPalWhiteOut
- ld a, $ff
- ld [wDestinationWarpID], a
- ret
-
-YouWinText: ; 13853 (4:7853)
- db "YOU WIN@"
-
-YouLoseText: ; 1385b (4:785b)
- db "YOU LOSE@"
-
-DrawText: ; 13864 (4:7864)
- db " DRAW@"
-
-PickUpPayDayMoneyText: ; 1386b (4:786b)
- TX_FAR _PickUpPayDayMoneyText
- db "@"
-
-; try to initiate a wild pokemon encounter
-; returns success in Z
-TryDoWildEncounter: ; 13870 (4:7870)
- ld a, [wNPCMovementScriptPointerTableNum]
- and a
- ret nz
- ld a, [wd736]
- and a
- ret nz
- callab IsPlayerStandingOnDoorTileOrWarpTile
- jr nc, .notStandingOnDoorOrWarpTile
-.CantEncounter
- ld a, $1
- and a
- ret
-.notStandingOnDoorOrWarpTile
- callab IsPlayerJustOutsideMap
- jr z, .CantEncounter
- ld a, [wRepelRemainingSteps]
- and a
- jr z, .asm_1389e
- dec a
- jr z, .lastRepelStep
- ld [wRepelRemainingSteps], a
-.asm_1389e
-; determine if wild pok�mon can appear in the half-block we�re standing in
-; is the bottom right tile (9,9) of the half-block we're standing in a grass/water tile?
- hlCoord 9, 9
- ld c, [hl]
- ld a, [W_GRASSTILE]
- cp c
- ld a, [W_GRASSRATE]
- jr z, .CanEncounter
- ld a, $14 ; in all tilesets with a water tile, this is its id
- cp c
- ld a, [W_WATERRATE]
- jr z, .CanEncounter
-; even if not in grass/water, standing anywhere we can encounter pok�mon
-; so long as the map is �indoor� and has wild pok�mon defined.
-; �as long as it�s not Viridian Forest or Safari Zone.
- ld a, [W_CURMAP]
- cp REDS_HOUSE_1F ; is this an indoor map?
- jr c, .CantEncounter2
- ld a, [W_CURMAPTILESET]
- cp FOREST ; Viridian Forest/Safari Zone
- jr z, .CantEncounter2
- ld a, [W_GRASSRATE]
-.CanEncounter
-; compare encounter chance with a random number to determine if there will be an encounter
- ld b, a
- ld a, [hRandomAdd]
- cp b
- jr nc, .CantEncounter2
- ld a, [hRandomSub]
- ld b, a
- ld hl, WildMonEncounterSlotChances
-.determineEncounterSlot
- ld a, [hli]
- cp b
- jr nc, .gotEncounterSlot
- inc hl
- jr .determineEncounterSlot
-.gotEncounterSlot
-; determine which wild pok�mon (grass or water) can appear in the half-block we�re standing in
- ld c, [hl]
- ld hl, W_GRASSMONS
- aCoord 8, 9
- cp $14 ; is the bottom left tile (8,9) of the half-block we're standing in a water tile?
- jr nz, .gotWildEncounterType ; else, it's treated as a grass tile by default
- ld hl, W_WATERMONS
-; since the bottom right tile of a "left shore" half-block is $14 but the bottom left tile is not,
-; "left shore" half-blocks (such as the one in the east coast of Cinnabar) load grass encounters.
-.gotWildEncounterType
- ld b, $0
- add hl, bc
- ld a, [hli]
- ld [W_CURENEMYLVL], a
- ld a, [hl]
- ld [wcf91], a
- ld [wEnemyMonSpecies2], a
- ld a, [wRepelRemainingSteps]
- and a
- jr z, .willEncounter
- ld a, [wPartyMon1Level]
- ld b, a
- ld a, [W_CURENEMYLVL]
- cp b
- jr c, .CantEncounter2 ; repel prevents encounters if the leading party mon's level is higher than the wild mon
- jr .willEncounter
-.lastRepelStep
- ld [wRepelRemainingSteps], a
- ld a, $d2
- ld [H_DOWNARROWBLINKCNT2], a
- call EnableAutoTextBoxDrawing
- call DisplayTextID
-.CantEncounter2
- ld a, $1
- and a
- ret
-.willEncounter
- xor a
- ret
-
-WildMonEncounterSlotChances: ; 13918 (4:7918)
-; There are 10 slots for wild pokemon, and this is the table that defines how common each of
-; those 10 slots is. A random number is generated and then the first byte of each pair in this
-; table is compared against that random number. If the random number is less than or equal
-; to the first byte, then that slot is chosen. The second byte is double the slot number.
- db $32, $00 ; 51/256 = 19.9% chance of slot 0
- db $65, $02 ; 51/256 = 19.9% chance of slot 1
- db $8C, $04 ; 39/256 = 15.2% chance of slot 2
- db $A5, $06 ; 25/256 = 9.8% chance of slot 3
- db $BE, $08 ; 25/256 = 9.8% chance of slot 4
- db $D7, $0A ; 25/256 = 9.8% chance of slot 5
- db $E4, $0C ; 13/256 = 5.1% chance of slot 6
- db $F1, $0E ; 13/256 = 5.1% chance of slot 7
- db $FC, $10 ; 11/256 = 4.3% chance of slot 8
- db $FF, $12 ; 3/256 = 1.2% chance of slot 9
-
-RecoilEffect_: ; 1392c (4:792c)
- ld a, [H_WHOSETURN]
- and a
- ld a, [W_PLAYERMOVENUM]
- ld hl, wBattleMonMaxHP
- jr z, .asm_1393d
- ld a, [W_ENEMYMOVENUM]
- ld hl, wEnemyMonMaxHP
-.asm_1393d
- ld d, a
- ld a, [W_DAMAGE]
- ld b, a
- ld a, [W_DAMAGE + 1]
- ld c, a
- srl b
- rr c
- ld a, d
- cp STRUGGLE
- jr z, .asm_13953
- srl b
- rr c
-.asm_13953
- ld a, b
- or c
- jr nz, .asm_13958
- inc c
-.asm_13958
- ld a, [hli]
- ld [wHPBarMaxHP+1], a
- ld a, [hl]
- ld [wHPBarMaxHP], a
- push bc
- ld bc, $fff2
- add hl, bc
- pop bc
- ld a, [hl]
- ld [wHPBarOldHP], a
- sub c
- ld [hld], a
- ld [wHPBarNewHP], a
- ld a, [hl]
- ld [wHPBarOldHP+1], a
- sbc b
- ld [hl], a
- ld [wHPBarNewHP+1], a
- jr nc, .asm_13982
- xor a
- ld [hli], a
- ld [hl], a
- ld hl, wHPBarNewHP
- ld [hli], a
- ld [hl], a
-.asm_13982
- hlCoord 10, 9
- ld a, [H_WHOSETURN]
- and a
- ld a, $1
- jr z, .asm_13990
- hlCoord 2, 2
- xor a
-.asm_13990
- ld [wHPBarType], a
- predef UpdateHPBar2
- ld hl, HitWithRecoilText
- jp PrintText
-HitWithRecoilText: ; 1399e (4:799e)
- TX_FAR _HitWithRecoilText
- db "@"
-
-ConversionEffect_: ; 139a3 (4:79a3)
- ld hl, wEnemyMonType1
- ld de, wBattleMonType1
- ld a, [H_WHOSETURN]
- and a
- ld a, [W_ENEMYBATTSTATUS1]
- jr z, .asm_139b8
- push hl
- ld h, d
- ld l, e
- pop de
- ld a, [W_PLAYERBATTSTATUS1]
-.asm_139b8
- bit Invulnerable, a ; is mon immune to typical attacks (dig/fly)
- jr nz, PrintButItFailedText
- ld a, [hli]
- ld [de], a
- inc de
- ld a, [hl]
- ld [de], a
- ld hl, PlayCurrentMoveAnimation
- call CallBankF
- ld hl, ConvertedTypeText
- jp PrintText
-
-ConvertedTypeText: ; 139cd (4:79cd)
- TX_FAR _ConvertedTypeText
- db "@"
-
-PrintButItFailedText: ; 139d2 (4:79d2)
- ld hl, PrintButItFailedText_
-CallBankF: ; 139d5 (4:79d5)
- ld b, BANK(PrintButItFailedText_)
- jp Bankswitch
-
-HazeEffect_: ; 139da (4:79da)
- ld a, $7
- ld hl, wPlayerMonAttackMod
- call ResetStatMods
- ld hl, wEnemyMonAttackMod
- call ResetStatMods
- ld hl, wPlayerMonUnmodifiedAttack
- ld de, wBattleMonAttack
- call ResetStats
- ld hl, wEnemyMonUnmodifiedAttack
- ld de, wEnemyMonAttack
- call ResetStats
- ld hl, wEnemyMonStatus
- ld de, wEnemySelectedMove
- ld a, [H_WHOSETURN]
- and a
- jr z, .asm_13a09
- ld hl, wBattleMonStatus
- dec de
-
-.asm_13a09
- ld a, [hl]
- ld [hl], $0
- and $27
- jr z, .asm_13a13
- ld a, $ff
- ld [de], a
-
-.asm_13a13
- xor a
- ld [W_PLAYERDISABLEDMOVE], a
- ld [W_ENEMYDISABLEDMOVE], a
- ld hl, wccee
- ld [hli], a
- ld [hl], a
- ld hl, W_PLAYERBATTSTATUS1
- call CureStatuses
- ld hl, W_ENEMYBATTSTATUS1
- call CureStatuses
- ld hl, PlayCurrentMoveAnimation
- call CallBankF
- ld hl, StatusChangesEliminatedText
- jp PrintText
-
-CureStatuses: ; 13a37 (4:7a37)
- res Confused, [hl]
- inc hl ; BATTSTATUS2
- ld a, [hl]
- and (1 << UsingRage) | (1 << NeedsToRecharge) | (1 << HasSubstituteUp) | (1 << 3) ; clear all but these from BATTSTATUS2
- ld [hli], a ; BATTSTATUS3
- ld a, [hl]
- and %11110000 | (1 << Transformed) ; clear Bad Poison, Reflect and Light Screen statuses
- ld [hl], a
- ret
-
-ResetStatMods: ; 13a43 (4:7a43)
- ld b, $8
-.loop
- ld [hli], a
- dec b
- jr nz, .loop
- ret
-
-ResetStats: ; 13a4a (4:7a4a)
- ld b, $8
-.loop
- ld a, [hli]
- ld [de], a
- inc de
- dec b
- jr nz, .loop
- ret
-
-StatusChangesEliminatedText: ; 13a53 (4:7a53)
- TX_FAR _StatusChangesEliminatedText
- db "@"
-
-GetTrainerName_: ; 13a58 (4:7a58)
- ld hl, W_GRASSRATE
- ld a, [wLinkState]
- and a
- jr nz, .rival
- ld hl, W_RIVALNAME
- ld a, [W_TRAINERCLASS]
- cp SONY1
- jr z, .rival
- cp SONY2
- jr z, .rival
- cp SONY3
- jr z, .rival
- ld [wd0b5], a
- ld a, TRAINER_NAME
- ld [wNameListType], a
- ld a, BANK(TrainerNames)
- ld [wPredefBank], a
- call GetName
- ld hl, wcd6d
-.rival
- ld de, W_TRAINERNAME
- ld bc, $d
- jp CopyData
--- a/engine/battle/animations.asm
+++ b/engine/battle/animations.asm
@@ -407,7 +407,7 @@
ld c,30
call DelayFrames
.next4
- call PlayApplyingAttackAnimation ; reload pic and flash the pic in and out (to show damage)
+ call PlayApplyingAttackAnimation ; shake the screen or flash the pic in and out (to show damage)
.AnimationFinished
call WaitForSoundToFinish
xor a
@@ -463,37 +463,37 @@
jp [hl]
AnimationTypePointerTable: ; 78dcf (1e:4dcf)
- dw ShakeScreenVertically ; enemy mon has used a non-damaging move
+ dw ShakeScreenVertically ; enemy mon has used a damaging move without a side effect
dw ShakeScreenHorizontallyHeavy ; enemy mon has used a damaging move with a side effect
- dw ShakeScreenHorizontallySlow ; enemy mon has used a damaging move without a side effect
- dw BlinkEnemyMonSprite ; player mon has used a non-damaging move
+ dw ShakeScreenHorizontallySlow ; enemy mon has used a non-damaging move
+ dw BlinkEnemyMonSprite ; player mon has used a damaging move without a side effect
dw ShakeScreenHorizontallyLight ; player mon has used a damaging move with a side effect
- dw ShakeScreenHorizontallySlow2 ; player mon has used a damaging move without a side effect
+ dw ShakeScreenHorizontallySlow2 ; player mon has used a non-damaging move
-ShakeScreenVertically: ; 78ddb (1e:4ddb)
+ShakeScreenVertically: ; 78ddb (1e:4ddb)
call PlayApplyingAttackSound
ld b, $8
jp AnimationShakeScreenVertically
-ShakeScreenHorizontallyHeavy: ; 78de3 (1e:4de3)
+ShakeScreenHorizontallyHeavy: ; 78de3 (1e:4de3)
call PlayApplyingAttackSound
ld b, $8
- jp AnimationShakeScreenHorizontallyFast
+ jp AnimationShakeScreenHorizontallyFast
-ShakeScreenHorizontallySlow: ; 78deb (1e:4deb)
+ShakeScreenHorizontallySlow: ; 78deb (1e:4deb)
ld bc, $602
- jr AnimationShakeScreenHorizontallySlow
+ jr AnimationShakeScreenHorizontallySlow
-BlinkEnemyMonSprite: ; 78df0 (1e:4df0)
+BlinkEnemyMonSprite: ; 78df0 (1e:4df0)
call PlayApplyingAttackSound
jp AnimationBlinkEnemyMon
-ShakeScreenHorizontallyLight: ; 78df6 (1e:4df6)
+ShakeScreenHorizontallyLight: ; 78df6 (1e:4df6)
call PlayApplyingAttackSound
ld b, $2
jp AnimationShakeScreenHorizontallyFast
-ShakeScreenHorizontallySlow2: ; 78dfe (1e:4dfe)
+ShakeScreenHorizontallySlow2: ; 78dfe (1e:4dfe)
ld bc, $302
AnimationShakeScreenHorizontallySlow: ; 78e01 (1e:4e01)
--- a/engine/battle/e.asm
+++ b/engine/battle/e.asm
@@ -335,7 +335,7 @@
ld a, [W_ENEMYMOVETYPE]
ld d, a
ld hl, wEnemyMonMoves ; enemy moves
- ld b, $5
+ ld b, NUM_MOVES + 1
ld c, $0
.loopMoves
dec b
--- /dev/null
+++ b/engine/battle/end_of_battle.asm
@@ -1,0 +1,88 @@
+EndOfBattle: ; 137aa (4:77aa)
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
+ jr nz, .notLinkBattle
+; link battle
+ ld a, [wEnemyMonPartyPos]
+ ld hl, wEnemyMon1Status
+ ld bc, wEnemyMon2 - wEnemyMon1
+ call AddNTimes
+ ld a, [wEnemyMonStatus]
+ ld [hl], a
+ call ClearScreen
+ callab DisplayLinkBattleVersusTextBox
+ ld a, [wBattleResult]
+ cp $1
+ ld de, YouWinText
+ jr c, .placeWinOrLoseString
+ ld de, YouLoseText
+ jr z, .placeWinOrLoseString
+ ld de, DrawText
+.placeWinOrLoseString
+ hlCoord 6, 8
+ call PlaceString
+ ld c, $c8
+ call DelayFrames
+ jr .evolution
+.notLinkBattle
+ ld a, [wBattleResult]
+ and a
+ jr nz, .resetVariables
+ ld hl, wTotalPayDayMoney
+ ld a, [hli]
+ or [hl]
+ inc hl
+ or [hl]
+ jr z, .evolution ; if pay day money is 0, jump
+ ld de, wPlayerMoney + 2
+ ld c, $3
+ predef AddBCDPredef
+ ld hl, PickUpPayDayMoneyText
+ call PrintText
+.evolution
+ xor a
+ ld [wccd4], a
+ predef EvolutionAfterBattle
+.resetVariables
+ xor a
+ ld [wLowHealthAlarm], a ;disable low health alarm
+ ld [wc02a], a
+ ld [W_ISINBATTLE], a
+ ld [W_BATTLETYPE], a
+ ld [W_MOVEMISSED], a
+ ld [W_CUROPPONENT], a
+ ld [wd11f], a
+ ld [wNumRunAttempts], a
+ ld [wEscapedFromBattle], a
+ ld hl, wcc2b
+ ld [hli], a
+ ld [hli], a
+ ld [hli], a
+ ld [hl], a
+ ld [wListScrollOffset], a
+ ld hl, wPlayerStatsToDouble
+ ld b, $18
+.loop
+ ld [hli], a
+ dec b
+ jr nz, .loop
+ ld hl, wd72c
+ set 0, [hl]
+ call WaitForSoundToFinish
+ call GBPalWhiteOut
+ ld a, $ff
+ ld [wDestinationWarpID], a
+ ret
+
+YouWinText: ; 13853 (4:7853)
+ db "YOU WIN@"
+
+YouLoseText: ; 1385b (4:785b)
+ db "YOU LOSE@"
+
+DrawText: ; 13864 (4:7864)
+ db " DRAW@"
+
+PickUpPayDayMoneyText: ; 1386b (4:786b)
+ TX_FAR _PickUpPayDayMoneyText
+ db "@"
\ No newline at end of file
--- /dev/null
+++ b/engine/battle/get_trainer_name.asm
@@ -1,0 +1,24 @@
+GetTrainerName_: ; 13a58 (4:7a58)
+ ld hl, W_GRASSRATE
+ ld a, [wLinkState]
+ and a
+ jr nz, .rival
+ ld hl, W_RIVALNAME
+ ld a, [W_TRAINERCLASS]
+ cp SONY1
+ jr z, .rival
+ cp SONY2
+ jr z, .rival
+ cp SONY3
+ jr z, .rival
+ ld [wd0b5], a
+ ld a, TRAINER_NAME
+ ld [wNameListType], a
+ ld a, BANK(TrainerNames)
+ ld [wPredefBank], a
+ call GetName
+ ld hl, wcd6d
+.rival
+ ld de, W_TRAINERNAME
+ ld bc, $d
+ jp CopyData
--- /dev/null
+++ b/engine/battle/moveEffects/conversion_effect.asm
@@ -1,0 +1,34 @@
+ConversionEffect_: ; 139a3 (4:79a3)
+ ld hl, wEnemyMonType1
+ ld de, wBattleMonType1
+ ld a, [H_WHOSETURN]
+ and a
+ ld a, [W_ENEMYBATTSTATUS1]
+ jr z, .asm_139b8
+ push hl
+ ld h, d
+ ld l, e
+ pop de
+ ld a, [W_PLAYERBATTSTATUS1]
+.asm_139b8
+ bit Invulnerable, a ; is mon immune to typical attacks (dig/fly)
+ jr nz, PrintButItFailedText
+ ld a, [hli]
+ ld [de], a
+ inc de
+ ld a, [hl]
+ ld [de], a
+ ld hl, PlayCurrentMoveAnimation
+ call CallBankF
+ ld hl, ConvertedTypeText
+ jp PrintText
+
+ConvertedTypeText: ; 139cd (4:79cd)
+ TX_FAR _ConvertedTypeText
+ db "@"
+
+PrintButItFailedText: ; 139d2 (4:79d2)
+ ld hl, PrintButItFailedText_
+CallBankF: ; 139d5 (4:79d5)
+ ld b, BANK(PrintButItFailedText_)
+ jp Bankswitch
--- /dev/null
+++ b/engine/battle/moveEffects/drain_hp_effect.asm
@@ -1,0 +1,104 @@
+DrainHPEffect_: ; 783f (1:783f)
+ ld hl, W_DAMAGE
+ ld a, [hl]
+ srl a ; divide damage by 2
+ ld [hli], a
+ ld a, [hl]
+ rr a
+ ld [hld], a
+ or [hl] ; is damage 0?
+ jr nz, .getAttackerHP
+; if damage is 0, increase to 1 so that the attacker gains at least 1 HP
+ inc hl
+ inc [hl]
+.getAttackerHP
+ ld hl, wBattleMonHP
+ ld de, wBattleMonMaxHP
+ ld a, [H_WHOSETURN]
+ and a
+ jp z, .addDamageToAttackerHP
+ ld hl, wEnemyMonHP
+ ld de, wEnemyMonMaxHP
+.addDamageToAttackerHP
+ ld bc, wHPBarOldHP+1
+; copy current HP to wHPBarOldHP
+ ld a, [hli]
+ ld [bc], a
+ ld a, [hl]
+ dec bc
+ ld [bc], a
+; copy max HP to wHPBarMaxHP
+ ld a, [de]
+ dec bc
+ ld [bc], a
+ inc de
+ ld a, [de]
+ dec bc
+ ld [bc], a
+; add damage to attacker's HP and copy new HP to wHPBarNewHP
+ ld a, [W_DAMAGE + 1]
+ ld b, [hl]
+ add b
+ ld [hld], a
+ ld [wHPBarNewHP], a
+ ld a, [W_DAMAGE]
+ ld b, [hl]
+ adc b
+ ld [hli], a
+ ld [wHPBarNewHP+1], a
+ jr c, .capToMaxHP ; if HP > 65,535, cap to max HP
+; compare HP with max HP
+ ld a, [hld]
+ ld b, a
+ ld a, [de]
+ dec de
+ sub b
+ ld a, [hli]
+ ld b, a
+ ld a, [de]
+ inc de
+ sbc b
+ jr nc, .next
+.capToMaxHP
+ ld a, [de]
+ ld [hld], a
+ ld [wHPBarNewHP], a
+ dec de
+ ld a, [de]
+ ld [hli], a
+ ld [wHPBarNewHP+1], a
+ inc de
+.next
+ ld a, [H_WHOSETURN]
+ and a
+ hlCoord 10, 9
+ ld a, $1
+ jr z, .next2
+ hlCoord 2, 2
+ xor a
+.next2
+ ld [wHPBarType], a
+ predef UpdateHPBar2
+ predef DrawPlayerHUDAndHPBar
+ predef DrawEnemyHUDAndHPBar
+ callab ReadPlayerMonCurHPAndStatus
+ ld hl, SuckedHealthText
+ ld a, [H_WHOSETURN]
+ and a
+ ld a, [W_PLAYERMOVEEFFECT]
+ jr z, .next3
+ ld a, [W_ENEMYMOVEEFFECT]
+.next3
+ cp DREAM_EATER_EFFECT
+ jr nz, .printText
+ ld hl, DreamWasEatenText
+.printText
+ jp PrintText
+
+SuckedHealthText: ; 78dc (1:78dc)
+ TX_FAR _SuckedHealthText
+ db "@"
+
+DreamWasEatenText: ; 78e1 (1:78e1)
+ TX_FAR _DreamWasEatenText
+ db "@"
--- /dev/null
+++ b/engine/battle/moveEffects/haze_effect.asm
@@ -1,0 +1,76 @@
+HazeEffect_: ; 139da (4:79da)
+ ld a, $7
+ ld hl, wPlayerMonAttackMod
+ call ResetStatMods
+ ld hl, wEnemyMonAttackMod
+ call ResetStatMods
+ ld hl, wPlayerMonUnmodifiedAttack
+ ld de, wBattleMonAttack
+ call ResetStats
+ ld hl, wEnemyMonUnmodifiedAttack
+ ld de, wEnemyMonAttack
+ call ResetStats
+ ld hl, wEnemyMonStatus
+ ld de, wEnemySelectedMove
+ ld a, [H_WHOSETURN]
+ and a
+ jr z, .asm_13a09
+ ld hl, wBattleMonStatus
+ dec de
+
+.asm_13a09
+ ld a, [hl]
+ ld [hl], $0
+ and $27
+ jr z, .asm_13a13
+ ld a, $ff
+ ld [de], a
+
+.asm_13a13
+ xor a
+ ld [W_PLAYERDISABLEDMOVE], a
+ ld [W_ENEMYDISABLEDMOVE], a
+ ld hl, wccee
+ ld [hli], a
+ ld [hl], a
+ ld hl, W_PLAYERBATTSTATUS1
+ call CureStatuses
+ ld hl, W_ENEMYBATTSTATUS1
+ call CureStatuses
+ ld hl, PlayCurrentMoveAnimation
+ call CallBankF
+ ld hl, StatusChangesEliminatedText
+ jp PrintText
+
+CureStatuses: ; 13a37 (4:7a37)
+ res Confused, [hl]
+ inc hl ; BATTSTATUS2
+ ld a, [hl]
+ and (1 << UsingRage) | (1 << NeedsToRecharge) | (1 << HasSubstituteUp) | (1 << 3) ; clear all but these from BATTSTATUS2
+ ld [hli], a ; BATTSTATUS3
+ ld a, [hl]
+ and %11110000 | (1 << Transformed) ; clear Bad Poison, Reflect and Light Screen statuses
+ ld [hl], a
+ ret
+
+ResetStatMods: ; 13a43 (4:7a43)
+ ld b, $8
+.loop
+ ld [hli], a
+ dec b
+ jr nz, .loop
+ ret
+
+ResetStats: ; 13a4a (4:7a4a)
+ ld b, $8
+.loop
+ ld a, [hli]
+ ld [de], a
+ inc de
+ dec b
+ jr nz, .loop
+ ret
+
+StatusChangesEliminatedText: ; 13a53 (4:7a53)
+ TX_FAR _StatusChangesEliminatedText
+ db "@"
--- /dev/null
+++ b/engine/battle/moveEffects/recoil_effect.asm
@@ -1,0 +1,68 @@
+RecoilEffect_: ; 1392c (4:792c)
+ ld a, [H_WHOSETURN]
+ and a
+ ld a, [W_PLAYERMOVENUM]
+ ld hl, wBattleMonMaxHP
+ jr z, .asm_1393d
+ ld a, [W_ENEMYMOVENUM]
+ ld hl, wEnemyMonMaxHP
+.asm_1393d
+ ld d, a
+ ld a, [W_DAMAGE]
+ ld b, a
+ ld a, [W_DAMAGE + 1]
+ ld c, a
+ srl b
+ rr c
+ ld a, d
+ cp STRUGGLE
+ jr z, .asm_13953
+ srl b
+ rr c
+.asm_13953
+ ld a, b
+ or c
+ jr nz, .asm_13958
+ inc c
+.asm_13958
+ ld a, [hli]
+ ld [wHPBarMaxHP+1], a
+ ld a, [hl]
+ ld [wHPBarMaxHP], a
+ push bc
+ ld bc, $fff2
+ add hl, bc
+ pop bc
+ ld a, [hl]
+ ld [wHPBarOldHP], a
+ sub c
+ ld [hld], a
+ ld [wHPBarNewHP], a
+ ld a, [hl]
+ ld [wHPBarOldHP+1], a
+ sbc b
+ ld [hl], a
+ ld [wHPBarNewHP+1], a
+ jr nc, .asm_13982
+ xor a
+ ld [hli], a
+ ld [hl], a
+ ld hl, wHPBarNewHP
+ ld [hli], a
+ ld [hl], a
+.asm_13982
+ hlCoord 10, 9
+ ld a, [H_WHOSETURN]
+ and a
+ ld a, $1
+ jr z, .asm_13990
+ hlCoord 2, 2
+ xor a
+.asm_13990
+ ld [wHPBarType], a
+ predef UpdateHPBar2
+ ld hl, HitWithRecoilText
+ jp PrintText
+HitWithRecoilText: ; 1399e (4:799e)
+ TX_FAR _HitWithRecoilText
+ db "@"
--- /dev/null
+++ b/engine/battle/wild_encounters.asm
@@ -1,0 +1,118 @@
+; try to initiate a wild pokemon encounter
+; returns success in Z
+TryDoWildEncounter: ; 13870 (4:7870)
+ ld a, [wNPCMovementScriptPointerTableNum]
+ and a
+ ret nz
+ ld a, [wd736]
+ and a
+ ret nz
+ callab IsPlayerStandingOnDoorTileOrWarpTile
+ jr nc, .notStandingOnDoorOrWarpTile
+.CantEncounter
+ ld a, $1
+ and a
+ ret
+.notStandingOnDoorOrWarpTile
+ callab IsPlayerJustOutsideMap
+ jr z, .CantEncounter
+ ld a, [wRepelRemainingSteps]
+ and a
+ jr z, .asm_1389e
+ dec a
+ jr z, .lastRepelStep
+ ld [wRepelRemainingSteps], a
+.asm_1389e
+; determine if wild pok�mon can appear in the half-block we�re standing in
+; is the bottom right tile (9,9) of the half-block we're standing in a grass/water tile?
+ hlCoord 9, 9
+ ld c, [hl]
+ ld a, [W_GRASSTILE]
+ cp c
+ ld a, [W_GRASSRATE]
+ jr z, .CanEncounter
+ ld a, $14 ; in all tilesets with a water tile, this is its id
+ cp c
+ ld a, [W_WATERRATE]
+ jr z, .CanEncounter
+; even if not in grass/water, standing anywhere we can encounter pok�mon
+; so long as the map is �indoor� and has wild pok�mon defined.
+; �as long as it�s not Viridian Forest or Safari Zone.
+ ld a, [W_CURMAP]
+ cp REDS_HOUSE_1F ; is this an indoor map?
+ jr c, .CantEncounter2
+ ld a, [W_CURMAPTILESET]
+ cp FOREST ; Viridian Forest/Safari Zone
+ jr z, .CantEncounter2
+ ld a, [W_GRASSRATE]
+.CanEncounter
+; compare encounter chance with a random number to determine if there will be an encounter
+ ld b, a
+ ld a, [hRandomAdd]
+ cp b
+ jr nc, .CantEncounter2
+ ld a, [hRandomSub]
+ ld b, a
+ ld hl, WildMonEncounterSlotChances
+.determineEncounterSlot
+ ld a, [hli]
+ cp b
+ jr nc, .gotEncounterSlot
+ inc hl
+ jr .determineEncounterSlot
+.gotEncounterSlot
+; determine which wild pok�mon (grass or water) can appear in the half-block we�re standing in
+ ld c, [hl]
+ ld hl, W_GRASSMONS
+ aCoord 8, 9
+ cp $14 ; is the bottom left tile (8,9) of the half-block we're standing in a water tile?
+ jr nz, .gotWildEncounterType ; else, it's treated as a grass tile by default
+ ld hl, W_WATERMONS
+; since the bottom right tile of a "left shore" half-block is $14 but the bottom left tile is not,
+; "left shore" half-blocks (such as the one in the east coast of Cinnabar) load grass encounters.
+.gotWildEncounterType
+ ld b, $0
+ add hl, bc
+ ld a, [hli]
+ ld [W_CURENEMYLVL], a
+ ld a, [hl]
+ ld [wcf91], a
+ ld [wEnemyMonSpecies2], a
+ ld a, [wRepelRemainingSteps]
+ and a
+ jr z, .willEncounter
+ ld a, [wPartyMon1Level]
+ ld b, a
+ ld a, [W_CURENEMYLVL]
+ cp b
+ jr c, .CantEncounter2 ; repel prevents encounters if the leading party mon's level is higher than the wild mon
+ jr .willEncounter
+.lastRepelStep
+ ld [wRepelRemainingSteps], a
+ ld a, $d2
+ ld [H_DOWNARROWBLINKCNT2], a
+ call EnableAutoTextBoxDrawing
+ call DisplayTextID
+.CantEncounter2
+ ld a, $1
+ and a
+ ret
+.willEncounter
+ xor a
+ ret
+
+WildMonEncounterSlotChances: ; 13918 (4:7918)
+; There are 10 slots for wild pokemon, and this is the table that defines how common each of
+; those 10 slots is. A random number is generated and then the first byte of each pair in this
+; table is compared against that random number. If the random number is less than or equal
+; to the first byte, then that slot is chosen. The second byte is double the slot number.
+ db $32, $00 ; 51/256 = 19.9% chance of slot 0
+ db $65, $02 ; 51/256 = 19.9% chance of slot 1
+ db $8C, $04 ; 39/256 = 15.2% chance of slot 2
+ db $A5, $06 ; 25/256 = 9.8% chance of slot 3
+ db $BE, $08 ; 25/256 = 9.8% chance of slot 4
+ db $D7, $0A ; 25/256 = 9.8% chance of slot 5
+ db $E4, $0C ; 13/256 = 5.1% chance of slot 6
+ db $F1, $0E ; 13/256 = 5.1% chance of slot 7
+ db $FC, $10 ; 11/256 = 4.3% chance of slot 8
+ db $FF, $12 ; 3/256 = 1.2% chance of slot 9
--- a/engine/menu/status_screen.asm
+++ b/engine/menu/status_screen.asm
@@ -1,3 +1,67 @@
+DrawHP: ; 128ef (4:68ef)
+; Draws the HP bar in the stats screen
+ call GetPredefRegisters
+ ld a, $1
+ jr DrawHP_
+
+DrawHP2: ; 128f6 (4:68f6)
+; Draws the HP bar in the party screen
+ call GetPredefRegisters
+ ld a, $2
+
+DrawHP_: ; 128fb (4:68fb)
+ ld [wHPBarType], a
+ push hl
+ ld a, [wLoadedMonHP]
+ ld b, a
+ ld a, [wLoadedMonHP + 1]
+ ld c, a
+ or b
+ jr nz, .nonzeroHP
+ xor a
+ ld c, a
+ ld e, a
+ ld a, $6
+ ld d, a
+ jp .drawHPBarAndPrintFraction
+.nonzeroHP
+ ld a, [wLoadedMonMaxHP]
+ ld d, a
+ ld a, [wLoadedMonMaxHP + 1]
+ ld e, a
+ predef HPBarLength
+ ld a, $6
+ ld d, a
+ ld c, a
+.drawHPBarAndPrintFraction
+ pop hl
+ push de
+ push hl
+ push hl
+ call DrawHPBar
+ pop hl
+ ld a, [hFlags_0xFFF6]
+ bit 0, a
+ jr z, .printFractionBelowBar
+ ld bc, $9 ; right of bar
+ jr .printFraction
+.printFractionBelowBar
+ ld bc, SCREEN_WIDTH + 1 ; below bar
+.printFraction
+ add hl, bc
+ ld de, wLoadedMonHP
+ ld bc, $203
+ call PrintNumber
+ ld a, "/"
+ ld [hli], a
+ ld de, wLoadedMonMaxHP
+ ld bc, $203
+ call PrintNumber
+ pop hl
+ pop de
+ ret
+
+
; Predef 0x37
StatusScreen: ; 12953 (4:6953)
call LoadMonData
--- /dev/null
+++ b/engine/overworld/is_player_just_outside_map.asm
@@ -1,0 +1,16 @@
+; returns whether the player is one tile outside the map in Z
+IsPlayerJustOutsideMap: ; 128d8 (4:68d8)
+ ld a, [W_YCOORD]
+ ld b, a
+ ld a, [W_CURMAPHEIGHT]
+ call .compareCoordWithMapDimension
+ ret z
+ ld a, [W_XCOORD]
+ ld b, a
+ ld a, [W_CURMAPWIDTH]
+.compareCoordWithMapDimension
+ add a
+ cp b
+ ret z
+ inc b
+ ret
--- a/main.asm
+++ b/main.asm
@@ -1907,7 +1907,7 @@
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 @@
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 @@
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"