summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--audio/engine.asm4
-rw-r--r--battle/ai/items.asm8
-rwxr-xr-xbattle/ai/move.asm2
-rw-r--r--battle/anim_commands.asm18
-rw-r--r--battle/anim_gfx.asm10
-rw-r--r--battle/anims.asm44
-rw-r--r--battle/core.asm59
-rw-r--r--battle/effect_commands.asm8
-rw-r--r--battle/moves/move_effects.asm2
-rwxr-xr-xbattle/objects/data.asm10
-rwxr-xr-xbattle/objects/gfx_headers.asm10
-rw-r--r--constants/animation_constants.asm53
-rwxr-xr-xconstants/battle_tower_constants.asm4
-rw-r--r--constants/event_flags.asm2
-rw-r--r--constants/gfx_constants.asm42
-rw-r--r--constants/map_constants.asm2
-rw-r--r--constants/map_setup_constants.asm2
-rwxr-xr-xengine/anim_hp_bar.asm137
-rw-r--r--engine/battle_start.asm12
-rwxr-xr-xengine/billspctop.asm388
-rw-r--r--engine/color.asm374
-rwxr-xr-xengine/health.asm110
-rwxr-xr-xengine/init_gender.asm2
-rwxr-xr-xengine/items.asm584
-rwxr-xr-xengine/main_menu.asm2
-rw-r--r--engine/map_setup.asm2
-rwxr-xr-xengine/mon_icons.asm25
-rw-r--r--engine/movement.asm8
-rwxr-xr-xengine/namingscreen.asm6
-rw-r--r--engine/party_menu.asm8
-rw-r--r--engine/phone.asm11
-rwxr-xr-xengine/player_movement.asm4
-rwxr-xr-xengine/player_object.asm856
-rwxr-xr-xengine/pokecenter_pc.asm247
-rwxr-xr-xengine/pokegear.asm23
-rwxr-xr-xengine/printnum.asm300
-rwxr-xr-xengine/scrolling_menu.asm6
-rwxr-xr-xengine/sine.asm50
-rwxr-xr-xengine/startmenu.asm88
-rwxr-xr-xengine/tile_events.asm10
-rwxr-xr-xengine/time.asm4
-rwxr-xr-xengine/trade/animation.asm2
-rwxr-xr-xevent/happiness_egg.asm238
-rw-r--r--event/mom.asm2
-rwxr-xr-xevent/overworld.asm1890
-rw-r--r--event/poke_seer.asm1
-rwxr-xr-xevent/special.asm231
m---------extras0
-rw-r--r--home.asm2
-rw-r--r--home/map.asm11
-rw-r--r--home/menu.asm10
-rw-r--r--home/movement.asm4
-rw-r--r--items/item_effects.asm4
-rwxr-xr-xitems/pokeball_wobble.asm88
-rw-r--r--macros/move_effect.asm350
-rw-r--r--macros/movement.asm10
-rw-r--r--macros/sound.asm2
-rw-r--r--main.asm4762
-rw-r--r--maps/BattleTower1F.asm4
-rw-r--r--maps/BlackthornGym2F.asm10
-rw-r--r--maps/BurnedTowerB1F.asm24
-rw-r--r--maps/CianwoodGym.asm80
-rw-r--r--maps/IcePathB1F.asm12
-rw-r--r--maps/LancesRoom.asm92
-rw-r--r--maps/Route36.asm60
-rw-r--r--maps/TinTower1F.asm20
-rwxr-xr-xmisc/battle_tower_5c.asm20
-rwxr-xr-xmisc/mobile_12_2.asm2
-rw-r--r--misc/mobile_22.asm6
-rw-r--r--misc/mobile_22_2.asm2
-rw-r--r--misc/mobile_40.asm2
-rwxr-xr-xmisc/mobile_46.asm8
-rw-r--r--sram.asm14
-rw-r--r--wram.asm48
74 files changed, 5726 insertions, 5822 deletions
diff --git a/audio/engine.asm b/audio/engine.asm
index ad03c16a5..d01d74c7d 100644
--- a/audio/engine.asm
+++ b/audio/engine.asm
@@ -38,8 +38,8 @@ _MapSetup_Sound_Off:: ; e8000
dec e
jr nz, .clearsound
- ld hl, Channel1 ; start of channel data
- ld de, $1bf ; length of area to clear (entire sound wram area)
+ ld hl, Channels ; start of channel data
+ ld de, ChannelsEnd - Channels ; length of area to clear (entire sound wram area)
.clearchannels ; clear Channel1-$c2bf
xor a
ld [hli], a
diff --git a/battle/ai/items.asm b/battle/ai/items.asm
index f5d22d786..c7c8f8201 100644
--- a/battle/ai/items.asm
+++ b/battle/ai/items.asm
@@ -9,7 +9,7 @@ AI_SwitchOrTryItem: ; 38000
and a
ret nz
- callba CheckSubstatus_RechargeChargedRampageBideRollout
+ callba CheckEnemyLockedIn
ret nz
ld a, [PlayerSubStatus5]
@@ -716,7 +716,7 @@ AI_Switch: ; 3846c
ld d, h
ld e, l
ld hl, EnemyMonStatus
- ld bc, $0004
+ ld bc, MON_MAXHP - MON_STATUS
call CopyBytes
pop af
@@ -726,7 +726,7 @@ AI_Switch: ; 3846c
.skiptext
ld a, 1
- ld [wd264], a
+ ld [wAISwitch], a
callab NewEnemyMonStatus
callab ResetEnemyStatLevels
ld hl, PlayerSubStatus1
@@ -734,7 +734,7 @@ AI_Switch: ; 3846c
callba EnemySwitch
callba ResetBattleParticipants
xor a
- ld [wd264], a
+ ld [wAISwitch], a
ld a, [wLinkMode]
and a
ret nz
diff --git a/battle/ai/move.asm b/battle/ai/move.asm
index 5f58bae3e..eb6a0536d 100755
--- a/battle/ai/move.asm
+++ b/battle/ai/move.asm
@@ -12,7 +12,7 @@ AIChooseMove: ; 440ce
ret nz
; No use picking a move if there's no choice.
- callba CheckSubstatus_RechargeChargedRampageBideRollout
+ callba CheckEnemyLockedIn
ret nz
diff --git a/battle/anim_commands.asm b/battle/anim_commands.asm
index 266b76af2..48dc9c433 100644
--- a/battle/anim_commands.asm
+++ b/battle/anim_commands.asm
@@ -980,7 +980,7 @@ BattleAnimCmd_RaiseSub: ; cc640 (33:4640)
GetSubstitutePic: ; cc64c
ld hl, sScratch
- ld bc, $310
+ ld bc, (7 * 7) tiles
.loop
xor a
ld [hli], a
@@ -994,16 +994,16 @@ GetSubstitutePic: ; cc64c
jr z, .player
ld hl, MonsterSpriteGFX + 0 tiles
- ld de, sScratch + $13 tiles
+ ld de, sScratch + (2 * 7 + 5) tiles
call .CopyTile
ld hl, MonsterSpriteGFX + 1 tiles
- ld de, sScratch + $1a tiles
+ ld de, sScratch + (3 * 7 + 5) tiles
call .CopyTile
ld hl, MonsterSpriteGFX + 2 tiles
- ld de, sScratch + $14 tiles
+ ld de, sScratch + (2 * 7 + 6) tiles
call .CopyTile
ld hl, MonsterSpriteGFX + 3 tiles
- ld de, sScratch + $1b tiles
+ ld de, sScratch + (3 * 7 + 6) tiles
call .CopyTile
ld hl, VTiles2 tile $00
@@ -1014,16 +1014,16 @@ GetSubstitutePic: ; cc64c
.player
ld hl, MonsterSpriteGFX + 4 tiles
- ld de, sScratch + $10 tiles
+ ld de, sScratch + (2 * 6 + 4) tiles
call .CopyTile
ld hl, MonsterSpriteGFX + 5 tiles
- ld de, sScratch + $16 tiles
+ ld de, sScratch + (3 * 6 + 4) tiles
call .CopyTile
ld hl, MonsterSpriteGFX + 6 tiles
- ld de, sScratch + $11 tiles
+ ld de, sScratch + (2 * 6 + 5) tiles
call .CopyTile
ld hl, MonsterSpriteGFX + 7 tiles
- ld de, sScratch + $17 tiles
+ ld de, sScratch + (3 * 6 + 5) tiles
call .CopyTile
ld hl, VTiles2 tile $31
diff --git a/battle/anim_gfx.asm b/battle/anim_gfx.asm
index c84dda83f..996c17f1e 100644
--- a/battle/anim_gfx.asm
+++ b/battle/anim_gfx.asm
@@ -1,9 +1,9 @@
AnimObj00GFX: ; 84a2e
-AnimObj01GFX: INCBIN "gfx/fx/001.2bpp.lz"
-AnimObj02GFX: INCBIN "gfx/fx/002.2bpp.lz"
-AnimObj03GFX: INCBIN "gfx/fx/003.2bpp.lz"
-AnimObj04GFX: INCBIN "gfx/fx/004.2bpp.lz"
-AnimObj05GFX: INCBIN "gfx/fx/005.2bpp.lz"
+AnimObjHitGFX: INCBIN "gfx/fx/001.2bpp.lz"
+AnimObjCutGFX: INCBIN "gfx/fx/002.2bpp.lz"
+AnimObjFireGFX: INCBIN "gfx/fx/003.2bpp.lz"
+AnimObjWaterGFX: INCBIN "gfx/fx/004.2bpp.lz"
+AnimObjLightningGFX: INCBIN "gfx/fx/005.2bpp.lz"
AnimObj07GFX: INCBIN "gfx/fx/007.2bpp.lz"
AnimObj08GFX: INCBIN "gfx/fx/008.2bpp.lz"
AnimObj10GFX: INCBIN "gfx/fx/010.2bpp.lz"
diff --git a/battle/anims.asm b/battle/anims.asm
index 5d8050c83..66ae9ff1b 100644
--- a/battle/anims.asm
+++ b/battle/anims.asm
@@ -1323,7 +1323,7 @@ BattleAnim_Thundershock: ; c9b53
BattleAnim_Thunderbolt: ; c9b66
anim_2gfx ANIM_GFX_LIGHTNING, ANIM_GFX_EXPLOSION
- anim_obj ANIM_OBJ_32, -15, 0, 7, 0, $2
+ anim_obj ANIM_OBJ_LIGHTNING_BOLT, -15, 0, 7, 0, $2
anim_wait 16
anim_bgeffect ANIM_BG_FLASH_INVERTED, $0, $4, $2
anim_sound 0, 1, SFX_THUNDERSHOCK
@@ -2497,10 +2497,10 @@ BattleAnim_Transform: ; ca54d
anim_call BattleAnim_FollowPlayerHead_0
anim_transform
anim_sound 0, 0, SFX_PSYBEAM
- anim_bgeffect ANIM_BG_28, $0, $1, $0
+ anim_bgeffect ANIM_BG_WAVE_DEFORM_USER, $0, $1, $0
anim_wait 48
anim_updateactorpic
- anim_incbgeffect ANIM_BG_28
+ anim_incbgeffect ANIM_BG_WAVE_DEFORM_USER
anim_wait 48
anim_call BattleAnim_ShowMon_0
anim_ret
@@ -2759,10 +2759,10 @@ BattleAnim_Minimize: ; ca78a
anim_1gfx ANIM_GFX_HIT
anim_call BattleAnim_FollowPlayerHead_0
anim_minimize
- anim_bgeffect ANIM_BG_28, $0, $1, $0
+ anim_bgeffect ANIM_BG_WAVE_DEFORM_USER, $0, $1, $0
anim_wait 48
anim_updateactorpic
- anim_incbgeffect ANIM_BG_28
+ anim_incbgeffect ANIM_BG_WAVE_DEFORM_USER
anim_wait 48
anim_call BattleAnim_ShowMon_0
anim_ret
@@ -2774,7 +2774,7 @@ BattleAnim_SkyAttack: ; ca7a1
anim_bgeffect ANIM_BG_27, $0, $1, $0
anim_wait 32
anim_sound 0, 0, SFX_HYPER_BEAM
- anim_obj ANIM_OBJ_6E, 6, 0, 11, 0, $40
+ anim_obj ANIM_OBJ_SKY_ATTACK_FEAROW, 6, 0, 11, 0, $40
anim_wait 64
anim_incobj 1
anim_wait 21
@@ -2805,7 +2805,7 @@ BattleAnim_NightShade: ; ca7cc
BattleAnim_Lick: ; ca7e5
anim_1gfx ANIM_GFX_WATER
anim_sound 0, 1, SFX_LICK
- anim_obj ANIM_OBJ_6F, -15, 0, 7, 0, $0
+ anim_obj ANIM_OBJ_LICK, -15, 0, 7, 0, $0
anim_wait 64
anim_ret
; ca7f1
@@ -3025,9 +3025,9 @@ BattleAnim_Meditate: ; ca9d8
anim_1gfx ANIM_GFX_HIT
anim_call BattleAnim_FollowEnemyFeet_0
anim_sound 0, 0, SFX_PSYBEAM
- anim_bgeffect ANIM_BG_28, $0, $1, $0
+ anim_bgeffect ANIM_BG_WAVE_DEFORM_USER, $0, $1, $0
anim_wait 48
- anim_incbgeffect ANIM_BG_28
+ anim_incbgeffect ANIM_BG_WAVE_DEFORM_USER
anim_wait 48
anim_call BattleAnim_ShowMon_0
anim_ret
@@ -3765,13 +3765,13 @@ BattleAnim_Octazooka: ; cb06f
BattleAnim_Spikes: ; cb092
anim_1gfx ANIM_GFX_MISC
anim_sound 6, 2, SFX_MENU
- anim_obj ANIM_OBJ_8E, 6, 0, 11, 0, $20
+ anim_obj ANIM_OBJ_SPIKES, 6, 0, 11, 0, $20
anim_wait 8
anim_sound 6, 2, SFX_MENU
- anim_obj ANIM_OBJ_8E, 6, 0, 11, 0, $30
+ anim_obj ANIM_OBJ_SPIKES, 6, 0, 11, 0, $30
anim_wait 8
anim_sound 6, 2, SFX_MENU
- anim_obj ANIM_OBJ_8E, 6, 0, 11, 0, $28
+ anim_obj ANIM_OBJ_SPIKES, 6, 0, 11, 0, $28
anim_wait 64
anim_ret
; cb0b0
@@ -3784,7 +3784,7 @@ BattleAnim_ZapCannon: ; cb0b0
anim_obj ANIM_OBJ_A3, 8, 0, 11, 4, $2
anim_wait 40
anim_sound 0, 1, SFX_THUNDERSHOCK
- anim_obj ANIM_OBJ_32, -15, 0, 7, 0, $2
+ anim_obj ANIM_OBJ_LIGHTNING_BOLT, -15, 0, 7, 0, $2
anim_wait 16
anim_obj ANIM_OBJ_31, -15, 0, 7, 0, $0
anim_wait 128
@@ -3830,14 +3830,14 @@ BattleAnim_PerishSong: ; cb113
anim_bgeffect ANIM_BG_06, $0, $2, $0
anim_bgeffect ANIM_BG_ALTERNATE_HUES, $0, $2, $0
anim_sound 0, 2, SFX_PERISH_SONG
- anim_obj ANIM_OBJ_A6, 11, 0, 0, 0, $0
- anim_obj ANIM_OBJ_A6, 11, 0, 0, 0, $8
- anim_obj ANIM_OBJ_A6, 11, 0, 0, 0, $10
- anim_obj ANIM_OBJ_A6, 11, 0, 0, 0, $18
- anim_obj ANIM_OBJ_A6, 11, 0, 0, 0, $20
- anim_obj ANIM_OBJ_A6, 11, 0, 0, 0, $28
- anim_obj ANIM_OBJ_A6, 11, 0, 0, 0, $30
- anim_obj ANIM_OBJ_A6, 11, 0, 0, 0, $38
+ anim_obj ANIM_OBJ_PERISH_SONG, 11, 0, 0, 0, $0
+ anim_obj ANIM_OBJ_PERISH_SONG, 11, 0, 0, 0, $8
+ anim_obj ANIM_OBJ_PERISH_SONG, 11, 0, 0, 0, $10
+ anim_obj ANIM_OBJ_PERISH_SONG, 11, 0, 0, 0, $18
+ anim_obj ANIM_OBJ_PERISH_SONG, 11, 0, 0, 0, $20
+ anim_obj ANIM_OBJ_PERISH_SONG, 11, 0, 0, 0, $28
+ anim_obj ANIM_OBJ_PERISH_SONG, 11, 0, 0, 0, $30
+ anim_obj ANIM_OBJ_PERISH_SONG, 11, 0, 0, 0, $38
anim_wait 112
anim_ret
; cb14c
@@ -4087,7 +4087,7 @@ BattleAnim_Spark: ; cb34d
anim_incobj 2
anim_wait 1
anim_sound 0, 1, SFX_THUNDERSHOCK
- anim_obj ANIM_OBJ_32, -15, 0, 7, 0, $2
+ anim_obj ANIM_OBJ_LIGHTNING_BOLT, -15, 0, 7, 0, $2
anim_obj ANIM_OBJ_33, -15, 0, 7, 0, $0
anim_wait 32
anim_ret
diff --git a/battle/core.asm b/battle/core.asm
index 7e6eea9c6..34e43a9ab 100644
--- a/battle/core.asm
+++ b/battle/core.asm
@@ -7,7 +7,7 @@ DoBattle: ; 3c000
ld [wPlayerAction], a
ld [BattleEnded], a
inc a
- ld [wd264], a
+ ld [wAISwitch], a
ld hl, OTPartyMon1HP
ld bc, PARTYMON_STRUCT_LENGTH - 1
ld d, BATTLEACTION_SWITCH1 - 1
@@ -60,7 +60,7 @@ DoBattle: ; 3c000
xor a
ld [CurPartyMon], a
.loop2
- call CheckIfPartyHasPkmnToBattleWith
+ call CheckIfCurPartyMonIsFitToFight
jr nz, .alive2
ld hl, CurPartyMon
inc [hl]
@@ -170,7 +170,7 @@ BattleTurn: ; 3c12f
xor a
ld [wPlayerIsSwitching], a
ld [wEnemyIsSwitching], a
- ld [wd264], a
+ ld [wAISwitch], a
ld [wPlayerJustGotFrozen], a
ld [wEnemyJustGotFrozen], a
ld [CurDamage], a
@@ -2497,7 +2497,7 @@ WinTrainerBattle: ; 3cfa4
call PrintWinLossText
.skip_win_loss_text
- jp HandleBattleReward
+ jp .GiveMoney
.mobile
call BattleWinSlideInEnemyTrainerFrontpic
@@ -2524,9 +2524,8 @@ WinTrainerBattle: ; 3cfa4
call ClearTileMap
call ClearBGPalettes
ret
-; 3d02b
-HandleBattleReward: ; 3d02b
+.GiveMoney
ld a, [wAmuletCoin]
and a
call nz, .DoubleReward
@@ -3024,7 +3023,7 @@ PickPartyMonInBattle: ; 3d33c
call JumpToPartyMenuAndPrintText
call SelectBattleMon
ret c
- call CheckIfPartyHasPkmnToBattleWith
+ call CheckIfCurPartyMonIsFitToFight
jr z, .loop
xor a
ret
@@ -3373,14 +3372,14 @@ CheckWhetherSwitchmonIsPredetermined: ; 3d533
.not_linked
ld a, [wEnemySwitchMonIndex]
and a
- jr z, .check_wd264
+ jr z, .check_wAISwitch
dec a
ld b, a
jr .return_carry
-.check_wd264
- ld a, [wd264]
+.check_wAISwitch
+ ld a, [wAISwitch]
and a
ld b, $0
jr nz, .return_carry
@@ -3656,7 +3655,7 @@ LoadEnemyPkmnToSwitchTo: ; 3d6ca
; 3d714
CheckWhetherToAskSwitch: ; 3d714
- ld a, [wd264]
+ ld a, [wAISwitch]
dec a
jp z, .return_nc
ld a, [PartyCount]
@@ -3836,19 +3835,19 @@ CheckPlayerPartyForFitPkmn: ; 3d873
xor a
ld hl, PartyMon1HP
ld bc, PartyMon2 - (PartyMon1 + 1)
-.asm_3d87e
+.loop
or [hl]
inc hl
or [hl]
add hl, bc
dec e
- jr nz, .asm_3d87e
+ jr nz, .loop
ld d, a
ret
; 3d887
-CheckIfPartyHasPkmnToBattleWith: ; 3d887
+CheckIfCurPartyMonIsFitToFight: ; 3d887
ld a, [CurPartyMon]
ld hl, PartyMon1HP
call GetPartyLocation
@@ -3856,9 +3855,9 @@ CheckIfPartyHasPkmnToBattleWith: ; 3d887
or [hl]
ret nz
- ld a, [wd264]
+ ld a, [wAISwitch]
and a
- jr nz, .asm_3d8b1
+ jr nz, .finish_fail
ld hl, PartySpecies
ld a, [CurPartyMon]
ld c, a
@@ -3867,14 +3866,14 @@ CheckIfPartyHasPkmnToBattleWith: ; 3d887
ld a, [hl]
cp EGG
ld hl, BattleText_AnEGGCantBattle
- jr z, .asm_3d8ae
+ jr z, .print_textbox
ld hl, BattleText_TheresNoWillToBattle
-.asm_3d8ae
+.print_textbox
call StdBattleTextBox
-.asm_3d8b1
+.finish_fail
xor a
ret
; 3d8b3
@@ -4501,6 +4500,8 @@ HandleHPHealingItem: ; 3dd2f
ld hl, BattleMonMaxHP
.go
+; If, and only if, Pokemon's HP is less than half max, use the item.
+; Store current HP in Buffer 3/4
push bc
ld a, [de]
ld [Buffer3], a
@@ -4528,6 +4529,7 @@ HandleHPHealingItem: ; 3dd2f
.less
call ItemRecoveryAnim
+ ; store max HP in Buffer1/2
ld a, [hli]
ld [Buffer2], a
ld a, [hl]
@@ -5434,7 +5436,7 @@ TryPlayerSwitch: ; 3e358
jp BattleMenuPKMN_Loop
.try_switch
- call CheckIfPartyHasPkmnToBattleWith
+ call CheckIfCurPartyMonIsFitToFight
jp z, BattleMenuPKMN_Loop
ld a, [CurBattleMon]
ld [LastPlayerMon], a
@@ -5675,15 +5677,15 @@ MoveSelectionScreen: ; 3e4bc
ld c, $2c
ld a, [wMoveSelectionMenuType]
dec a
- ld b, $c1
+ ld b, D_DOWN | D_UP | A_BUTTON
jr z, .okay
dec a
- ld b, $c3
+ ld b, D_DOWN | D_UP | A_BUTTON | B_BUTTON
jr z, .okay
ld a, [wLinkMode]
and a
jr nz, .okay
- ld b, $c7
+ ld b, D_DOWN | D_UP | A_BUTTON | B_BUTTON | SELECT
.okay
ld a, b
@@ -5727,6 +5729,7 @@ MoveSelectionScreen: ; 3e4bc
bit SELECT_F, a
jp nz, .pressed_select
bit B_BUTTON_F, a
+ ; A button
push af
xor a
@@ -6106,7 +6109,7 @@ ParseEnemyAction: ; 3e7c1
jp .finish
.skip_encore
- call CheckSubstatus_RechargeChargedRampageBideRollout
+ call CheckEnemyLockedIn
jp nz, ResetVarsForSubstatusRage
jr .continue
@@ -6173,7 +6176,7 @@ ParseEnemyAction: ; 3e7c1
.skip_load
call SetEnemyTurn
callab UpdateMoveData
- call CheckSubstatus_RechargeChargedRampageBideRollout
+ call CheckEnemyLockedIn
jr nz, .raging
xor a
ld [wEnemyCharging], a
@@ -6219,7 +6222,7 @@ ResetVarsForSubstatusRage: ; 3e8c1
ret
; 3e8d1
-CheckSubstatus_RechargeChargedRampageBideRollout: ; 3e8d1
+CheckEnemyLockedIn: ; 3e8d1
ld a, [EnemySubStatus4]
and 1 << SUBSTATUS_RECHARGE
ret nz
@@ -8025,7 +8028,7 @@ SendOutPkmnText: ; 3f26d
ld hl, JumpText_GoPkmn ; If we're in a LinkBattle print just "Go <PlayerMon>"
- ld a, [wd264] ; unless this (unidentified) variable is set
+ ld a, [wAISwitch] ; unless this (unidentified) variable is set
and a
jr nz, .skip_to_textbox
@@ -8482,7 +8485,7 @@ BattleIntro: ; 3f4dd
ld [hMapAnims], a
callba PlayBattleMusic
callba ShowLinkBattleParticipants
- callba FindFirstAliveMon
+ callba FindFirstAliveMonAndStartBattle
call DisableSpriteUpdates
callba ClearBattleRAM
call InitEnemy
diff --git a/battle/effect_commands.asm b/battle/effect_commands.asm
index 1350300ca..e83cf2f2e 100644
--- a/battle/effect_commands.asm
+++ b/battle/effect_commands.asm
@@ -2924,7 +2924,9 @@ TruncateHL_BC: ; 3534d
ld a, [wLinkMode]
cp 3
jr z, .done
-
+; If we go back to the loop point,
+; it's the same as doing this exact
+; same check twice.
ld a, h
or b
jr nz, .loop
@@ -7871,7 +7873,7 @@ BattleCommand_Substitute: ; 36e7c
ld [hl], a
ld [de], a
call _CheckBattleScene
- jr c, .mobile
+ jr c, .no_anim
xor a
ld [wNumHits], a
@@ -7881,7 +7883,7 @@ BattleCommand_Substitute: ; 36e7c
call LoadAnim
jr .finish
-.mobile
+.no_anim
call BattleCommand_RaiseSubNoAnim
.finish
ld hl, MadeSubstituteText
diff --git a/battle/moves/move_effects.asm b/battle/moves/move_effects.asm
index 454a1ac9b..2d4c06a33 100644
--- a/battle/moves/move_effects.asm
+++ b/battle/moves/move_effects.asm
@@ -2095,7 +2095,7 @@ FutureSight:
damagestats
damagecalc
futuresight
- damagevariation
+ damagevariation ; skip here if last turn
checkhit
hittargetnosub
failuretext
diff --git a/battle/objects/data.asm b/battle/objects/data.asm
index 7ae0dc371..8a3f42f85 100755
--- a/battle/objects/data.asm
+++ b/battle/objects/data.asm
@@ -156,7 +156,7 @@ endm
; ANIM_OBJ_31
battleanimobj $21, $90, BATTLEANIMFRAMESET_36, BATTLEANIMFUNC_00, $03, $05
-; ANIM_OBJ_32
+; ANIM_OBJ_LIGHTNING_BOLT
battleanimobj $21, $90, BATTLEANIMFRAMESET_37, BATTLEANIMFUNC_03, $02, $08
; ANIM_OBJ_33
@@ -336,10 +336,10 @@ endm
; ANIM_OBJ_6D
battleanimobj $01, $88, BATTLEANIMFRAMESET_7A, BATTLEANIMFUNC_31, $03, $11
-; ANIM_OBJ_6E
+; ANIM_OBJ_SKY_ATTACK_FEAROW
battleanimobj $21, $88, BATTLEANIMFRAMESET_7B, BATTLEANIMFUNC_32, $02, $20
-; ANIM_OBJ_6F
+; ANIM_OBJ_LICK
battleanimobj $21, $98, BATTLEANIMFRAMESET_7C, BATTLEANIMFUNC_00, $02, $04
; ANIM_OBJ_70
@@ -432,7 +432,7 @@ endm
; ANIM_OBJ_8D
battleanimobj $21, $a0, BATTLEANIMFRAMESET_99, BATTLEANIMFUNC_35, $04, $19
-; ANIM_OBJ_8E
+; ANIM_OBJ_SPIKES
battleanimobj $21, $70, BATTLEANIMFRAMESET_8B, BATTLEANIMFUNC_3F, $02, $1f
; ANIM_OBJ_8F
@@ -504,7 +504,7 @@ endm
; ANIM_OBJ_A5
battleanimobj $61, $90, BATTLEANIMFRAMESET_A9, BATTLEANIMFUNC_46, $02, $23
-; ANIM_OBJ_A6
+; ANIM_OBJ_PERISH_SONG
battleanimobj $00, $00, BATTLEANIMFRAMESET_24, BATTLEANIMFUNC_47, $02, $0e
; ANIM_OBJ_A7
diff --git a/battle/objects/gfx_headers.asm b/battle/objects/gfx_headers.asm
index bec34ce74..eadd1abfb 100755
--- a/battle/objects/gfx_headers.asm
+++ b/battle/objects/gfx_headers.asm
@@ -8,11 +8,11 @@ object_gfx: MACRO
ENDM
object_gfx 0, AnimObj00GFX
- object_gfx 21, AnimObj01GFX
- object_gfx 6, AnimObj02GFX
- object_gfx 6, AnimObj03GFX
- object_gfx 20, AnimObj04GFX
- object_gfx 26, AnimObj05GFX
+ object_gfx 21, AnimObjHitGFX
+ object_gfx 6, AnimObjCutGFX
+ object_gfx 6, AnimObjFireGFX
+ object_gfx 20, AnimObjWaterGFX
+ object_gfx 26, AnimObjLightningGFX
object_gfx 18, AnimObj06GFX
object_gfx 12, AnimObj07GFX
object_gfx 9, AnimObj08GFX
diff --git a/constants/animation_constants.asm b/constants/animation_constants.asm
index 5ae2f324f..9ea2f3f34 100644
--- a/constants/animation_constants.asm
+++ b/constants/animation_constants.asm
@@ -76,7 +76,7 @@ BATTLEANIMSTRUCT_LENGTH EQU const_value
const ANIM_OBJ_2F
const ANIM_OBJ_30
const ANIM_OBJ_31
- const ANIM_OBJ_32
+ const ANIM_OBJ_LIGHTNING_BOLT
const ANIM_OBJ_33
const ANIM_OBJ_34
const ANIM_OBJ_35
@@ -136,8 +136,8 @@ BATTLEANIMSTRUCT_LENGTH EQU const_value
const ANIM_OBJ_6B
const ANIM_OBJ_6C
const ANIM_OBJ_6D
- const ANIM_OBJ_6E
- const ANIM_OBJ_6F
+ const ANIM_OBJ_SKY_ATTACK_FEAROW
+ const ANIM_OBJ_LICK
const ANIM_OBJ_70
const ANIM_OBJ_71
const ANIM_OBJ_72
@@ -168,7 +168,7 @@ BATTLEANIMSTRUCT_LENGTH EQU const_value
const ANIM_OBJ_8B
const ANIM_OBJ_8C
const ANIM_OBJ_8D
- const ANIM_OBJ_8E
+ const ANIM_OBJ_SPIKES
const ANIM_OBJ_8F
const ANIM_OBJ_90
const ANIM_OBJ_91
@@ -192,7 +192,7 @@ BATTLEANIMSTRUCT_LENGTH EQU const_value
const ANIM_OBJ_A3
const ANIM_OBJ_A4
const ANIM_OBJ_A5
- const ANIM_OBJ_A6
+ const ANIM_OBJ_PERISH_SONG
const ANIM_OBJ_A7
const ANIM_OBJ_A8
const ANIM_OBJ_A9
@@ -742,7 +742,7 @@ const_value SET 1
const ANIM_BG_25
const ANIM_BG_26
const ANIM_BG_27
- const ANIM_BG_28
+ const ANIM_BG_WAVE_DEFORM_USER
const ANIM_BG_PSYCHIC
const ANIM_BG_2A
const ANIM_BG_2B
@@ -768,6 +768,47 @@ const_value SET 1
const ANIM_MON_EGG1 ; 7
const ANIM_MON_EGG2 ; 8
+const_value SET 1
+ const ANIM_GFX_HIT
+ const ANIM_GFX_CUT
+ const ANIM_GFX_FIRE
+ const ANIM_GFX_WATER
+ const ANIM_GFX_LIGHTNING
+ const ANIM_GFX_PLANT
+ const ANIM_GFX_SMOKE
+ const ANIM_GFX_EXPLOSION
+ const ANIM_GFX_ROCKS
+ const ANIM_GFX_ICE
+ const ANIM_GFX_POKE_BALL
+ const ANIM_GFX_POISON
+ const ANIM_GFX_BUBBLE
+ const ANIM_GFX_NOISE
+ const ANIM_GFX_POWDER
+ const ANIM_GFX_BEAM
+ const ANIM_GFX_SPEED
+ const ANIM_GFX_CHARGE
+ const ANIM_GFX_WIND
+ const ANIM_GFX_WHIP
+ const ANIM_GFX_EGG
+ const ANIM_GFX_ROPE
+ const ANIM_GFX_PSYCHIC
+ const ANIM_GFX_REFLECT
+ const ANIM_GFX_STATUS
+ const ANIM_GFX_SAND
+ const ANIM_GFX_WEB
+ const ANIM_GFX_HAZE
+ const ANIM_GFX_HORN
+ const ANIM_GFX_FLOWER
+ const ANIM_GFX_MISC
+ const ANIM_GFX_SKY_ATTACK
+ const ANIM_GFX_GLOBE
+ const ANIM_GFX_SHAPES
+ const ANIM_GFX_OBJECTS
+ const ANIM_GFX_SHINE
+ const ANIM_GFX_ANGELS
+ const ANIM_GFX_WAVE
+ const ANIM_GFX_AEROBLAST
+
const_def
const BG_EFFECT_STRUCT_FUNCTION
const BG_EFFECT_STRUCT_JT_INDEX
diff --git a/constants/battle_tower_constants.asm b/constants/battle_tower_constants.asm
index 1e5b0d625..c690c9b0b 100755
--- a/constants/battle_tower_constants.asm
+++ b/constants/battle_tower_constants.asm
@@ -19,8 +19,8 @@
const BATTLETOWERACTION_11 ; store 0 in 5:aa8d
const BATTLETOWERACTION_12 ; store 1 in 5:aa8d
const BATTLETOWERACTION_13 ; check 5:aa8d
- const BATTLETOWERACTION_14 ; if save file is yours: bit 0, [sbe4f]
- const BATTLETOWERACTION_15 ; set 0, [sbe4f]
+ const BATTLETOWERACTION_14 ; if save file is yours: bit 0, [s1_be4f]
+ const BATTLETOWERACTION_15 ; set 0, [s1_be4f]
const BATTLETOWERACTION_16 ; update time in SRAM bank 5
const BATTLETOWERACTION_17 ; check time in SRAM bank 5
const BATTLETOWERACTION_18 ; level check
diff --git a/constants/event_flags.asm b/constants/event_flags.asm
index 775991a87..636d0226c 100644
--- a/constants/event_flags.asm
+++ b/constants/event_flags.asm
@@ -1232,7 +1232,7 @@
const EVENT_BEAT_BLACKBELT_LUNG
const EVENT_BEAT_BLACKBELT_KENJI
const EVENT_BEAT_BLACKBELT_WAI
-; Beauti
+; Beauty
const EVENT_BEAT_BEAUTY_VICTORIA
const EVENT_BEAT_BEAUTY_SAMANTHA
const EVENT_BEAT_BEAUTY_JULIE
diff --git a/constants/gfx_constants.asm b/constants/gfx_constants.asm
index c774faa95..9478cd123 100644
--- a/constants/gfx_constants.asm
+++ b/constants/gfx_constants.asm
@@ -1,45 +1,3 @@
-const_value SET 1
- const ANIM_GFX_HIT
- const ANIM_GFX_CUT
- const ANIM_GFX_FIRE
- const ANIM_GFX_WATER
- const ANIM_GFX_LIGHTNING
- const ANIM_GFX_PLANT
- const ANIM_GFX_SMOKE
- const ANIM_GFX_EXPLOSION
- const ANIM_GFX_ROCKS
- const ANIM_GFX_ICE
- const ANIM_GFX_POKE_BALL
- const ANIM_GFX_POISON
- const ANIM_GFX_BUBBLE
- const ANIM_GFX_NOISE
- const ANIM_GFX_POWDER
- const ANIM_GFX_BEAM
- const ANIM_GFX_SPEED
- const ANIM_GFX_CHARGE
- const ANIM_GFX_WIND
- const ANIM_GFX_WHIP
- const ANIM_GFX_EGG
- const ANIM_GFX_ROPE
- const ANIM_GFX_PSYCHIC
- const ANIM_GFX_REFLECT
- const ANIM_GFX_STATUS
- const ANIM_GFX_SAND
- const ANIM_GFX_WEB
- const ANIM_GFX_HAZE
- const ANIM_GFX_HORN
- const ANIM_GFX_FLOWER
- const ANIM_GFX_MISC
- const ANIM_GFX_SKY_ATTACK
- const ANIM_GFX_GLOBE
- const ANIM_GFX_SHAPES
- const ANIM_GFX_OBJECTS
- const ANIM_GFX_SHINE
- const ANIM_GFX_ANGELS
- const ANIM_GFX_WAVE
- const ANIM_GFX_AEROBLAST
-
-
LEN_2BPP_TILE EQU 16
LEN_1BPP_TILE EQU 8
TILES_PER_FRAME EQU 6
diff --git a/constants/map_constants.asm b/constants/map_constants.asm
index 9be0a775a..4e1dd718f 100644
--- a/constants/map_constants.asm
+++ b/constants/map_constants.asm
@@ -707,3 +707,5 @@ CMDQUEUE_04 EQU 4
CMDQUEUE_05 EQU 5
CMDQUEUE_ENTRY_SIZE EQU 6
CMDQUEUE_CAPACITY EQU 4
+
+CMDQUEUE_STONETABLE EQU 2
diff --git a/constants/map_setup_constants.asm b/constants/map_setup_constants.asm
index 0ee137ead..1a3f60e7b 100644
--- a/constants/map_setup_constants.asm
+++ b/constants/map_setup_constants.asm
@@ -19,7 +19,7 @@ const_value SET 1
const MAPCALLBACK_SPRITES
const MAPCALLBACK_NEWMAP
-; Command descriptions from Condensation water's scripting compendium. const_def
+; Command descriptions from Condensation water's scripting compendium.
const_def
const map_lcd_on ; 00
diff --git a/engine/anim_hp_bar.asm b/engine/anim_hp_bar.asm
index c00a97921..404e6cbc3 100755
--- a/engine/anim_hp_bar.asm
+++ b/engine/anim_hp_bar.asm
@@ -1,46 +1,46 @@
_AnimateHPBar: ; d627
- call Functiond65f
- jr c, .do_player
- call Functiond670
-.enemy_loop
+ call .IsMaximumMoreThan48Pixels
+ jr c, .MoreThan48Pixels
+ call .ComputePixels
+.ShortAnimLoop
push bc
push hl
- call Functiond6e2
+ call ShortAnim_UpdateVariables
pop hl
pop bc
push af
push bc
push hl
- call Functiond730
- call Functiond7c9
+ call ShortHPBarAnim_UpdateTiles
+ call HPBarAnim_BGMapUpdate
pop hl
pop bc
pop af
- jr nc, .enemy_loop
+ jr nc, .ShortAnimLoop
ret
-.do_player
- call Functiond670
-.player_loop
+.MoreThan48Pixels
+ call .ComputePixels
+.LongAnimLoop
push bc
push hl
- call Functiond6f5
+ call LongAnim_UpdateVariables
pop hl
pop bc
ret c
push af
push bc
push hl
- call Functiond749
- call Functiond7c9
+ call LongHPBarAnim_UpdateTiles
+ call HPBarAnim_BGMapUpdate
pop hl
pop bc
pop af
- jr nc, .player_loop
+ jr nc, .LongAnimLoop
ret
; d65f
-Functiond65f: ; d65f
+.IsMaximumMoreThan48Pixels: ; d65f
ld a, [Buffer2]
and a
jr nz, .player
@@ -55,7 +55,7 @@ Functiond65f: ; d65f
ret
; d670
-Functiond670: ; d670
+.ComputePixels: ; d670
; Buffer1-2: Max HP
; Buffer3-4: Old HP
; Buffer5-6: New HP
@@ -72,7 +72,7 @@ Functiond670: ; d670
pop hl
call ComputeHPBarPixels
ld a, e
- ld [wd1f1], a
+ ld [wCurHPBarPixels], a
ld a, [Buffer5]
ld c, a
@@ -84,7 +84,7 @@ Functiond670: ; d670
ld d, a
call ComputeHPBarPixels
ld a, e
- ld [wd1f2], a
+ ld [wNewHPBarPixels], a
push hl
ld hl, Buffer3
@@ -103,15 +103,15 @@ Functiond670: ; d670
ld a, d
sbc b
ld d, a
- jr c, .asm_d6c1
+ jr c, .negative
ld a, [Buffer3]
ld [wd1f5], a
ld a, [Buffer5]
ld [wd1f6], a
ld bc, 1
- jr .asm_d6d9
+ jr .got_direction
-.asm_d6c1
+.negative
ld a, [Buffer3]
ld [wd1f6], a
ld a, [Buffer5]
@@ -123,8 +123,8 @@ Functiond670: ; d670
ld a, d
xor $ff
ld d, a
- ld bc, rIE
-.asm_d6d9
+ ld bc, -1
+.got_direction
ld a, d
ld [wd1f3], a
ld a, e
@@ -132,25 +132,25 @@ Functiond670: ; d670
ret
; d6e2
-Functiond6e2: ; d6e2
- ld hl, wd1f1
- ld a, [wd1f2]
+ShortAnim_UpdateVariables: ; d6e2
+ ld hl, wCurHPBarPixels
+ ld a, [wNewHPBarPixels]
cp [hl]
- jr nz, .asm_d6ed
+ jr nz, .not_finished
scf
ret
-.asm_d6ed
+.not_finished
ld a, c
add [hl]
ld [hl], a
- call Functiond839
+ call ShortHPBar_CalcPixelFrame
and a
ret
; d6f5
-Functiond6f5: ; d6f5
-.asm_d6f5
+LongAnim_UpdateVariables: ; d6f5
+.loop
ld hl, Buffer3
ld a, [hli]
ld e, a
@@ -158,22 +158,22 @@ Functiond6f5: ; d6f5
ld d, a
ld a, e
cp [hl]
- jr nz, .asm_d707
+ jr nz, .next
inc hl
ld a, d
cp [hl]
- jr nz, .asm_d707
+ jr nz, .next
scf
ret
-.asm_d707
+.next
ld l, e
ld h, d
add hl, bc
ld a, l
ld [Buffer3], a
ld a, h
- ld [wd1ed], a
+ ld [Buffer4], a
push hl
push de
push bc
@@ -186,40 +186,45 @@ Functiond6f5: ; d6f5
ld c, a
ld a, [hli]
ld b, a
+ ; This routine is buggy. The result from ComputeHPBarPixels is stored
+ ; in e. However, the pop de opcode deletes this result before it is even
+ ; used. The game then proceeds as though it never deleted that output.
+ ; To fix, uncomment the line below.
call ComputeHPBarPixels
+ ; ld a, e
pop bc
pop de
pop hl
- ld a, e
- ld hl, wd1f1
+ ld a, e ; Comment or delete this line to fix the above bug.
+ ld hl, wCurHPBarPixels
cp [hl]
- jr z, .asm_d6f5
+ jr z, .loop
ld [hl], a
and a
ret
; d730
-Functiond730: ; d730
- call Functiond784
+ShortHPBarAnim_UpdateTiles: ; d730
+ call HPBarAnim_UpdateHPRemaining
ld d, $6
ld a, [wWhichHPBar]
and $1
ld b, a
- ld a, [wd1f1]
+ ld a, [wCurHPBarPixels]
ld e, a
ld c, a
push de
- call Functiond771
+ call HPBarAnim_RedrawHPBar
pop de
- call Functiond7b4
+ call HPBarAnim_PaletteUpdate
ret
; d749
-Functiond749: ; d749
- call Functiond784
+LongHPBarAnim_UpdateTiles: ; d749
+ call HPBarAnim_UpdateHPRemaining
ld a, [Buffer3]
ld c, a
- ld a, [wd1ed]
+ ld a, [Buffer4]
ld b, a
ld a, [Buffer1]
ld e, a
@@ -232,20 +237,20 @@ Functiond749: ; d749
and $1
ld b, a
push de
- call Functiond771
+ call HPBarAnim_RedrawHPBar
pop de
- call Functiond7b4
+ call HPBarAnim_PaletteUpdate
ret
; d771
-Functiond771: ; d771
+HPBarAnim_RedrawHPBar: ; d771
ld a, [wWhichHPBar]
cp $2
jr nz, .skip
- ld a, $28
+ ld a, 2 * SCREEN_WIDTH
add l
ld l, a
- ld a, $0
+ ld a, 0
adc h
ld h, a
.skip
@@ -253,17 +258,17 @@ Functiond771: ; d771
ret
; d784
-Functiond784: ; d784
+HPBarAnim_UpdateHPRemaining: ; d784
ld a, [wWhichHPBar]
and a
ret z
cp $1
jr z, .load_15
- ld de, $16
+ ld de, SCREEN_WIDTH + 2
jr .loaded_de
.load_15
- ld de, $15
+ ld de, SCREEN_WIDTH + 1
.loaded_de
push hl
add hl, de
@@ -275,7 +280,7 @@ endr
dec hl
ld a, [Buffer3]
ld [StringBuffer2 + 1], a
- ld a, [wd1ed]
+ ld a, [Buffer4]
ld [StringBuffer2], a
ld de, StringBuffer2
lb bc, 2, 3
@@ -284,7 +289,7 @@ endr
ret
; d7b4
-Functiond7b4: ; d7b4
+HPBarAnim_PaletteUpdate: ; d7b4
ld a, [hCGB]
and a
ret z
@@ -296,7 +301,7 @@ Functiond7b4: ; d7b4
ret
; d7c9
-Functiond7c9: ; d7c9
+HPBarAnim_BGMapUpdate: ; d7c9
ld a, [hCGB]
and a
jr nz, .cgb
@@ -312,13 +317,13 @@ Functiond7c9: ; d7c9
jr z, .load_1
ld a, [CurPartyMon]
cp $3
- jr nc, .c_is_1
+ jr nc, .bottom_half_of_screen
ld c, $0
- jr .c_is_0
+ jr .got_third
-.c_is_1
+.bottom_half_of_screen
ld c, $1
-.c_is_0
+.got_third
push af
cp $2
jr z, .skip_delay
@@ -370,14 +375,14 @@ Functiond7c9: ; d7c9
ret
; d839
-Functiond839: ; d839
+ShortHPBar_CalcPixelFrame: ; d839
ld a, [Buffer1]
ld c, a
ld b, 0
ld hl, 0
- ld a, [wd1f1]
+ ld a, [wCurHPBarPixels]
cp 6 * 8
- jr nc, .coppy_buffer
+ jr nc, .return_max
and a
jr z, .return_zero
call AddNTimes
@@ -423,7 +428,7 @@ Functiond839: ; d839
ld [Buffer3], a
ret
-.coppy_buffer
+.return_max
ld a, [Buffer1]
ld [Buffer3], a
ret
diff --git a/engine/battle_start.asm b/engine/battle_start.asm
index 6fb64e9b1..083469b0d 100644
--- a/engine/battle_start.asm
+++ b/engine/battle_start.asm
@@ -1,5 +1,5 @@
Predef_StartBattle: ; 8c20f
- call Function8c26d
+ call .InitGFX
ld a, [rBGP]
ld [wBGP], a
ld a, [rOBP0]
@@ -52,15 +52,15 @@ Predef_StartBattle: ; 8c20f
ret
; 8c26d
-Function8c26d: ; 8c26d
+.InitGFX: ; 8c26d
ld a, [wLinkMode]
cp LINK_MOBILE
jr z, .mobile
callba Function6454
call UpdateSprites
call DelayFrame
- call Function8c2a0
- call Function8cf4f
+ call .NonMobile_LoadPokeballTiles
+ call BattleStart_LoadEDTile
jr .resume
.mobile
@@ -81,7 +81,7 @@ Function8c26d: ; 8c26d
ret
; 8c2a0
-Function8c2a0: ; 8c2a0
+.NonMobile_LoadPokeballTiles: ; 8c2a0
call LoadTrainerBattlePokeballTiles
hlbgcoord 0, 0
call Function8c2cf
@@ -663,7 +663,7 @@ StartTrainerBattle_LoadPokeBallGraphics: ; 8c5dc (23:45dc)
ld a, $1
ld [hCGBPalUpdate], a
call DelayFrame
- call Function8cf4f
+ call BattleStart_LoadEDTile
.nextscene: ; 8c673 (23:4673)
call StartTrainerBattle_NextScene
diff --git a/engine/billspctop.asm b/engine/billspctop.asm
new file mode 100755
index 000000000..038341ccc
--- /dev/null
+++ b/engine/billspctop.asm
@@ -0,0 +1,388 @@
+_BillsPC: ; e3fd
+ call .CheckCanUsePC
+ ret c
+ call .LogIn
+ call .UseBillsPC
+ jp .LogOut
+
+.CheckCanUsePC: ; e40a (3:640a)
+ ld a, [PartyCount]
+ and a
+ ret nz
+ ld hl, .Text_GottaHavePokemon
+ call MenuTextBoxBackup
+ scf
+ ret
+
+.Text_GottaHavePokemon: ; 0xe417
+ ; You gotta have #MON to call!
+ text_jump UnknownText_0x1c1006
+ db "@"
+
+.LogIn: ; e41c (3:641c)
+ xor a
+ ld [hBGMapMode], a
+ call LoadStandardMenuDataHeader
+ call ClearPCItemScreen
+ ld hl, Options
+ ld a, [hl]
+ push af
+ set NO_TEXT_SCROLL, [hl]
+ ld hl, .Text_What
+ call PrintText
+ pop af
+ ld [Options], a
+ call LoadFontsBattleExtra
+ ret
+
+.Text_What: ; 0xe43a
+ ; What?
+ text_jump UnknownText_0x1c1024
+ db "@"
+
+.LogOut: ; e43f (3:643f)
+ call CloseSubmenu
+ ret
+
+.UseBillsPC: ; e443 (3:6443)
+ ld hl, .MenuDataHeader
+ call LoadMenuDataHeader
+ ld a, $1
+.loop
+ ld [wMenuCursorBuffer], a
+ call SetPalettes
+ xor a
+ ld [wWhichIndexSet], a
+ ld [hBGMapMode], a
+ call DoNthMenu
+ jr c, .cancel
+ ld a, [wMenuCursorBuffer]
+ push af
+ ld a, [MenuSelection]
+ ld hl, .Jumptable
+ rst JumpTable
+ pop bc
+ ld a, b
+ jr nc, .loop
+.cancel
+ call CloseWindow
+ ret
+
+.MenuDataHeader: ; 0xe46f
+ db $40 ; flags
+ db 00, 00 ; start coords
+ db 17, 19 ; end coords
+ dw .MenuData2
+ db 1 ; default option
+
+.MenuData2: ; 0xe477
+ db $80 ; flags
+ db 0 ; items
+ dw .items
+ dw PlaceMenuStrings
+ dw .strings
+
+.strings: ; e47f
+ db "WITHDRAW <PK><MN>@"
+ db "DEPOSIT <PK><MN>@"
+ db "CHANGE BOX@"
+ db "MOVE <PK><MN> W/O MAIL@"
+ db "SEE YA!@"
+
+.Jumptable: ; e4ba (3:64ba)
+ dw BillsPC_WithdrawMenu
+ dw BillsPC_DepositMenu
+ dw BillsPC_ChangeBoxMenu
+ dw BillsPC_MovePKMNMenu
+ dw BillsPC_SeeYa
+
+.items: ; e4c4
+ db 5
+ db 0 ; WITHDRAW
+ db 1; DEPOSIT
+ db 2 ; CHANGE BOX
+ db 3 ; MOVE PKMN
+ db 4 ; SEE YA!
+ db -1
+
+BillsPC_SeeYa: ; e4cb
+ scf
+ ret
+
+BillsPC_MovePKMNMenu: ; e4cd
+ call LoadStandardMenuDataHeader
+ callba IsAnyMonHoldingMail
+ jr nc, .no_mail
+ ld hl, .Text_MonHoldingMail
+ call PrintText
+ jr .quit
+
+.no_mail
+ callba StartMovePkmnWOMail_SaveGame
+ jr c, .quit
+ callba _MovePKMNWithoutMail
+ call ReturnToMapFromSubmenu
+ call ClearPCItemScreen
+
+.quit
+ call CloseWindow
+ and a
+ ret
+
+.Text_MonHoldingMail: ; 0xe4f9
+ ; There is a #MON holding MAIL. Please remove the MAIL.
+ text_jump UnknownText_0x1c102b
+ db "@"
+
+BillsPC_DepositMenu: ; e4fe (3:64fe)
+ call LoadStandardMenuDataHeader
+ callba _DepositPKMN
+ call ReturnToMapFromSubmenu
+ call ClearPCItemScreen
+ call CloseWindow
+ and a
+ ret
+
+Functione512: ; unused
+ ld a, [PartyCount]
+ and a
+ jr z, .no_pkmn
+ cp 2
+ jr c, .only_one_pkmn
+ and a
+ ret
+
+.no_pkmn
+ ld hl, .Text_NoPKMN
+ call MenuTextBoxBackup
+ scf
+ ret
+
+.only_one_pkmn
+ ld hl, .Text_ItsYourLastPKMN
+ call MenuTextBoxBackup
+ scf
+ ret
+
+.Text_NoPKMN: ; 0xe52e
+ ; You don't have a single #MON!
+ text_jump UnknownText_0x1c1062
+ db "@"
+
+.Text_ItsYourLastPKMN: ; 0xe533
+ ; You can't deposit your last #MON!
+ text_jump UnknownText_0x1c1080
+ db "@"
+
+CheckCurPartyMonFainted: ; e538
+ ld hl, PartyMon1HP
+ ld de, PARTYMON_STRUCT_LENGTH
+ ld b, $0
+.loop
+ ld a, [CurPartyMon]
+ cp b
+ jr z, .skip
+ ld a, [hli]
+ or [hl]
+ jr nz, .notfainted
+ dec hl
+
+.skip
+ inc b
+ ld a, [PartyCount]
+ cp b
+ jr z, .done
+ add hl, de
+ jr .loop
+
+.done
+ scf
+ ret
+
+.notfainted
+ and a
+ ret
+
+BillsPC_WithdrawMenu: ; e559 (3:6559)
+ call LoadStandardMenuDataHeader
+ callba _WithdrawPKMN
+ call ReturnToMapFromSubmenu
+ call ClearPCItemScreen
+ call CloseWindow
+ and a
+ ret
+
+Functione56d: ; unused
+ ld a, [PartyCount]
+ cp PARTY_LENGTH
+ jr nc, .asm_e576
+ and a
+ ret
+
+.asm_e576
+ ld hl, UnknownText_0xe57e
+ call MenuTextBoxBackup
+ scf
+ ret
+
+UnknownText_0xe57e: ; 0xe57e
+ ; You can't take any more #MON.
+ text_jump UnknownText_0x1c10a2
+ db "@"
+
+BillsPC_ChangeBoxMenu: ; e583 (3:6583)
+ callba _ChangeBox
+ and a
+ ret
+
+ClearPCItemScreen: ; e58b
+ call DisableSpriteUpdates
+ xor a
+ ld [hBGMapMode], a
+ call ClearBGPalettes
+ call ClearSprites
+ hlcoord 0, 0
+ ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
+ ld a, " "
+ call ByteFill
+ hlcoord 0,0
+ lb bc, 10, 18
+ call TextBox
+ hlcoord 0,12
+ lb bc, 4, 18
+ call TextBox
+ call WaitBGMap2
+ call SetPalettes ; load regular palettes?
+ ret
+
+CopyBoxmonToTempMon: ; e5bb
+ ld a, [CurPartyMon]
+ ld hl, sBoxMon1Species
+ ld bc, BOXMON_STRUCT_LENGTH
+ call AddNTimes
+ ld de, TempMonSpecies
+ ld bc, BOXMON_STRUCT_LENGTH
+ ld a, BANK(sBoxMon1Species)
+ call GetSRAMBank
+ call CopyBytes
+ call CloseSRAM
+ ret
+
+Functione5d9: ; unreferenced
+ ld a, [wCurBox]
+ cp b
+ jr z, .same_box
+ ld a, b
+ ld hl, .BoxAddrs
+ ld bc, 3
+ call AddNTimes
+ ld a, [hli]
+ push af
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ pop af
+ jr .okay
+
+.same_box
+ ld a, BANK(sBoxCount)
+ ld hl, sBoxCount
+
+.okay
+ call GetSRAMBank
+ ld a, [hl]
+ ld bc, 1 + MONS_PER_BOX + 1
+ add hl, bc
+ ld b, a
+ ld c, $0
+ ld de, wc608
+ ld a, b
+ and a
+ jr z, .empty_box
+.loop
+ push hl
+ push bc
+ ld a, c
+ ld bc, 0
+ add hl, bc
+ ld bc, BOXMON_STRUCT_LENGTH
+ call AddNTimes
+ ld a, [hl]
+ ld [de], a
+ inc de
+ ld [CurSpecies], a
+ call GetBaseData
+ pop bc
+ pop hl
+
+ push hl
+ push bc
+ ld a, c
+ ld bc, MONS_PER_BOX * (BOXMON_STRUCT_LENGTH + NAME_LENGTH)
+ add hl, bc
+ call SkipNames
+ call CopyBytes
+ pop bc
+ pop hl
+
+ push hl
+ push bc
+ ld a, c
+ ld bc, MON_LEVEL
+ add hl, bc
+ ld bc, BOXMON_STRUCT_LENGTH
+ call AddNTimes
+ ld a, [hl]
+ ld [de], a
+ inc de
+ pop bc
+ pop hl
+
+ push hl
+ push bc
+ ld a, c
+ ld bc, MON_DVS
+ add hl, bc
+ ld bc, BOXMON_STRUCT_LENGTH
+ call AddNTimes
+ ld a, [hli]
+ and $f0
+ ld b, a
+ ld a, [hl]
+ and $f0
+ swap a
+ or b
+ ld b, a
+ ld a, [BaseGender]
+ cp b
+ ld a, $1
+ jr c, .okay2
+ xor a
+.okay2
+ ld [de], a
+ inc de
+ pop bc
+ pop hl
+
+ inc c
+ dec b
+ jr nz, .loop
+.empty_box
+ call CloseSRAM
+ ret
+
+.BoxAddrs: ; e66e
+ dba sBox1
+ dba sBox2
+ dba sBox3
+ dba sBox4
+ dba sBox5
+ dba sBox6
+ dba sBox7
+ dba sBox8
+ dba sBox9
+ dba sBox10
+ dba sBox11
+ dba sBox12
+ dba sBox13
+ dba sBox14
diff --git a/engine/color.asm b/engine/color.asm
index 57f616955..435f0e57b 100644
--- a/engine/color.asm
+++ b/engine/color.asm
@@ -5,10 +5,8 @@ SHINY_ATK_BIT EQU 5
SHINY_DEF_VAL EQU 10
SHINY_SPD_VAL EQU 10
SHINY_SPC_VAL EQU 10
-LO_NYBBLE EQU $0f
-HI_NYBBLE EQU $f0
-CheckShininess: ; 8a68
+CheckShininess:
; Check if a mon is shiny by DVs at bc.
; Return carry if shiny.
@@ -22,19 +20,19 @@ CheckShininess: ; 8a68
; Defense
ld a, [hli]
- and LO_NYBBLE
+ and $f
cp SHINY_DEF_VAL
jr nz, .NotShiny
; Speed
ld a, [hl]
- and HI_NYBBLE
+ and $f0
cp SHINY_SPD_VAL << 4
jr nz, .NotShiny
; Special
ld a, [hl]
- and LO_NYBBLE
+ and $f
cp SHINY_SPC_VAL
jr nz, .NotShiny
@@ -45,10 +43,8 @@ CheckShininess: ; 8a68
.NotShiny
and a
ret
-; 8a88
-
-CheckContestMon: ; 8a88
+CheckContestMon:
; Check a mon's DVs at hl in the bug catching contest.
; Return carry if its DVs are good enough to place in the contest.
@@ -59,7 +55,7 @@ CheckContestMon: ; 8a88
; Defense
ld a, [hli]
- and LO_NYBBLE
+ and $f
cp 10
jr c, .Bad
@@ -70,7 +66,7 @@ CheckContestMon: ; 8a88
; Special
ld a, [hl]
- and LO_NYBBLE
+ and $f
cp 10
jr c, .Bad
@@ -81,10 +77,8 @@ CheckContestMon: ; 8a88
.Bad
and a
ret
-; 8aa4
-
-Function8aa4: ; 8aa4
+Function8aa4:
push de
push bc
ld hl, PalPacket_9ce6
@@ -106,16 +100,13 @@ Function8aa4: ; 8aa4
ld hl, BlkPacket_9a86
call Function9809
ret
-; 8ad1
-
-InitPartyMenuPalettes: ; 8ad1
+InitPartyMenuPalettes:
ld hl, PalPacket_9c56 + 1
call CopyFourPalettes
call InitPartyMenuOBPals
call WipeAttrMap
ret
-; 8ade
SGB_ApplyPartyMenuHPPals: ; 8ade SGB layout $fc
ld hl, wHPPals
@@ -142,9 +133,8 @@ SGB_ApplyPartyMenuHPPals: ; 8ade SGB layout $fc
pop de
ld [hl], e
ret
-; 8b07
-Function8b07: ; 8b07
+Function8b07:
; Unreferenced
call CheckCGB
ret z
@@ -177,9 +167,7 @@ Function8b07: ; 8b07
RGB 08, 16, 28
RGB 00, 00, 00
-; 8b3f
-
-Function8b3f: ; 8b3f
+Function8b3f:
; Unreferenced
call CheckCGB
ret nz
@@ -188,9 +176,8 @@ Function8b3f: ; 8b3f
ret z
ld hl, BlkPacket_9a86
jp Function9809
-; 8b4d
-Function8b4d: ; 8b4d
+Function8b4d:
call CheckCGB
jr nz, .cgb
ld a, [hSGB]
@@ -204,9 +191,8 @@ Function8b4d: ; 8b4d
ld a, $3b
call GetPredefPal
jp LoadHLPaletteIntoDE
-; 8b67
-Function8b67: ; 8b67
+Function8b67:
call CheckCGB
jr nz, .cgb
ld a, [hSGB]
@@ -220,9 +206,8 @@ Function8b67: ; 8b67
ld a, $3c
call GetPredefPal
jp LoadHLPaletteIntoDE
-; 8b81
-Function8b81: ; 8b81
+Function8b81:
call CheckCGB
jr nz, .asm_8bb2
ld a, [hSGB]
@@ -253,9 +238,8 @@ Function8b81: ; 8b81
call GetMonPalettePointer_
call LoadPalette_White_Col1_Col2_Black
ret
-; 8bbd
-Function8bbd: ; 8bbd
+Function8bbd:
ld a, [TrainerClass]
call GetTrainerPalettePointer
ld a, e
@@ -290,9 +274,8 @@ asm_8bd7
pop hl
call LoadPalette_White_Col1_Col2_Black
ret
-; 8bec
-Function8bec: ; 8bec
+Function8bec:
ld a, [hCGB]
and a
jr nz, .asm_8bf7
@@ -321,9 +304,8 @@ Function8bec: ; 8bec
call FillBoxCGB
call LoadEDTile
ret
-; 8c1d
-ApplyMonOrTrainerPals: ; 8c1d
+ApplyMonOrTrainerPals:
call CheckCGB
ret z
ld a, e
@@ -344,9 +326,8 @@ ApplyMonOrTrainerPals: ; 8c1d
call ApplyAttrMap
call ApplyPals
ret
-; 8c43
-ApplyHPBarPals: ; 8c43
+ApplyHPBarPals:
ld a, [wWhichHPBar]
and a
jr z, .Enemy
@@ -395,9 +376,8 @@ ApplyHPBarPals: ; 8c43
ld a, e
call FillBoxCGB
ret
-; 8c8a
-LoadStatsScreenPals: ; 8c8a
+LoadStatsScreenPals:
call CheckCGB
ret z
ld hl, StatsScreenPals
@@ -420,9 +400,8 @@ LoadStatsScreenPals: ; 8c8a
call ApplyPals
ld a, $1
ret
-; 8cb4
-Function8cb4: ; 8cb4
+Function8cb4:
ld l, e
ld h, 0
rept 3
@@ -463,9 +442,8 @@ endr
call WipeAttrMap
call ApplyAttrMap
ret
-; 8d05
-Palettes_8d05: ; 8d05
+Palettes_8d05:
RGB 20, 31, 11
RGB 31, 19, 00
RGB 31, 10, 09
@@ -516,12 +494,9 @@ Palettes_8d05: ; 8d05
RGB 00, 21, 00
RGB 00, 00, 00
-; 8d55
-
INCLUDE "predef/cgb.asm"
-
-Function95f0: ; 95f0
+Function95f0:
ld hl, Palette_9608
ld de, UnknBGPals
ld bc, 8
@@ -531,22 +506,18 @@ Function95f0: ; 95f0
call WipeAttrMap
call ApplyAttrMap
ret
-; 9608
-Palette_9608: ; 9608
+Palette_9608:
RGB 31, 31, 31
RGB 09, 31, 31
RGB 10, 12, 31
RGB 00, 03, 19
-; 9610
-
-
-CopyFourPalettes: ; 9610
+CopyFourPalettes:
ld de, UnknBGPals
ld c, $4
-CopyPalettes: ; 9615
+CopyPalettes:
.loop
push bc
ld a, [hli]
@@ -559,9 +530,8 @@ CopyPalettes: ; 9615
dec c
jr nz, .loop
ret
-; 9625
-GetPredefPal: ; 9625
+GetPredefPal:
ld l, a
ld h, $0
rept 3 ; multiply by 8
@@ -570,9 +540,8 @@ endr
ld bc, Palettes_9df6
add hl, bc
ret
-; 9630
-LoadHLPaletteIntoDE: ; 9630
+LoadHLPaletteIntoDE:
ld a, [rSVBK]
push af
ld a, $5
@@ -587,9 +556,8 @@ LoadHLPaletteIntoDE: ; 9630
pop af
ld [rSVBK], a
ret
-; 9643
-LoadPalette_White_Col1_Col2_Black: ; 9643
+LoadPalette_White_Col1_Col2_Black:
ld a, [rSVBK]
push af
ld a, $5
@@ -619,9 +587,8 @@ LoadPalette_White_Col1_Col2_Black: ; 9643
pop af
ld [rSVBK], a
ret
-; 9663
-FillBoxCGB: ; 9663
+FillBoxCGB:
.row
push bc
push hl
@@ -636,9 +603,8 @@ FillBoxCGB: ; 9663
dec b
jr nz, .row
ret
-; 9673
-Function9673: ; 9673
+Function9673:
push af
push bc
push de
@@ -667,27 +633,23 @@ endr
pop bc
pop af
ret
-; 9699
-
-WipeAttrMap: ; 9699
+WipeAttrMap:
hlcoord 0, 0, AttrMap
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
xor a
call ByteFill
ret
-; 96a4
-ApplyPals: ; 96a4
+ApplyPals:
ld hl, UnknBGPals
ld de, BGPals
ld bc, 16 palettes
ld a, $5
call FarCopyWRAM
ret
-; 96b3
-ApplyAttrMap: ; 96b3
+ApplyAttrMap:
ld a, [rLCDC]
bit 7, a
jr z, .UpdateVBank1
@@ -728,7 +690,6 @@ ApplyAttrMap: ; 96b3
ld a, $0
ld [rVBK], a
ret
-; 96f3
CGB_ApplyPartyMenuHPPals: ; 96f3 CGB layout $fc
ld hl, wHPPals
@@ -755,19 +716,16 @@ CGB_ApplyPartyMenuHPPals: ; 96f3 CGB layout $fc
ld a, e
call FillBoxCGB
ret
-; 971a
-
-InitPartyMenuOBPals: ; 971a
+InitPartyMenuOBPals:
ld hl, Palettes_b681
ld de, UnknOBPals
ld bc, 2 palettes
ld a, $5
call FarCopyWRAM
ret
-; 9729
-GetBattlemonBackpicPalettePointer: ; 9729
+GetBattlemonBackpicPalettePointer:
push de
callba GetPartyMonDVs
ld c, l
@@ -776,9 +734,8 @@ GetBattlemonBackpicPalettePointer: ; 9729
call GetPlayerOrMonPalettePointer
pop de
ret
-; 973a
-GetEnemyFrontpicPalettePointer: ; 973a
+GetEnemyFrontpicPalettePointer:
push de
callba GetEnemyMonDVs
ld c, l
@@ -787,9 +744,8 @@ GetEnemyFrontpicPalettePointer: ; 973a
call GetFrontpicPalettePointer
pop de
ret
-; 974b
-GetPlayerOrMonPalettePointer: ; 974b
+GetPlayerOrMonPalettePointer:
and a
jp nz, GetMonNormalOrShinyPalettePointer
ld a, [wPlayerSpriteSetupFlags]
@@ -804,14 +760,13 @@ GetPlayerOrMonPalettePointer: ; 974b
.male
ld hl, PlayerPalette
ret
-; 9764
-GetFrontpicPalettePointer: ; 9764
+GetFrontpicPalettePointer:
and a
jp nz, GetMonNormalOrShinyPalettePointer
ld a, [TrainerClass]
-GetTrainerPalettePointer: ; 976b
+GetTrainerPalettePointer:
ld l, a
ld h, 0
add hl,hl
@@ -819,14 +774,12 @@ GetTrainerPalettePointer: ; 976b
ld bc, TrainerPalettes
add hl, bc
ret
-; 9775
-GetMonPalettePointer_: ; 9775
+GetMonPalettePointer_:
call GetMonPalettePointer
ret
-; 9779
-Function9779: mobile ; 9779
+Function9779: mobile
call CheckCGB
ret z
ld hl, Palettes_979c
@@ -844,9 +797,8 @@ Function9779: mobile ; 9779
ld a, $5
call FarCopyWRAM
ret
-; 979c
-Palettes_979c: ; 979c
+Palettes_979c:
RGB 31, 31, 31
RGB 25, 25, 25
RGB 13, 13, 13
@@ -877,9 +829,7 @@ Palettes_979c: ; 979c
RGB 20, 15, 03
RGB 00, 00, 00
-; 97cc
-
-Function97cc: ; 97cc
+Function97cc:
call CheckCGB
ret z
ld a, $90
@@ -891,9 +841,8 @@ Function97cc: ; 97cc
call GetPredefPal
call Function97e5
ret
-; 97e5
-Function97e5: ; 97e5
+Function97e5:
ld c, 1 palettes
.loop
ld a, [hli]
@@ -901,9 +850,8 @@ Function97e5: ; 97e5
dec c
jr nz, .loop
ret
-; 97ee
-GetMonPalettePointer: ; 97ee
+GetMonPalettePointer:
ld l, a
ld h, $0
rept 3
@@ -912,9 +860,8 @@ endr
ld bc, PokemonPalettes
add hl, bc
ret
-; 97f9
-GetMonNormalOrShinyPalettePointer: ; 97f9
+GetMonNormalOrShinyPalettePointer:
push bc
call GetMonPalettePointer
pop bc
@@ -926,9 +873,8 @@ rept 4
inc hl
endr
ret
-; 9809
-Function9809: ; 9809
+Function9809:
ld a, [wcfbe]
push af
set 7, a
@@ -937,9 +883,8 @@ Function9809: ; 9809
pop af
ld [wcfbe], a
ret
-; 981a
-PushSGBPals: ; 981a
+PushSGBPals:
ld a, [hl]
and $7
ret z
@@ -978,9 +923,8 @@ PushSGBPals: ; 981a
dec b
jr nz, .loop
ret
-; 9853
-Function9853: ; 9853
+Function9853:
call CheckCGB
ret nz
di
@@ -1010,10 +954,8 @@ Function9853: ; 9853
ld [wcfbe], a
ei
ret
-; 9890
-
-Function9890:: ; 9890
+Function9890::
call CheckCGB
ret z
ld a, $1
@@ -1066,9 +1008,8 @@ Function9890:: ; 9890
dec c
jr nz, .loop
ret
-; 98eb
-Function98eb: ; 98eb
+Function98eb:
ld hl, .PalPacketPointerTable
ld c, 9
.loop
@@ -1084,9 +1025,8 @@ Function98eb: ; 98eb
dec c
jr nz, .loop
ret
-; 98ff
-.PalPacketPointerTable: ; 98ff
+.PalPacketPointerTable:
dw PalPacket_9d56
dw PalPacket_9d76
dw PalPacket_9d86
@@ -1096,9 +1036,8 @@ Function98eb: ; 98eb
dw PalPacket_9dc6
dw PalPacket_9dd6
dw PalPacket_9de6
-; 9911
-Function9911: ; 9911
+Function9911:
di
xor a
ld [rJOYP], a
@@ -1111,32 +1050,28 @@ Function9911: ; 9911
call PushSGBPals
ei
ret
-; 992c
-Function992c: ; 992c
+Function992c:
call .LoadSGBBorderPointers
push de
call Function9a24
pop hl
call Function99d8
ret
-; 9938
-.LoadSGBBorderPointers: ; 9938
+.LoadSGBBorderPointers:
ld hl, SGBBorder
ld de, SGBBorderMap
ret
-; 993f
-Function993f: ; 993f
+Function993f:
ld hl, VTiles0
ld bc, $2000
xor a
call ByteFill
ret
-; 994a
-Function994a: ; 994a
+Function994a:
ld hl, PalPacket_9d26
call PushSGBPals
call SGBDelayCycles
@@ -1180,15 +1115,13 @@ endr
call Function99ab
scf
ret
-; 99ab
-Function99ab: ; 99ab
+Function99ab:
ld hl, PalPacket_9d16
call PushSGBPals
jp SGBDelayCycles
-; 99b4
-Function99b4: ; 99b4
+Function99b4:
call DisableLCD
ld a, $e4
ld [rBGP], a
@@ -1204,9 +1137,8 @@ Function99b4: ; 99b4
xor a
ld [rBGP], a
ret
-; 99d8
-Function99d8: ; 99d8
+Function99d8:
call DisableLCD
ld a, $e4
ld [rBGP], a
@@ -1239,9 +1171,8 @@ Function99d8: ; 99d8
xor a
ld [rBGP], a
ret
-; 9a24
-Function9a24: ; 9a24
+Function9a24:
call DisableLCD
ld a, %11100100
ld [rBGP], a
@@ -1264,7 +1195,6 @@ Function9a24: ; 9a24
xor a
ld [rBGP], a
ret
-; 9a52
CopyData: ; 0x9a52
; copy bc bytes of data from hl to de
@@ -1310,7 +1240,7 @@ DrawDefaultTiles: ; 0x9a64
ret
; 0x9a7a
-SGBDelayCycles: ; 9a7a
+SGBDelayCycles:
ld de, 7000
.wait
nop
@@ -1321,51 +1251,47 @@ SGBDelayCycles: ; 9a7a
or e
jr nz, .wait
ret
-; 9a86
-BlkPacket_9a86: ; 9a86
+BlkPacket_9a86:
db $21, $01, $03, $00, $00, $00, $13, $11, $00, $00, $00, $00, $00, $00, $00, $00
-BlkPacket_9a96: ; 9a96
+BlkPacket_9a96:
db $21, $01, $07, $05, $00, $0a, $13, $0d, $00, $00, $00, $00, $00, $00, $00, $00
-BlkPacket_9aa6: ; 9a86
+BlkPacket_9aa6:
db $22, $05, $07, $0a, $00, $0c, $13, $11, $03, $05, $01, $00, $0a, $03, $03, $00
db $0a, $08, $13, $0a, $03, $0a, $00, $04, $08, $0b, $03, $0f, $0b, $00, $13, $07
-BlkPacket_9ac6: ; 9a86
+BlkPacket_9ac6:
db $21, $01, $07, $05, $00, $01, $07, $07, $00, $00, $00, $00, $00, $00, $00, $00
-BlkPacket_9ad6: ; 9a86
+BlkPacket_9ad6:
db $21, $01, $07, $05, $0b, $01, $13, $02, $00, $00, $00, $00, $00, $00, $00, $00
-BlkPacket_9ae6: ; 9a86
+BlkPacket_9ae6:
db $21, $01, $07, $05, $01, $01, $08, $08, $00, $00, $00, $00, $00, $00, $00, $00
-BlkPacket_9af6: ; 9a86
+BlkPacket_9af6:
db $21, $01, $07, $05, $07, $05, $0d, $0b, $00, $00, $00, $00, $00, $00, $00, $00
-BlkPacket_9b06: ; 9a86
+BlkPacket_9b06:
db $22, $05, $03, $05, $00, $00, $13, $0b, $03, $0a, $00, $04, $13, $09, $02, $0f
db $00, $06, $13, $07, $03, $00, $04, $04, $0f, $09, $03, $00, $00, $0c, $13, $11
-BlkPacket_9b26: ; 9a86
+BlkPacket_9b26:
db $23, $07, $07, $10, $00, $00, $02, $0c, $02, $00, $0c, $00, $12, $01, $02, $00
db $0c, $02, $12, $03, $02, $00, $0c, $04, $12, $05, $02, $00, $0c, $06, $12, $07
db $02, $00, $0c, $08, $12, $09, $02, $00, $0c, $0a, $12, $0b, $00, $00, $00, $00
-BlkPacket_9b56: ; 9a86
+BlkPacket_9b56:
db $22, $03, $07, $20, $00, $00, $13, $04, $03, $0f, $00, $06, $13, $11, $03, $05
db $0f, $01, $12, $04, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
-BlkPacket_9b76: ; 9a86
+BlkPacket_9b76:
db $21, $01, $07, $10, $00, $00, $13, $05, $00, $00, $00, $00, $00, $00, $00, $00
-BlkPacket_9b86: ; 9a86
+BlkPacket_9b86:
db $21, $02, $07, $0a, $00, $04, $13, $0d, $03, $05, $00, $06, $13, $0b, $00, $00
-; 9b96
-
-; 9b96
PalPacket_9b96: db $51, $48, $00, $49, $00, $4a, $00, $4b, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9ba6: db $51, $2b, $00, $24, $00, $20, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
@@ -1405,9 +1331,8 @@ PalPacket_9db6: db $79, $31, $08, $00, $0b, $0c, $a5, $ca, $c9, $7e, $d0, $06, $
PalPacket_9dc6: db $79, $26, $08, $00, $0b, $39, $cd, $48, $0c, $d0, $34, $a5, $c9, $c9, $80, $d0
PalPacket_9dd6: db $79, $1b, $08, $00, $0b, $ea, $ea, $ea, $ea, $ea, $a9, $01, $cd, $4f, $0c, $d0
PalPacket_9de6: db $79, $10, $08, $00, $0b, $4c, $20, $08, $ea, $ea, $ea, $ea, $ea, $60, $ea, $ea
-; 9df6
-Palettes_9df6: ; 9df6
+Palettes_9df6:
RGB 31, 31, 31
RGB 22, 25, 19
RGB 16, 21, 30
@@ -1803,9 +1728,7 @@ Palettes_9df6: ; 9df6
RGB 21, 21, 21
RGB 31, 31, 31
-; a06e
-
-SGBBorderMap: ; a06e
+SGBBorderMap:
db $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $14,$14, $15,$14, $16,$14, $17,$14, $17,$54, $16,$54, $15,$54, $14,$54, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14
db $01,$14, $02,$14, $03,$14, $03,$54, $02,$54, $01,$54, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $24,$14, $25,$14, $26,$14, $07,$14, $07,$54, $26,$54, $25,$54, $24,$54, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$54, $01,$14, $02,$14, $03,$14, $03,$54, $02,$54, $01,$54
db $11,$14, $12,$14, $13,$14, $13,$54, $12,$54, $11,$54, $10,$54, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $24,$14, $34,$14, $35,$14, $35,$54, $34,$54, $33,$54, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $10,$14, $11,$14, $12,$14, $13,$14, $13,$54, $12,$54, $11,$54
@@ -1834,9 +1757,8 @@ SGBBorderMap: ; a06e
db $25,$14, $26,$14, $07,$14, $07,$54, $26,$54, $25,$54, $24,$54, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $01,$14, $02,$14, $03,$14, $03,$54, $02,$54, $01,$54, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $24,$14, $25,$14, $26,$14, $07,$14, $07,$54, $26,$54, $25,$54
db $33,$14, $34,$14, $35,$14, $35,$54, $34,$54, $24,$54, $07,$54, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $10,$14, $11,$14, $12,$14, $13,$14, $13,$54, $12,$54, $11,$54, $10,$54, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $24,$14, $34,$14, $35,$14, $35,$54, $34,$54, $33,$54
db $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $20,$14, $21,$14, $22,$14, $23,$14, $23,$54, $22,$54, $21,$54, $20,$54, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14, $07,$14
-; a49e
-SGBBorderPalettes: ; a49e
+SGBBorderPalettes:
RGB 24, 06, 06
RGB 24, 24, 26
RGB 14, 15, 20
@@ -1917,13 +1839,10 @@ SGBBorderPalettes: ; a49e
RGB 31, 31, 25
RGB 31, 31, 25
-; a51e
-
-SGBBorder: ; a51e
+SGBBorder:
INCBIN "gfx/misc/sgb_border.2bpp"
-; a8be
-Palettes_a8be: ; a8be
+Palettes_a8be:
RGB 30, 26, 15
RGB 00, 23, 00
@@ -1933,23 +1852,19 @@ Palettes_a8be: ; a8be
RGB 30, 26, 15
RGB 31, 00, 00
-Palettes_a8ca: ; a8ca
+Palettes_a8ca:
RGB 30, 26, 15
RGB 04, 17, 31
-; a8ce
-; a8ce
INCLUDE "gfx/pics/palette_pointers.asm"
-; b0ce
-; b0ce
INCLUDE "gfx/trainers/palette_pointers.asm"
-; b1de
-LoadMapPals: ; b1de
+LoadMapPals:
callba LoadSpecialMapPalette
jr c, .got_pals
+ ; Which palette group is based on whether we're outside or inside
ld a, [wPermission]
and 7
ld e, a
@@ -1960,16 +1875,18 @@ LoadMapPals: ; b1de
ld a, [hli]
ld h, [hl]
ld l, a
+ ; Futher refine by time of day
ld a, [TimeOfDayPal]
and 3
-rept 3
add a
-endr
+ add a
+ add a
ld e, a
ld d, 0
add hl, de
ld e, l
ld d, h
+ ; Switch to palettes WRAM bank
ld a, [rSVBK]
push af
ld a, $5
@@ -1977,14 +1894,14 @@ endr
ld hl, UnknBGPals
ld b, 8
.outer_loop
- ld a, [de]
+ ld a, [de] ; lookup index for TilesetBGPalette
push de
push hl
ld l, a
ld h, 0
-rept 3
- add hl,hl
-endr
+ add hl, hl
+ add hl, hl
+ add hl, hl
ld de, TilesetBGPalette
add hl, de
ld e, l
@@ -2042,43 +1959,41 @@ endr
ld a, $5
call FarCopyWRAM
ret
-; b279
-
-.TilesetColorsPointers: ; b279
- dw TilesetColors1
- dw TilesetColors1
- dw TilesetColors1
- dw TilesetColors2
- dw TilesetColors3
- dw TilesetColors4
- dw TilesetColors2
- dw TilesetColors3
-; b289
-
-TilesetColors1: ; b289
- db $00, $01, $02, $28, $04, $05, $06, $07
- db $08, $09, $0a, $28, $0c, $0d, $0e, $0f
- db $10, $11, $12, $29, $14, $15, $16, $17
- db $18, $19, $1a, $1b, $1c, $1d, $1e, $1f
-
-TilesetColors2: ; b289
- db $20, $21, $22, $23, $24, $25, $26, $07
- db $20, $21, $22, $23, $24, $25, $26, $07
- db $10, $11, $12, $13, $14, $15, $16, $07
- db $18, $19, $1a, $1b, $1c, $1d, $1e, $07
-
-TilesetColors3: ; b289
- db $00, $01, $02, $03, $04, $05, $06, $07
- db $08, $09, $0a, $0b, $0c, $0d, $0e, $0f
- db $10, $11, $12, $13, $14, $15, $16, $17
- db $18, $19, $1a, $1b, $1c, $1d, $1e, $1f
-
-TilesetColors4: ; b289
- db $00, $01, $02, $03, $04, $05, $06, $07
- db $08, $09, $0a, $0b, $0c, $0d, $0e, $0f
- db $10, $11, $12, $13, $14, $15, $16, $17
- db $18, $19, $1a, $1b, $1c, $1d, $1e, $1f
-; b309
+
+.TilesetColorsPointers
+ dw .OutdoorColors ; unused
+ dw .OutdoorColors ; TOWN
+ dw .OutdoorColors ; ROUTE
+ dw .IndoorColors ; INDOOR
+ dw .DungeonColors ; CAVE
+ dw .Perm5Colors ; PERM_5
+ dw .IndoorColors ; GATE
+ dw .DungeonColors ; DUNGEON
+
+; Valid indices: $00 - $29
+.OutdoorColors
+ db $00, $01, $02, $28, $04, $05, $06, $07 ; morn
+ db $08, $09, $0a, $28, $0c, $0d, $0e, $0f ; day
+ db $10, $11, $12, $29, $14, $15, $16, $17 ; nite
+ db $18, $19, $1a, $1b, $1c, $1d, $1e, $1f ; dark
+
+.IndoorColors
+ db $20, $21, $22, $23, $24, $25, $26, $07 ; morn
+ db $20, $21, $22, $23, $24, $25, $26, $07 ; day
+ db $10, $11, $12, $13, $14, $15, $16, $07 ; nite
+ db $18, $19, $1a, $1b, $1c, $1d, $1e, $07 ; dark
+
+.DungeonColors
+ db $00, $01, $02, $03, $04, $05, $06, $07 ; morn
+ db $08, $09, $0a, $0b, $0c, $0d, $0e, $0f ; day
+ db $10, $11, $12, $13, $14, $15, $16, $17 ; nite
+ db $18, $19, $1a, $1b, $1c, $1d, $1e, $1f ; dark
+
+.Perm5Colors
+ db $00, $01, $02, $03, $04, $05, $06, $07 ; morn
+ db $08, $09, $0a, $0b, $0c, $0d, $0e, $0f ; day
+ db $10, $11, $12, $13, $14, $15, $16, $17 ; nite
+ db $18, $19, $1a, $1b, $1c, $1d, $1e, $1f ; dark
Palette_b309: ; b309 mobile
RGB 31, 31, 31
@@ -2086,26 +2001,22 @@ Palette_b309: ; b309 mobile
RGB 30, 10, 06
RGB 00, 00, 00
-; b311
-
Palette_b311: ; b311 not mobile
RGB 31, 31, 31
RGB 17, 19, 31
RGB 14, 16, 31
RGB 00, 00, 00
-; b319
-
-TilesetBGPalette: ; b319
+TilesetBGPalette:
INCLUDE "tilesets/bg.pal"
-MapObjectPals:: ; b469
+MapObjectPals::
INCLUDE "tilesets/ob.pal"
-RoofPals: ; b569
+RoofPals:
INCLUDE "tilesets/roof.pal"
-Palettes_b641: ; b641
+Palettes_b641:
RGB 27, 31, 27
RGB 21, 21, 21
RGB 13, 13, 13
@@ -2146,9 +2057,7 @@ Palettes_b641: ; b641
RGB 07, 07, 12
RGB 00, 00, 00
-; b681
-
-Palettes_b681: ; b681
+Palettes_b681:
RGB 27, 31, 27
RGB 31, 19, 10
RGB 31, 07, 04
@@ -2219,8 +2128,7 @@ Palettes_b681: ; b681
RGB 20, 15, 03
RGB 07, 07, 07
-
-Palettes_b6f1: ; b6f1
+Palettes_b6f1:
RGB 31, 31, 31
RGB 18, 23, 31
RGB 15, 20, 31
@@ -2246,8 +2154,7 @@ Palettes_b6f1: ; b6f1
RGB 18, 23, 31
RGB 00, 00, 00
-
-Palettes_b719: ; b719
+Palettes_b719:
RGB 31, 31, 31
RGB 07, 06, 03
RGB 07, 06, 03
@@ -2258,9 +2165,7 @@ Palettes_b719: ; b719
RGB 26, 22, 00
RGB 00, 00, 00
-; b729
-
-MalePokegearPals: ; b729
+MalePokegearPals:
RGB 28, 31, 20
RGB 21, 21, 21
RGB 13, 13, 13
@@ -2291,9 +2196,7 @@ MalePokegearPals: ; b729
RGB 15, 07, 00
RGB 31, 00, 00
-; b759
-
-FemalePokegearPals: ; b759
+FemalePokegearPals:
RGB 28, 31, 20
RGB 21, 21, 21
RGB 13, 13, 13
@@ -2324,9 +2227,7 @@ FemalePokegearPals: ; b759
RGB 15, 07, 00
RGB 31, 00, 00
-; b789
-
-Palettes_b789: ; b789
+Palettes_b789:
RGB 31, 31, 31
RGB 30, 22, 24
RGB 18, 18, 18
@@ -2347,9 +2248,7 @@ Palettes_b789: ; b789
RGB 18, 18, 18
RGB 00, 00, 00
-; b7a9
-
-Palettes_b7a9: ; b7a9
+Palettes_b7a9:
RGB 31, 31, 31
RGB 24, 25, 28
RGB 24, 24, 09
@@ -2430,4 +2329,3 @@ Palettes_b7a9: ; b7a9
RGB 00, 00, 00
RGB 00, 00, 00
-; b829
diff --git a/engine/health.asm b/engine/health.asm
new file mode 100755
index 000000000..1c926f677
--- /dev/null
+++ b/engine/health.asm
@@ -0,0 +1,110 @@
+HealParty: ; c658
+ xor a
+ ld [CurPartyMon], a
+ ld hl, PartySpecies
+.loop
+ ld a, [hli]
+ cp -1
+ jr z, .done
+ cp EGG
+ jr z, .next
+
+ push hl
+ call HealPartyMon
+ pop hl
+
+.next
+ ld a, [CurPartyMon]
+ inc a
+ ld [CurPartyMon], a
+ jr .loop
+
+.done
+ ret
+
+HealPartyMon: ; c677
+ ld a, MON_SPECIES
+ call GetPartyParamLocation
+ ld d, h
+ ld e, l
+
+ ld hl, MON_STATUS
+ add hl, de
+ xor a
+ ld [hli], a
+ ld [hl], a
+
+ ld hl, MON_MAXHP
+ add hl, de
+
+ ; bc = MON_HP
+ ld b, h
+ ld c, l
+ dec bc
+ dec bc
+
+ ld a, [hli]
+ ld [bc], a
+ inc bc
+ ld a, [hl]
+ ld [bc], a
+
+ callba RestoreAllPP
+ ret
+
+ComputeHPBarPixels: ; c699
+; e = bc * (6 * 8) / de
+ ld a, b
+ or c
+ jr z, .zero
+ push hl
+ xor a
+ ld [hMultiplicand + 0], a
+ ld a, b
+ ld [hMultiplicand + 1], a
+ ld a, c
+ ld [hMultiplicand + 2], a
+ ld a, 6 * 8
+ ld [hMultiplier], a
+ call Multiply
+ ; We need de to be under 256 because hDivisor is only 1 byte.
+ ld a, d
+ and a
+ jr z, .divide
+ ; divide de and hProduct by 4
+ srl d
+ rr e
+ srl d
+ rr e
+ ld a, [hProduct + 2]
+ ld b, a
+ ld a, [hProduct + 3]
+ srl b
+ rr a
+ srl b
+ rr a
+ ld [hDividend + 3], a
+ ld a, b
+ ld [hDividend + 2], a
+.divide
+ ld a, e
+ ld [hDivisor], a
+ ld b, 4
+ call Divide
+ ld a, [hQuotient + 2]
+ ld e, a
+ pop hl
+ and a
+ ret nz
+ ld e, 1
+ ret
+
+.zero
+ ld e, 0
+ ret
+
+AnimateHPBar: ; c6e0
+ call WaitBGMap
+ call _AnimateHPBar
+ call WaitBGMap
+ ret
diff --git a/engine/init_gender.asm b/engine/init_gender.asm
index 5de576c2a..ff5babdf9 100755
--- a/engine/init_gender.asm
+++ b/engine/init_gender.asm
@@ -67,7 +67,7 @@ TextJump_AreYouABoyOrAreYouAGirl: ; 0x48e0f
InitGenderScreen: ; 48e14 (12:4e14)
ld a, $10
ld [MusicFade], a
- ld a, $0
+ ld a, MUSIC_NONE
ld [MusicFadeIDLo], a
ld a, $0
ld [MusicFadeIDHi], a
diff --git a/engine/items.asm b/engine/items.asm
new file mode 100755
index 000000000..ede8e4f73
--- /dev/null
+++ b/engine/items.asm
@@ -0,0 +1,584 @@
+_ReceiveItem:: ; d1d5
+ call DoesHLEqualNumItems
+ jp nz, PutItemInPocket
+ push hl
+ call CheckItemPocket
+ pop de
+ ld a, [wItemAttributeParamBuffer]
+ dec a
+ ld hl, .Pockets
+ rst JumpTable
+ ret
+
+.Pockets: ; d1e9
+ dw .Item
+ dw .KeyItem
+ dw .Ball
+ dw .TMHM
+
+.Item: ; d1f1
+ ld h, d
+ ld l, e
+ jp PutItemInPocket
+
+.KeyItem: ; d1f6
+ ld h, d
+ ld l, e
+ jp ReceiveKeyItem
+
+.Ball: ; d1fb
+ ld hl, NumBalls
+ jp PutItemInPocket
+
+.TMHM: ; d201
+ ld h, d
+ ld l, e
+ ld a, [CurItem]
+ ld c, a
+ call GetTMHMNumber
+ jp ReceiveTMHM
+
+_TossItem:: ; d20d
+ call DoesHLEqualNumItems
+ jr nz, .remove
+ push hl
+ call CheckItemPocket
+ pop de
+ ld a, [wItemAttributeParamBuffer]
+ dec a
+ ld hl, .Pockets
+ rst JumpTable
+ ret
+
+.Pockets
+ dw .Item
+ dw .KeyItem
+ dw .Ball
+ dw .TMHM
+
+.Ball ; d228
+ ld hl, NumBalls
+ jp RemoveItemFromPocket
+
+.TMHM ; d22e
+ ld h, d
+ ld l, e
+ ld a, [CurItem]
+ ld c, a
+ call GetTMHMNumber
+ jp TossTMHM
+
+.KeyItem ; d23a
+ ld h, d
+ ld l, e
+ jp TossKeyItem
+
+.Item ; d23f
+ ld h, d
+ ld l, e
+
+.remove
+ jp RemoveItemFromPocket
+
+_CheckItem:: ; d244
+ call DoesHLEqualNumItems
+ jr nz, .nope
+ push hl
+ call CheckItemPocket
+ pop de
+ ld a, [wItemAttributeParamBuffer]
+ dec a
+ ld hl, .Pockets
+ rst JumpTable
+ ret
+
+.Pockets
+ dw .Item
+ dw .KeyItem
+ dw .Ball
+ dw .TMHM
+
+.Ball ; d25f
+ ld hl, NumBalls
+ jp CheckTheItem
+
+.TMHM ; d265
+ ld h, d
+ ld l, e
+ ld a, [CurItem]
+ ld c, a
+ call GetTMHMNumber
+ jp CheckTMHM
+
+.KeyItem ; d271
+ ld h, d
+ ld l, e
+ jp CheckKeyItems
+
+.Item ; d276
+ ld h, d
+ ld l, e
+
+.nope
+ jp CheckTheItem
+
+DoesHLEqualNumItems: ; d27b
+ ld a, l
+ cp NumItems % $100
+ ret nz
+ ld a, h
+ cp NumItems / $100
+ ret
+
+GetPocketCapacity: ; d283
+ ld c, MAX_ITEMS
+ ld a, e
+ cp NumItems % $100
+ jr nz, .not_bag
+ ld a, d
+ cp NumItems / $100
+ ret z
+
+.not_bag
+ ld c, MAX_PC_ITEMS
+ ld a, e
+ cp PCItems % $100
+ jr nz, .not_pc
+ ld a, d
+ cp PCItems / $100
+ ret z
+
+.not_pc
+ ld c, MAX_BALLS
+ ret
+
+PutItemInPocket: ; d29c
+ ld d, h
+ ld e, l
+ inc hl
+ ld a, [CurItem]
+ ld c, a
+ ld b, 0
+.loop
+ ld a, [hli]
+ cp -1
+ jr z, .terminator
+ cp c
+ jr nz, .next
+ ld a, 99
+ sub [hl]
+ add b
+ ld b, a
+ ld a, [wItemQuantityChangeBuffer]
+ cp b
+ jr z, .ok
+ jr c, .ok
+
+.next
+ inc hl
+ jr .loop
+
+.terminator
+ call GetPocketCapacity
+ ld a, [de]
+ cp c
+ jr c, .ok
+ and a
+ ret
+
+.ok
+ ld h, d
+ ld l, e
+ ld a, [CurItem]
+ ld c, a
+ ld a, [wItemQuantityChangeBuffer]
+ ld [wItemQuantityBuffer], a
+.loop2
+ inc hl
+ ld a, [hli]
+ cp -1
+ jr z, .terminator2
+ cp c
+ jr nz, .loop2
+ ld a, [wItemQuantityBuffer]
+ add [hl]
+ cp 100
+ jr nc, .newstack
+ ld [hl], a
+ jr .done
+
+.newstack
+ ld [hl], 99
+ sub 99
+ ld [wItemQuantityBuffer], a
+ jr .loop2
+
+.terminator2
+ dec hl
+ ld a, [CurItem]
+ ld [hli], a
+ ld a, [wItemQuantityBuffer]
+ ld [hli], a
+ ld [hl], -1
+ ld h, d
+ ld l, e
+ inc [hl]
+
+.done
+ scf
+ ret
+
+RemoveItemFromPocket: ; d2ff
+ ld d, h
+ ld e, l
+ ld a, [hli]
+ ld c, a
+ ld a, [CurItemQuantity]
+ cp c
+ jr nc, .ok ; memory
+ ld c, a
+ ld b, $0
+ add hl, bc
+ add hl, bc
+ ld a, [CurItem]
+ cp [hl]
+ inc hl
+ jr z, .skip
+ ld h, d
+ ld l, e
+ inc hl
+
+.ok
+ ld a, [CurItem]
+ ld b, a
+.loop
+ ld a, [hli]
+ cp b
+ jr z, .skip
+ cp -1
+ jr z, .nope
+ inc hl
+ jr .loop
+
+.skip
+ ld a, [wItemQuantityChangeBuffer]
+ ld b, a
+ ld a, [hl]
+ sub b
+ jr c, .nope
+ ld [hl], a
+ ld [wItemQuantityBuffer], a
+ and a
+ jr nz, .yup
+ dec hl
+ ld b, h
+ ld c, l
+ inc hl
+ inc hl
+.loop2
+ ld a, [hli]
+ ld [bc], a
+ inc bc
+ cp -1
+ jr nz, .loop2
+ ld h, d
+ ld l, e
+ dec [hl]
+
+.yup
+ scf
+ ret
+
+.nope
+ and a
+ ret
+
+CheckTheItem: ; d349
+ ld a, [CurItem]
+ ld c, a
+.loop
+ inc hl
+ ld a, [hli]
+ cp -1
+ jr z, .done
+ cp c
+ jr nz, .loop
+ scf
+ ret
+
+.done
+ and a
+ ret
+
+ReceiveKeyItem: ; d35a
+ ld hl, NumKeyItems
+ ld a, [hli]
+ cp MAX_KEY_ITEMS
+ jr nc, .nope
+ ld c, a
+ ld b, 0
+ add hl, bc
+ ld a, [CurItem]
+ ld [hli], a
+ ld [hl], -1
+ ld hl, NumKeyItems
+ inc [hl]
+ scf
+ ret
+
+.nope
+ and a
+ ret
+
+TossKeyItem: ; d374
+ ld a, [wd107]
+ ld e, a
+ ld d, 0
+ ld hl, NumKeyItems
+ ld a, [hl]
+ cp e
+ jr nc, .ok
+ call .Toss
+ ret nc
+ jr .ok2
+
+.ok
+ dec [hl]
+ inc hl
+ add hl, de
+
+.ok2
+ ld d, h
+ ld e, l
+ inc hl
+.loop
+ ld a, [hli]
+ ld [de], a
+ inc de
+ cp -1
+ jr nz, .loop
+ scf
+ ret
+
+.Toss: ; d396
+ ld hl, NumKeyItems
+ ld a, [CurItem]
+ ld c, a
+.loop3
+ inc hl
+ ld a, [hl]
+ cp c
+ jr z, .ok3
+ cp -1
+ jr nz, .loop3
+ xor a
+ ret
+
+.ok3
+ ld a, [NumKeyItems]
+ dec a
+ ld [NumKeyItems], a
+ scf
+ ret
+
+CheckKeyItems: ; d3b1
+ ld a, [CurItem]
+ ld c, a
+ ld hl, KeyItems
+.loop
+ ld a, [hli]
+ cp c
+ jr z, .done
+ cp -1
+ jr nz, .loop
+ and a
+ ret
+
+.done
+ scf
+ ret
+
+ReceiveTMHM: ; d3c4
+ dec c
+ ld b, 0
+ ld hl, TMsHMs
+ add hl, bc
+ ld a, [wItemQuantityChangeBuffer]
+ add [hl]
+ cp 100
+ jr nc, .toomany
+ ld [hl], a
+ scf
+ ret
+
+.toomany
+ and a
+ ret
+
+TossTMHM: ; d3d8
+ dec c
+ ld b, 0
+ ld hl, TMsHMs
+ add hl, bc
+ ld a, [wItemQuantityChangeBuffer]
+ ld b, a
+ ld a, [hl]
+ sub b
+ jr c, .nope
+ ld [hl], a
+ ld [wItemQuantityBuffer], a
+ jr nz, .yup
+ ld a, [wTMHMPocketScrollPosition]
+ and a
+ jr z, .yup
+ dec a
+ ld [wTMHMPocketScrollPosition], a
+
+.yup
+ scf
+ ret
+
+.nope
+ and a
+ ret
+
+CheckTMHM: ; d3fb
+ dec c
+ ld b, $0
+ ld hl, TMsHMs
+ add hl, bc
+ ld a, [hl]
+ and a
+ ret z
+ scf
+ ret
+
+GetTMHMNumber:: ; d407
+; Return the number of a TM/HM by item id c.
+
+ ld a, c
+
+; Skip any dummy items.
+ cp ITEM_C3 ; TM04-05
+ jr c, .done
+ cp ITEM_DC ; TM28-29
+ jr c, .skip
+
+ dec a
+.skip
+ dec a
+.done
+ sub TM01
+ inc a
+ ld c, a
+ ret
+
+GetNumberedTMHM: ; d417
+; Return the item id of a TM/HM by number c.
+
+ ld a, c
+
+; Skip any gaps.
+ cp ITEM_C3 - (TM01 - 1)
+ jr c, .done
+ cp ITEM_DC - (TM01 - 1) - 1
+ jr c, .skip_one
+
+.skip_two
+ inc a
+.skip_one
+ inc a
+.done
+ add TM01
+ dec a
+ ld c, a
+ ret
+
+_CheckTossableItem:: ; d427
+; Return 1 in wItemAttributeParamBuffer and carry if CurItem can't be removed from the bag.
+ ld a, ITEMATTR_PERMISSIONS
+ call GetItemAttr
+ bit 7, a
+ jr nz, ItemAttr_ReturnCarry
+ and a
+ ret
+
+CheckSelectableItem: ; d432
+; Return 1 in wItemAttributeParamBuffer and carry if CurItem can't be selected.
+ ld a, ITEMATTR_PERMISSIONS
+ call GetItemAttr
+ bit 6, a
+ jr nz, ItemAttr_ReturnCarry
+ and a
+ ret
+
+CheckItemPocket:: ; d43d
+; Return the pocket for CurItem in wItemAttributeParamBuffer.
+ ld a, ITEMATTR_POCKET
+ call GetItemAttr
+ and $f
+ ld [wItemAttributeParamBuffer], a
+ ret
+
+CheckItemContext: ; d448
+; Return the context for CurItem in wItemAttributeParamBuffer.
+ ld a, ITEMATTR_HELP
+ call GetItemAttr
+ and $f
+ ld [wItemAttributeParamBuffer], a
+ ret
+
+CheckItemMenu: ; d453
+; Return the menu for CurItem in wItemAttributeParamBuffer.
+ ld a, ITEMATTR_HELP
+ call GetItemAttr
+ swap a
+ and $f
+ ld [wItemAttributeParamBuffer], a
+ ret
+
+GetItemAttr: ; d460
+; Get attribute a of CurItem.
+
+ push hl
+ push bc
+
+ ld hl, ItemAttributes
+ ld c, a
+ ld b, 0
+ add hl, bc
+
+ xor a
+ ld [wItemAttributeParamBuffer], a
+
+ ld a, [CurItem]
+ dec a
+ ld c, a
+ ld a, NUM_ITEMATTRS
+ call AddNTimes
+ ld a, BANK(ItemAttributes)
+ call GetFarByte
+
+ pop bc
+ pop hl
+ ret
+
+ItemAttr_ReturnCarry: ; d47f
+ ld a, 1
+ ld [wItemAttributeParamBuffer], a
+ scf
+ ret
+
+GetItemPrice: ; d486
+; Return the price of CurItem in de.
+ push hl
+ push bc
+ ld a, ITEMATTR_PRICE
+ call GetItemAttr
+ ld e, a
+ ld a, ITEMATTR_PRICE_HI
+ call GetItemAttr
+ ld d, a
+ pop bc
+ pop hl
+ ret
diff --git a/engine/main_menu.asm b/engine/main_menu.asm
index 637253c12..2c9afcc07 100755
--- a/engine/main_menu.asm
+++ b/engine/main_menu.asm
@@ -202,7 +202,7 @@ MainMenuJoypadLoop: ; 49de4
ld a, [w2DMenuFlags1]
set 5, a
ld [w2DMenuFlags1], a
- call Function1f1a
+ call GetScrollingMenuJoypad
ld a, [wMenuJoypad]
cp B_BUTTON
jr z, .b_button
diff --git a/engine/map_setup.asm b/engine/map_setup.asm
index 8fa768c87..952c12ac1 100644
--- a/engine/map_setup.asm
+++ b/engine/map_setup.asm
@@ -248,7 +248,7 @@ MapSetupCommands: ; 15440
dba EnterMapMusic ; 07
dba ForceMapMusic ; 08
dba FadeInMusic ; 09
- dba LoadBlockData ; 0a
+ dba LoadBlockData ; 0a (callback 1)
dba LoadNeighboringBlockData ; 0b
dba SaveScreen ; 0c
dba BufferScreen ; 0d
diff --git a/engine/mon_icons.asm b/engine/mon_icons.asm
index 5e41cd4a1..6a5c7484f 100755
--- a/engine/mon_icons.asm
+++ b/engine/mon_icons.asm
@@ -14,7 +14,7 @@ LoadOverworldMonIcon: ; 8e82b
ret
; 8e83f
-Function8e83f: ; 8e83f
+LoadMenuMonIcon: ; 8e83f
push hl
push de
push bc
@@ -28,9 +28,8 @@ Function8e83f: ; 8e83f
.LoadIcon: ; 8e849
ld d, 0
ld hl, .Jumptable
-rept 2
add hl, de
-endr
+ add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
@@ -39,13 +38,13 @@ endr
.Jumptable: ; 8e854 (23:6854)
- dw Function8e8d5 ; init
- dw Function8e961
- dw Function8e97d
- dw Trade_LoadMonIconGFX
- dw Function8e898
- dw Mobile_InitPartyMenuBGPal71
- dw .GetPartyMenuMonIcon
+ dw Function8e8d5 ; party menu
+ dw Function8e961 ; naming screen
+ dw Function8e97d ; moves (?)
+ dw Trade_LoadMonIconGFX ; trade
+ dw Function8e898 ; mobile
+ dw Mobile_InitPartyMenuBGPal71 ; mobile
+ dw .GetPartyMenuMonIcon ; unused
.GetPartyMenuMonIcon: ; 8e862 (23:6862)
@@ -89,7 +88,7 @@ Function8e898: ; 8e898 (23:6898)
call Function8e8d5
ld hl, SPRITEANIMSTRUCT_ANIM_SEQ_ID
add hl, bc
- ld a, $0
+ ld a, SPRITE_ANIM_SEQ_NULL
ld [hl], a
ld hl, SPRITEANIMSTRUCT_XCOORD
add hl, bc
@@ -106,7 +105,7 @@ Mobile_InitPartyMenuBGPal71: ; 8e8b1 (23:68b1)
call SetPartyMonIconAnimSpeed
ld hl, SPRITEANIMSTRUCT_ANIM_SEQ_ID
add hl, bc
- ld a, $0
+ ld a, SPRITE_ANIM_SEQ_NULL
ld [hl], a
ld hl, SPRITEANIMSTRUCT_XCOORD
add hl, bc
@@ -229,7 +228,7 @@ Function8e961: ; 8e961 (23:6961)
call InitSpriteAnimStruct
ld hl, SPRITEANIMSTRUCT_ANIM_SEQ_ID
add hl, bc
- ld [hl], $0
+ ld [hl], SPRITE_ANIM_SEQ_NULL
ret
Function8e97d: ; 8e97d (23:697d)
diff --git a/engine/movement.asm b/engine/movement.asm
index ca3ac55b5..04f3f5208 100644
--- a/engine/movement.asm
+++ b/engine/movement.asm
@@ -55,8 +55,8 @@ MovementPointers: ; 5075
dw Movement_fast_jump_step_up ; 35
dw Movement_fast_jump_step_left ; 36
dw Movement_fast_jump_step_right ; 37
- dw Movement_38 ; 38
- dw Movement_39 ; 39
+ dw Movement_remove_sliding ; 38
+ dw Movement_set_sliding ; 39
dw Movement_remove_fixed_facing ; 3a
dw Movement_fix_facing ; 3b
dw Movement_show_person ; 3c
@@ -373,14 +373,14 @@ Movement_56: ; 5279
ret
; 5293
-Movement_38: ; 5293
+Movement_remove_sliding: ; 5293
ld hl, OBJECT_FLAGS1
add hl, bc
res SLIDING, [hl]
jp ContinueReadingMovement
; 529c
-Movement_39: ; 529c
+Movement_set_sliding: ; 529c
ld hl, OBJECT_FLAGS1
add hl, bc
set SLIDING, [hl]
diff --git a/engine/namingscreen.asm b/engine/namingscreen.asm
index ac56ec250..e65a2d54f 100755
--- a/engine/namingscreen.asm
+++ b/engine/namingscreen.asm
@@ -88,10 +88,10 @@ endr
.Pokemon: ; 1173e (4:573e)
ld a, [CurPartySpecies]
ld [wd265], a
- ld hl, Function8e83f
- ld a, BANK(Function8e83f)
+ ld hl, LoadMenuMonIcon
+ ld a, BANK(LoadMenuMonIcon)
ld e, $1
- rst FarCall ; ; indirect jump to Function8e83f (8e83f (23:683f))
+ rst FarCall ; ; indirect jump to LoadMenuMonIcon (8e83f (23:683f))
ld a, [CurPartySpecies]
ld [wd265], a
call GetPokemonName
diff --git a/engine/party_menu.asm b/engine/party_menu.asm
index b9048da10..9bf02351e 100644
--- a/engine/party_menu.asm
+++ b/engine/party_menu.asm
@@ -658,8 +658,8 @@ InitPartyMenuGFX: ; 503e0
.loop
push bc
push hl
- ld hl, Function8e83f
- ld a, BANK(Function8e83f)
+ ld hl, LoadMenuMonIcon
+ ld a, BANK(LoadMenuMonIcon)
ld e, $0
rst FarCall
ld a, [hObjectStructIndexBuffer]
@@ -752,8 +752,8 @@ PartyMenuSelect: ; 0x50457
ld [wPartyMenuCursor], a
ld a, [hJoyLast]
ld b, a
- bit 1, b
- jr nz, .exitmenu ; B button?
+ bit B_BUTTON_F, b
+ jr nz, .exitmenu ; B button
ld a, [wMenuCursorY]
dec a
ld [CurPartyMon], a
diff --git a/engine/phone.asm b/engine/phone.asm
index 1a3023bf1..ac21c1565 100644
--- a/engine/phone.asm
+++ b/engine/phone.asm
@@ -451,22 +451,20 @@ Script_ReceivePhoneCall: ; 0x90241
; 0x90255
Script_SpecialBillCall:: ; 0x90255
- callasm Function9025c
+ callasm .LoadBillScript
jump Script_ReceivePhoneCall
-; 0x9025c
-Function9025c: ; 9025c
+.LoadBillScript
ld e, PHONE_BILL
jp LoadCallerScript
; 90261
UnknownScript_0x90261: ; 0x90261
- callasm Function9026a
+ callasm .LoadElmScript
pause 30
jump Script_ReceivePhoneCall
-; 0x9026a
-Function9026a: ; 9026a
+.LoadElmScript
ld e, PHONE_ELM
jp LoadCallerScript
; 9026f
@@ -494,7 +492,6 @@ Phone_CallerTextboxWithName: ; 90292 (24:4292)
call Function90363
ret
-
PhoneCall:: ; 9029a
ld a, b
ld [PhoneScriptBank], a
diff --git a/engine/player_movement.asm b/engine/player_movement.asm
index 80c5e6edc..6ab121f61 100755
--- a/engine/player_movement.asm
+++ b/engine/player_movement.asm
@@ -121,12 +121,12 @@ DoPlayerMovement:: ; 80000
ld a, [PlayerStandingTile]
ld c, a
call CheckWhirlpoolTile
- jr c, .asm_800c4
+ jr c, .not_whirlpool
ld a, 3
scf
ret
-.asm_800c4
+.not_whirlpool
and $f0
cp $30 ; moving water
jr z, .water
diff --git a/engine/player_object.asm b/engine/player_object.asm
new file mode 100755
index 000000000..e84dff23e
--- /dev/null
+++ b/engine/player_object.asm
@@ -0,0 +1,856 @@
+BlankScreen: ; 8000
+ call DisableSpriteUpdates
+ xor a
+ ld [hBGMapMode], a
+ call ClearBGPalettes
+ call ClearSprites
+ hlcoord 0, 0
+ ld bc, TileMapEnd - TileMap
+ ld a, " "
+ call ByteFill
+ hlcoord 0, 0, AttrMap
+ ld bc, AttrMapEnd - AttrMap
+ ld a, $7
+ call ByteFill
+ call WaitBGMap2
+ call SetPalettes
+ ret
+
+SpawnPlayer: ; 8029
+ ld a, -1
+ ld [wObjectFollow_Leader], a
+ ld [wObjectFollow_Follower], a
+ ld a, $0
+ ld hl, PlayerObjectTemplate
+ call CopyPlayerObjectTemplate
+ ld b, $0
+ call PlayerSpawn_ConvertCoords
+ ld a, $0
+ call GetMapObject
+ ld hl, MAPOBJECT_COLOR
+ add hl, bc
+ ln e, (1 << 3) | PAL_OW_RED, PERSONTYPE_SCRIPT
+ ld a, [wPlayerSpriteSetupFlags]
+ bit 2, a
+ jr nz, .ok
+ ld a, [PlayerGender]
+ bit 0, a
+ jr z, .ok
+ ln e, (1 << 3) | PAL_OW_BLUE, PERSONTYPE_SCRIPT
+
+.ok
+ ld [hl], e
+ ld a, $0
+ ld [hMapObjectIndexBuffer], a
+ ld bc, MapObjects
+ ld a, $0
+ ld [hObjectStructIndexBuffer], a
+ ld de, ObjectStructs
+ call CopyMapObjectToObjectStruct
+ ld a, PLAYER
+ ld [wCenteredObject], a
+ ret
+
+PlayerObjectTemplate: ; 8071
+; A dummy map object used to initialize the player object.
+; Shorter than the actual amount copied by two bytes.
+; Said bytes seem to be unused.
+ person_event SPRITE_CHRIS, -4, -4, SPRITEMOVEDATA_PLAYER, 15, 15, -1, -1, 0, PERSONTYPE_SCRIPT, 0, 0, -1
+
+CopyDECoordsToMapObject:: ; 807e
+ push de
+ ld a, b
+ call GetMapObject
+ pop de
+ ld hl, MAPOBJECT_X_COORD
+ add hl, bc
+ ld [hl], d
+ ld hl, MAPOBJECT_Y_COORD
+ add hl, bc
+ ld [hl], e
+ ret
+
+PlayerSpawn_ConvertCoords: ; 808f
+ push bc
+ ld a, [XCoord]
+ add 4
+ ld d, a
+ ld a, [YCoord]
+ add 4
+ ld e, a
+ pop bc
+ call CopyDECoordsToMapObject
+ ret
+
+WritePersonXY:: ; 80a1
+ ld a, b
+ call CheckObjectVisibility
+ ret c
+
+ ld hl, OBJECT_NEXT_MAP_X
+ add hl, bc
+ ld d, [hl]
+ ld hl, OBJECT_NEXT_MAP_Y
+ add hl, bc
+ ld e, [hl]
+ ld a, [hMapObjectIndexBuffer]
+ ld b, a
+ call CopyDECoordsToMapObject
+ and a
+ ret
+
+RefreshPlayerCoords: ; 80b8
+ ld a, [XCoord]
+ add 4
+ ld d, a
+ ld hl, PlayerStandingMapX
+ sub [hl]
+ ld [hl], d
+ ld hl, MapObjects + MAPOBJECT_X_COORD
+ ld [hl], d
+ ld hl, PlayerLastMapX
+ ld [hl], d
+ ld d, a
+ ld a, [YCoord]
+ add 4
+ ld e, a
+ ld hl, PlayerStandingMapY
+ sub [hl]
+ ld [hl], e
+ ld hl, MapObjects + MAPOBJECT_Y_COORD
+ ld [hl], e
+ ld hl, PlayerLastMapY
+ ld [hl], e
+ ld e, a
+ ld a, [wObjectFollow_Leader]
+ cp $0
+ ret nz ; wtf
+ ret
+
+CopyObjectStruct:: ; 80e7
+ call CheckObjectMask
+ and a
+ ret nz ; masked
+
+ ld hl, ObjectStructs + OBJECT_STRUCT_LENGTH * 1
+ ld a, 1
+ ld de, OBJECT_STRUCT_LENGTH
+.loop
+ ld [hObjectStructIndexBuffer], a
+ ld a, [hl]
+ and a
+ jr z, .done
+ add hl, de
+ ld a, [hObjectStructIndexBuffer]
+ inc a
+ cp NUM_OBJECT_STRUCTS
+ jr nz, .loop
+ scf
+ ret ; overflow
+
+.done
+ ld d, h
+ ld e, l
+ call CopyMapObjectToObjectStruct
+ ld hl, VramState
+ bit 7, [hl]
+ ret z
+
+ ld hl, OBJECT_FLAGS2
+ add hl, de
+ set 5, [hl]
+ ret
+
+CopyMapObjectToObjectStruct: ; 8116
+ call .CopyMapObjectToTempObject
+ call CopyTempObjectToObjectStruct
+ ret
+
+.CopyMapObjectToTempObject: ; 811d
+ ld a, [hObjectStructIndexBuffer]
+ ld hl, MAPOBJECT_OBJECT_STRUCT_ID
+ add hl, bc
+ ld [hl], a
+
+ ld a, [hMapObjectIndexBuffer]
+ ld [wTempObjectCopyMapObjectIndex], a
+
+ ld hl, MAPOBJECT_SPRITE
+ add hl, bc
+ ld a, [hl]
+ ld [wTempObjectCopySprite], a
+
+ call GetSpriteVTile
+ ld [wTempObjectCopySpriteVTile], a
+
+ ld a, [hl]
+ call GetSpritePalette
+ ld [wTempObjectCopyPalette], a
+
+ ld hl, MAPOBJECT_COLOR
+ add hl, bc
+ ld a, [hl]
+ and $f0
+ jr z, .skip_color_override
+ swap a
+ and $7 ; OAM_PALETTE
+ ld [wTempObjectCopyPalette], a
+
+.skip_color_override
+ ld hl, MAPOBJECT_MOVEMENT
+ add hl, bc
+ ld a, [hl]
+ ld [wTempObjectCopyMovement], a
+
+ ld hl, MAPOBJECT_RANGE
+ add hl, bc
+ ld a, [hl]
+ ld [wTempObjectCopyRange], a
+
+ ld hl, MAPOBJECT_X_COORD
+ add hl, bc
+ ld a, [hl]
+ ld [wTempObjectCopyX], a
+
+ ld hl, MAPOBJECT_Y_COORD
+ add hl, bc
+ ld a, [hl]
+ ld [wTempObjectCopyY], a
+
+ ld hl, MAPOBJECT_RADIUS
+ add hl, bc
+ ld a, [hl]
+ ld [wTempObjectCopyRadius], a
+ ret
+
+InitializeVisibleSprites: ; 8177
+ ld bc, MapObjects + OBJECT_LENGTH
+ ld a, 1
+.loop
+ ld [hMapObjectIndexBuffer], a
+ ld hl, MAPOBJECT_SPRITE
+ add hl, bc
+ ld a, [hl]
+ and a
+ jr z, .next
+
+ ld hl, MAPOBJECT_OBJECT_STRUCT_ID
+ add hl, bc
+ ld a, [hl]
+ cp -1
+ jr nz, .next
+
+ ld a, [XCoord]
+ ld d, a
+ ld a, [YCoord]
+ ld e, a
+
+ ld hl, MAPOBJECT_X_COORD
+ add hl, bc
+ ld a, [hl]
+ add 1
+ sub d
+ jr c, .next
+
+ cp MAPOBJECT_SCREEN_WIDTH
+ jr nc, .next
+
+ ld hl, MAPOBJECT_Y_COORD
+ add hl, bc
+ ld a, [hl]
+ add 1
+ sub e
+ jr c, .next
+
+ cp MAPOBJECT_SCREEN_HEIGHT
+ jr nc, .next
+
+ push bc
+ call CopyObjectStruct
+ pop bc
+ jp c, .ret
+
+.next
+ ld hl, OBJECT_LENGTH
+ add hl, bc
+ ld b, h
+ ld c, l
+ ld a, [hMapObjectIndexBuffer]
+ inc a
+ cp NUM_OBJECTS
+ jr nz, .loop
+ ret
+
+.ret: ; 81c9
+ ret
+
+CheckObjectEnteringVisibleRange:: ; 81ca
+ nop
+ ld a, [wPlayerStepDirection]
+ cp STANDING
+ ret z
+ ld hl, .dw
+ rst JumpTable
+ ret
+
+.dw: ; 81d6
+ dw .Down
+ dw .Up
+ dw .Left
+ dw .Right
+
+.Up: ; 81de
+ ld a, [YCoord]
+ sub 1
+ jr .Vertical
+
+.Down: ; 81e5
+ ld a, [YCoord]
+ add 9
+.Vertical: ; 81ea
+ ld d, a
+ ld a, [XCoord]
+ ld e, a
+ ld bc, MapObjects + OBJECT_LENGTH
+ ld a, 1
+.loop_v
+ ld [hMapObjectIndexBuffer], a
+ ld hl, MAPOBJECT_SPRITE
+ add hl, bc
+ ld a, [hl]
+ and a
+ jr z, .next_v
+ ld hl, MAPOBJECT_Y_COORD
+ add hl, bc
+ ld a, d
+ cp [hl]
+ jr nz, .next_v
+ ld hl, MAPOBJECT_OBJECT_STRUCT_ID
+ add hl, bc
+ ld a, [hl]
+ cp -1
+ jr nz, .next_v
+ ld hl, MAPOBJECT_X_COORD
+ add hl, bc
+ ld a, [hl]
+ add 1
+ sub e
+ jr c, .next_v
+ cp MAPOBJECT_SCREEN_WIDTH
+ jr nc, .next_v
+ push de
+ push bc
+ call CopyObjectStruct
+ pop bc
+ pop de
+
+.next_v
+ ld hl, OBJECT_LENGTH
+ add hl, bc
+ ld b, h
+ ld c, l
+ ld a, [hMapObjectIndexBuffer]
+ inc a
+ cp NUM_OBJECTS
+ jr nz, .loop_v
+ ret
+
+.Left: ; 8232
+ ld a, [XCoord]
+ sub 1
+ jr .Horizontal
+
+.Right: ; 8239
+ ld a, [XCoord]
+ add 10
+.Horizontal: ; 823e
+ ld e, a
+ ld a, [YCoord]
+ ld d, a
+ ld bc, MapObjects + OBJECT_LENGTH
+ ld a, 1
+.loop_h
+ ld [hMapObjectIndexBuffer], a
+ ld hl, MAPOBJECT_SPRITE
+ add hl, bc
+ ld a, [hl]
+ and a
+ jr z, .next_h
+ ld hl, MAPOBJECT_X_COORD
+ add hl, bc
+ ld a, e
+ cp [hl]
+ jr nz, .next_h
+ ld hl, MAPOBJECT_OBJECT_STRUCT_ID
+ add hl, bc
+ ld a, [hl]
+ cp -1
+ jr nz, .next_h
+ ld hl, MAPOBJECT_Y_COORD
+ add hl, bc
+ ld a, [hl]
+ add 1
+ sub d
+ jr c, .next_h
+ cp MAPOBJECT_SCREEN_HEIGHT
+ jr nc, .next_h
+ push de
+ push bc
+ call CopyObjectStruct
+ pop bc
+ pop de
+
+.next_h
+ ld hl, OBJECT_LENGTH
+ add hl, bc
+ ld b, h
+ ld c, l
+ ld a, [hMapObjectIndexBuffer]
+ inc a
+ cp NUM_OBJECTS
+ jr nz, .loop_h
+ ret
+
+CopyTempObjectToObjectStruct: ; 8286
+ ld a, [wTempObjectCopyMapObjectIndex]
+ ld hl, OBJECT_MAP_OBJECT_INDEX
+ add hl, de
+ ld [hl], a
+
+ ld a, [wTempObjectCopyMovement]
+ call CopySpriteMovementData
+
+ ld a, [wTempObjectCopyPalette]
+ ld hl, OBJECT_PALETTE
+ add hl, de
+ or [hl]
+ ld [hl], a
+
+ ld a, [wTempObjectCopyY]
+ call .InitYCoord
+
+ ld a, [wTempObjectCopyX]
+ call .InitXCoord
+
+ ld a, [wTempObjectCopySprite]
+ ld hl, OBJECT_SPRITE
+ add hl, de
+ ld [hl], a
+
+ ld a, [wTempObjectCopySpriteVTile]
+ ld hl, OBJECT_SPRITE_TILE
+ add hl, de
+ ld [hl], a
+
+ ld hl, OBJECT_STEP_TYPE
+ add hl, de
+ ld [hl], STEP_TYPE_00
+
+ ld hl, OBJECT_FACING_STEP
+ add hl, de
+ ld [hl], STANDING
+
+ ld a, [wTempObjectCopyRadius]
+ call .InitRadius
+
+ ld a, [wTempObjectCopyRange]
+ ld hl, OBJECT_RANGE
+ add hl, de
+ ld [hl], a
+
+ and a
+ ret
+
+.InitYCoord: ; 82d5
+ ld hl, OBJECT_INIT_Y
+ add hl, de
+ ld [hl], a
+
+ ld hl, OBJECT_NEXT_MAP_Y
+ add hl, de
+ ld [hl], a
+
+ ld hl, YCoord
+ sub [hl]
+ and $f
+ swap a
+ ld hl, wFollowNotExactPersonY
+ sub [hl]
+ ld hl, OBJECT_SPRITE_Y
+ add hl, de
+ ld [hl], a
+ ret
+
+.InitXCoord: ; 82f1
+ ld hl, OBJECT_INIT_X
+ add hl, de
+ ld [hl], a
+ ld hl, OBJECT_NEXT_MAP_X
+ add hl, de
+ ld [hl], a
+ ld hl, XCoord
+ sub [hl]
+ and $f
+ swap a
+ ld hl, wFollowNotExactPersonX
+ sub [hl]
+ ld hl, OBJECT_SPRITE_X
+ add hl, de
+ ld [hl], a
+ ret
+
+.InitRadius: ; 830d
+ ld h, a
+ inc a
+ and $f
+ ld l, a
+ ld a, h
+ add $10
+ and $f0
+ or l
+ ld hl, OBJECT_RADIUS
+ add hl, de
+ ld [hl], a
+ ret
+
+TrainerWalkToPlayer: ; 831e
+ ld a, [hLastTalked]
+ call InitMovementBuffer
+ ld a, movement_step_sleep_1
+ call AppendToMovementBuffer
+ ld a, [wd03f]
+ dec a
+ jr z, .TerminateStep
+ ld a, [hLastTalked]
+ ld b, a
+ ld c, PLAYER
+ ld d, 1
+ call .GetPathToPlayer
+ call DecrementMovementBufferCount
+
+.TerminateStep
+ ld a, movement_step_end
+ call AppendToMovementBuffer
+ ret
+
+.GetPathToPlayer: ; 8341
+ push de
+ push bc
+; get player object struct, load to de
+ ld a, c
+ call GetMapObject
+ ld hl, MAPOBJECT_OBJECT_STRUCT_ID
+ add hl, bc
+ ld a, [hl]
+ call GetObjectStruct
+ ld d, b
+ ld e, c
+
+; get last talked object struct, load to bc
+ pop bc
+ ld a, b
+ call GetMapObject
+ ld hl, MAPOBJECT_OBJECT_STRUCT_ID
+ add hl, bc
+ ld a, [hl]
+ call GetObjectStruct
+
+; get last talked coords, load to bc
+ ld hl, OBJECT_NEXT_MAP_X
+ add hl, bc
+ ld a, [hl]
+ ld hl, OBJECT_NEXT_MAP_Y
+ add hl, bc
+ ld c, [hl]
+ ld b, a
+
+; get player coords, load to de
+ ld hl, OBJECT_NEXT_MAP_X
+ add hl, de
+ ld a, [hl]
+ ld hl, OBJECT_NEXT_MAP_Y
+ add hl, de
+ ld e, [hl]
+ ld d, a
+
+ pop af
+ call ComputePathToWalkToPlayer
+ ret
+
+Special_SurfStartStep: ; 8379
+ call InitMovementBuffer
+ call .GetMovementData
+ call AppendToMovementBuffer
+ ld a, movement_step_end
+ call AppendToMovementBuffer
+ ret
+
+.GetMovementData: ; 8388
+ ld a, [PlayerDirection]
+ srl a
+ srl a
+ and 3
+ ld e, a
+ ld d, 0
+ ld hl, .movement_data
+ add hl, de
+ ld a, [hl]
+ ret
+
+.movement_data
+ slow_step_down
+ slow_step_up
+ slow_step_left
+ slow_step_right
+
+FollowNotExact:: ; 839e
+ push bc
+ ld a, c
+ call CheckObjectVisibility
+ ld d, b
+ ld e, c
+ pop bc
+ ret c
+
+ ld a, b
+ call CheckObjectVisibility
+ ret c
+
+; Person 2 is now in bc, person 1 is now in de
+ ld hl, OBJECT_NEXT_MAP_X
+ add hl, bc
+ ld a, [hl]
+ ld hl, OBJECT_NEXT_MAP_Y
+ add hl, bc
+ ld c, [hl]
+ ld b, a
+
+ ld hl, OBJECT_NEXT_MAP_X
+ add hl, de
+ ld a, [hl]
+ cp b
+ jr z, .same_x
+ jr c, .to_the_left
+ inc b
+ jr .continue
+
+.to_the_left
+ dec b
+ jr .continue
+
+.same_x
+ ld hl, OBJECT_NEXT_MAP_Y
+ add hl, de
+ ld a, [hl]
+ cp c
+ jr z, .continue
+ jr c, .below
+ inc c
+ jr .continue
+
+.below
+ dec c
+
+.continue
+ ld hl, OBJECT_NEXT_MAP_X
+ add hl, de
+ ld [hl], b
+ ld a, b
+ ld hl, XCoord
+ sub [hl]
+ and $f
+ swap a
+ ld hl, wFollowNotExactPersonX
+ sub [hl]
+ ld hl, OBJECT_SPRITE_X
+ add hl, de
+ ld [hl], a
+ ld hl, OBJECT_NEXT_MAP_Y
+ add hl, de
+ ld [hl], c
+ ld a, c
+ ld hl, YCoord
+ sub [hl]
+ and $f
+ swap a
+ ld hl, wFollowNotExactPersonY
+ sub [hl]
+ ld hl, OBJECT_SPRITE_Y
+ add hl, de
+ ld [hl], a
+ ld a, [hObjectStructIndexBuffer]
+ ld hl, OBJECT_RANGE
+ add hl, de
+ ld [hl], a
+ ld hl, OBJECT_MOVEMENTTYPE
+ add hl, de
+ ld [hl], SPRITEMOVEDATA_FOLLOWNOTEXACT
+ ld hl, OBJECT_STEP_TYPE
+ add hl, de
+ ld [hl], STEP_TYPE_00
+ ret
+
+GetRelativeFacing:: ; 8417
+; Determines which way map object e would have to turn to face map object d. Returns carry if it's impossible for whatever reason.
+ ld a, d
+ call GetMapObject
+ ld hl, MAPOBJECT_OBJECT_STRUCT_ID
+ add hl, bc
+ ld a, [hl]
+ cp NUM_OBJECT_STRUCTS
+ jr nc, .carry
+ ld d, a
+ ld a, e
+ call GetMapObject
+ ld hl, MAPOBJECT_OBJECT_STRUCT_ID
+ add hl, bc
+ ld a, [hl]
+ cp NUM_OBJECT_STRUCTS
+ jr nc, .carry
+ ld e, a
+ call .GetFacing_e_relativeto_d
+ ret
+
+.carry
+ scf
+ ret
+
+.GetFacing_e_relativeto_d: ; 8439
+; Determines which way object e would have to turn to face object d. Returns carry if it's impossible.
+; load the coordinates of object d into bc
+ ld a, d
+ call GetObjectStruct
+ ld hl, OBJECT_NEXT_MAP_X
+ add hl, bc
+ ld a, [hl]
+ ld hl, OBJECT_NEXT_MAP_Y
+ add hl, bc
+ ld c, [hl]
+ ld b, a
+ push bc
+; load the coordinates of object e into de
+ ld a, e
+ call GetObjectStruct
+ ld hl, OBJECT_NEXT_MAP_X
+ add hl, bc
+ ld d, [hl]
+ ld hl, OBJECT_NEXT_MAP_Y
+ add hl, bc
+ ld e, [hl]
+ pop bc
+; |x1 - x2|
+ ld a, b
+ sub d
+ jr z, .same_x_1
+ jr nc, .b_right_of_d_1
+ cpl
+ inc a
+
+.b_right_of_d_1
+; |y1 - y2|
+ ld h, a
+ ld a, c
+ sub e
+ jr z, .same_y_1
+ jr nc, .c_below_e_1
+ cpl
+ inc a
+
+.c_below_e_1
+; |y1 - y2| - |x1 - x2|
+ sub h
+ jr c, .same_y_1
+
+.same_x_1
+; compare the y coordinates
+ ld a, c
+ cp e
+ jr z, .same_x_and_y
+ jr c, .c_directly_below_e
+; c directly above e
+ ld d, DOWN
+ and a
+ ret
+
+.c_directly_below_e
+ ld d, UP
+ and a
+ ret
+
+.same_y_1
+ ld a, b
+ cp d
+ jr z, .same_x_and_y
+ jr c, .b_directly_right_of_d
+; b directly left of d
+ ld d, RIGHT
+ and a
+ ret
+
+.b_directly_right_of_d
+ ld d, LEFT
+ and a
+ ret
+
+.same_x_and_y
+ scf
+ ret
+
+QueueFollowerFirstStep: ; 848a
+ call .QueueFirstStep
+ jr c, .same
+ ld [wFollowMovementQueue], a
+ xor a
+ ld [wFollowerMovementQueueLength], a
+ ret
+
+.same
+ ld a, -1
+ ld [wFollowerMovementQueueLength], a
+ ret
+
+.QueueFirstStep
+ ld a, [wObjectFollow_Leader]
+ call GetObjectStruct
+ ld hl, OBJECT_NEXT_MAP_X
+ add hl, bc
+ ld d, [hl]
+ ld hl, OBJECT_NEXT_MAP_Y
+ add hl, bc
+ ld e, [hl]
+ ld a, [wObjectFollow_Follower]
+ call GetObjectStruct
+ ld hl, OBJECT_NEXT_MAP_X
+ add hl, bc
+ ld a, d
+ cp [hl]
+ jr z, .check_y
+ jr c, .left
+ and a
+ ld a, movement_step_right
+ ret
+
+.left
+ and a
+ ld a, movement_step_left
+ ret
+
+.check_y
+ ld hl, OBJECT_NEXT_MAP_Y
+ add hl, bc
+ ld a, e
+ cp [hl]
+ jr z, .same_xy
+ jr c, .up
+ and a
+ ld a, movement_step_down
+ ret
+
+.up
+ and a
+ ld a, movement_step_up
+ ret
+
+.same_xy
+ scf
+ ret
diff --git a/engine/pokecenter_pc.asm b/engine/pokecenter_pc.asm
index a75798709..4c4effb6b 100755
--- a/engine/pokecenter_pc.asm
+++ b/engine/pokecenter_pc.asm
@@ -2,9 +2,9 @@ PokemonCenterPC: ; 1559a
call PC_CheckPartyForPokemon
ret c
call PC_PlayBootSound
- ld hl, UnknownText_0x15a27
+ ld hl, PokeCenterPCText_BootedUpPC
call PC_DisplayText
- ld hl, UnknownText_0x15a2c
+ ld hl, PokeCenterPCText_AccessWhosePC
call PC_DisplayTextWaitMenu
ld hl, .TopMenu
call LoadMenuDataHeader
@@ -25,40 +25,35 @@ PokemonCenterPC: ; 1559a
call ExitMenu
call CloseWindow
ret
-; 155d6
-.TopMenu: ; 0x155d6
+.TopMenu
db $48 ; flags
db 00, 00 ; start coords
db 12, 15 ; end coords
dw .MenuData2
db 1 ; default option
-; 0x155de
-.MenuData2: ; 0x155de
+.MenuData2
db $a0 ; flags
db 0 ; items
dw .WhichPC
dw PlaceNthMenuStrings
dw .JumpTable
-; 0x155e6
-.JumpTable: ; 155e6
+.JumpTable
dw PlayersPC, .String_PlayersPC
dw BillsPC, .String_BillsPC
dw OaksPC, .String_OaksPC
dw HallOfFamePC, .String_HallOfFame
dw TurnOffPC, .String_TurnOff
-; 155fa
-.String_PlayersPC: db "<PLAYER>'s PC@"
-.String_BillsPC: db "BILL's PC@"
-.String_OaksPC: db "PROF.OAK's PC@"
-.String_HallOfFame: db "HALL OF FAME@"
-.String_TurnOff: db "TURN OFF@"
-; 1562c
+.String_PlayersPC: db "<PLAYER>'s PC@"
+.String_BillsPC: db "BILL's PC@"
+.String_OaksPC: db "PROF.OAK's PC@"
+.String_HallOfFame: db "HALL OF FAME@"
+.String_TurnOff: db "TURN OFF@"
-.WhichPC: ; 1562c
+.WhichPC
; before pokedex
db 3 ; items
db 1, 0, 4 ; bill's, player's, turn off
@@ -73,9 +68,8 @@ PokemonCenterPC: ; 1559a
db 5 ; items
db 1, 0, 2, 3, 4 ; bill's, player's, oak's, hall of fame, turn off
db -1
-; 1563e
-.ChooseWhichPCListToUse: ; 1563e
+.ChooseWhichPCListToUse
call CheckReceivedDex
jr nz, .got_dex
ld a, $0
@@ -96,13 +90,12 @@ PC_CheckPartyForPokemon: ; 15650
ret nz
ld de, SFX_CHOOSE_PC_OPTION
call PlaySFX
- ld hl, UnknownText_0x15663
+ ld hl, .MustHavePokemonToUse
call PC_DisplayText
scf
ret
-; 15663
-UnknownText_0x15663: ; 0x15663
+.MustHavePokemonToUse
; Bzzzzt! You must have a #MON to use this!
text_jump UnknownText_0x1c1328
db "@"
@@ -110,7 +103,7 @@ UnknownText_0x15663: ; 0x15663
BillsPC: ; 15668
call PC_PlayChoosePCSound
- ld hl, UnknownText_0x15a31
+ ld hl, PokeCenterPCText_AccessedBillsPC
call PC_DisplayText
callba _BillsPC
and a
@@ -119,7 +112,7 @@ BillsPC: ; 15668
PlayersPC: ; 15679
call PC_PlayChoosePCSound
- ld hl, UnknownText_0x15a36
+ ld hl, PokeCenterPCText_AccessedOwnPC
call PC_DisplayText
ld b, $0
call _PlayersPC
@@ -129,7 +122,7 @@ PlayersPC: ; 15679
OaksPC: ; 15689
call PC_PlayChoosePCSound
- ld hl, UnknownText_0x15a3b
+ ld hl, PokeCenterPCText_AccessedOaksPC
call PC_DisplayText
callba ProfOaksPC
and a
@@ -146,7 +139,7 @@ HallOfFamePC: ; 1569a
; 156ab
TurnOffPC: ; 156ab
- ld hl, UnknownText_0x15a40
+ ld hl, PokeCenterPCText_LinkClosed
call PrintText
scf
ret
@@ -166,7 +159,7 @@ PC_PlayChoosePCSound: ; 156c2
ld de, SFX_CHOOSE_PC_OPTION
jr PC_WaitPlaySFX
-Function156c7: ; 156c7
+PC_PlaySwapItemsSound: ; 156c7
ld de, SFX_SWITCH_POKEMON
call PC_WaitPlaySFX
ld de, SFX_SWITCH_POKEMON
@@ -218,8 +211,8 @@ _PlayersPC: ; 15704
Function15715: ; 15715
xor a
- ld [wd0d7], a
- ld [wd0dd], a
+ ld [wPCItemsCursor], a
+ ld [wPCItemsScrollPosition], a
ld hl, KrissPCMenuData
call LoadMenuDataHeader
.asm_15722
@@ -316,19 +309,18 @@ UnknownText_0x157cc: ; 0x157cc
KrisWithdrawItemMenu: ; 0x157d1
call LoadStandardMenuDataHeader
callba ClearPCItemScreen
-.asm_157da
- call Function15985
- jr c, .asm_157e4
- call Function157e9
- jr .asm_157da
+.loop
+ call PCItemsJoypad
+ jr c, .quit
+ call .Submenu
+ jr .loop
-.asm_157e4
+.quit
call CloseSubmenu
xor a
ret
-; 0x157e9
-Function157e9: ; 0x157e9
+.Submenu
; check if the item has a quantity
callba _CheckTossableItem
ld a, [wItemAttributeParamBuffer]
@@ -351,7 +343,7 @@ Function157e9: ; 0x157e9
.withdraw
ld a, [wItemQuantityChangeBuffer]
ld [Buffer1], a ; quantity
- ld a, [wd107]
+ ld a, [CurItemQuantity]
ld [Buffer2], a
ld hl, NumItems
call ReceiveItem
@@ -359,7 +351,7 @@ Function157e9: ; 0x157e9
ld a, [Buffer1]
ld [wItemQuantityChangeBuffer], a
ld a, [Buffer2]
- ld [wd107], a
+ ld [CurItemQuantity], a
ld hl, PCItems
call TossItem
predef PartyMonItemName
@@ -377,7 +369,6 @@ Function157e9: ; 0x157e9
.done
ret
-; 0x15850
.HowManyText ; 0x15850
text_jump _KrissPCHowManyWithdrawText
@@ -391,24 +382,22 @@ Function157e9: ; 0x157e9
text_jump _KrissPCNoRoomWithdrawText
db "@"
-
KrisTossItemMenu: ; 0x1585f
call LoadStandardMenuDataHeader
callba ClearPCItemScreen
-.asm_15868
- call Function15985
- jr c, .asm_15878
+.loop
+ call PCItemsJoypad
+ jr c, .quit
ld de, PCItems
- callba Function129f4
- jr .asm_15868
+ callba TossItemFromPC
+ jr .loop
-.asm_15878
+.quit
call CloseSubmenu
xor a
ret
; 0x1587d
-
KrisDecorationMenu: ; 0x1587d
callba _KrisDecorationMenu
ld a, c
@@ -418,54 +407,48 @@ KrisDecorationMenu: ; 0x1587d
ret
; 0x15888
-
KrisLogOffMenu: ; 0x15888
xor a
scf
ret
; 0x1588b
-
KrisDepositItemMenu: ; 0x1588b
- call Function158b8
- jr c, .asm_158b6
+ call .CheckItemsInBag
+ jr c, .nope
call DisableSpriteUpdates
call LoadStandardMenuDataHeader
callba DepositSellInitPackBuffers
-.asm_1589c
+.loop
callba DepositSellPack
ld a, [wcf66]
and a
- jr z, .asm_158b3
- call Function158cc
+ jr z, .close
+ call .TryDepositItem
callba CheckRegisteredItem
- jr .asm_1589c
+ jr .loop
-.asm_158b3
+.close
call CloseSubmenu
-.asm_158b6
+.nope
xor a
ret
-; 0x158b8
-Function158b8: ; 0x158b8
+.CheckItemsInBag
callba HasNoItems
ret nc
- ld hl, UnknownText_0x158c7
+ ld hl, .NoItemsInBag
call MenuTextBoxBackup
scf
ret
-; 0x158c7
-UnknownText_0x158c7: ; 0x158c7
+.NoItemsInBag
; No items here!
text_jump UnknownText_0x1c13df
db "@"
-; 0x158cc
-
-Function158cc: ; 0x158cc
+.TryDepositItem
ld a, [wSpriteUpdatesEnabled]
push af
ld a, $0
@@ -477,9 +460,8 @@ Function158cc: ; 0x158cc
pop af
ld [wSpriteUpdatesEnabled], a
ret
-; 0x158e7
-.dw: ; 0x158e7
+.dw
dw .tossable
dw .no_toss
dw .no_toss
@@ -488,32 +470,31 @@ Function158cc: ; 0x158cc
dw .tossable
dw .tossable
-.no_toss:
+.no_toss
ret
-.tossable:
+.tossable
ld a, [Buffer1]
push af
ld a, [Buffer2]
push af
- call Function1590a
+ call .DepositItem_
pop af
ld [Buffer2], a
pop af
ld [Buffer1], a
ret
-; 0x1590a
-Function1590a: ; 0x1590a
+.DepositItem_
callba _CheckTossableItem
ld a, [wItemAttributeParamBuffer]
and a
- jr z, .asm_1591d
+ jr z, .AskQuantity
ld a, $1
ld [wItemQuantityChangeBuffer], a
- jr .asm_15933
+ jr .DepositItem
-.asm_1591d
+.AskQuantity
ld hl, .HowManyText
call MenuTextBox
callba SelectQuantityToToss
@@ -521,20 +502,20 @@ Function1590a: ; 0x1590a
call ExitMenu
call ExitMenu
pop af
- jr c, .asm_1596c
+ jr c, .DeclinedToDeposit
-.asm_15933
+.DepositItem
ld a, [wItemQuantityChangeBuffer]
ld [Buffer1], a
- ld a, [wd107]
+ ld a, [CurItemQuantity]
ld [Buffer2], a
ld hl, PCItems
call ReceiveItem
- jr nc, .asm_15965
+ jr nc, .NoRoomInPC
ld a, [Buffer1]
ld [wItemQuantityChangeBuffer], a
ld a, [Buffer2]
- ld [wd107], a
+ ld [CurItemQuantity], a
ld hl, NumItems
call TossItem
predef PartyMonItemName
@@ -542,16 +523,14 @@ Function1590a: ; 0x1590a
call PrintText
ret
-.asm_15965
+.NoRoomInPC
ld hl, .NoRoomText
call PrintText
ret
-.asm_1596c
+.DeclinedToDeposit
and a
ret
-; 0x1596e
-
.HowManyText ; 0x1596e
text_jump _KrissPCHowManyDepositText
@@ -565,87 +544,82 @@ Function1590a: ; 0x1590a
text_jump _KrissPCNoRoomDepositText
db "@"
-
KrisMailBoxMenu: ; 0x1597d
callba _KrisMailBoxMenu
xor a
ret
; 0x15985
-
-Function15985: ; 0x15985
+PCItemsJoypad: ; 0x15985
xor a
- ld [wd0e3], a
-.asm_15989
+ ld [wSwitchItem], a
+.loop
ld a, [wSpriteUpdatesEnabled]
push af
ld a, $0
ld [wSpriteUpdatesEnabled], a
- ld hl, MenuData15a08
+ ld hl, .PCItemsMenuData
call CopyMenuDataHeader
hlcoord 0, 0
- ld b, $a
- ld c, $12
+ ld b, 10
+ ld c, 18
call TextBox
- ld a, [wd0d7]
+ ld a, [wPCItemsCursor]
ld [wMenuCursorBuffer], a
- ld a, [wd0dd]
+ ld a, [wPCItemsScrollPosition]
ld [wMenuScrollPosition], a
call ScrollingMenu
ld a, [wMenuScrollPosition]
- ld [wd0dd], a
+ ld [wPCItemsScrollPosition], a
ld a, [wMenuCursorY]
- ld [wd0d7], a
+ ld [wPCItemsCursor], a
pop af
ld [wSpriteUpdatesEnabled], a
- ld a, [wd0e3]
+ ld a, [wSwitchItem]
and a
- jr nz, .asm_159d8
+ jr nz, .moving_stuff_around
ld a, [wMenuJoypad]
- cp $2
- jr z, .asm_15a06
- cp $1
- jr z, .asm_159fb
- cp $4
- jr z, .asm_159f2
- jr .asm_159f8
-
-.asm_159d8
+ cp B_BUTTON
+ jr z, .b_1
+ cp A_BUTTON
+ jr z, .a_1
+ cp SELECT
+ jr z, .select_1
+ jr .next
+
+.moving_stuff_around
ld a, [wMenuJoypad]
- cp $2
- jr z, .asm_159e9
- cp $1
- jr z, .asm_159ef
- cp $4
- jr z, .asm_159ef
- jr .asm_159f8
-
-.asm_159e9
+ cp B_BUTTON
+ jr z, .b_2
+ cp A_BUTTON
+ jr z, .a_select_2
+ cp SELECT
+ jr z, .a_select_2
+ jr .next
+
+.b_2
xor a
- ld [wd0e3], a
- jr .asm_159f8
-
-.asm_159ef
- call Function156c7
+ ld [wSwitchItem], a
+ jr .next
-.asm_159f2
+.a_select_2
+ call PC_PlaySwapItemsSound
+.select_1
callba SwitchItemsInBag
+.next
+ jp .loop
-.asm_159f8
- jp .asm_15989
-
-.asm_159fb
- callba Function24706
+.a_1
+ callba ScrollingMenu_ClearLeftColumn
call PlaceHollowCursor
and a
ret
-.asm_15a06
+.b_1
scf
ret
-; 0x15a08
-MenuData15a08: ; 0x15a08
+.PCItemsMenuData
db %01000000
db 1, 4 ; start coords
db 10, 18 ; end coords
@@ -667,38 +641,37 @@ PC_DisplayText: ; 15a20
ret
; 15a27
-
-UnknownText_0x15a27: ; 0x15a27
+PokeCenterPCText_BootedUpPC: ; 0x15a27
; turned on the PC.
text_jump UnknownText_0x1c144d
db "@"
; 0x15a2c
-UnknownText_0x15a2c: ; 0x15a2c
+PokeCenterPCText_AccessWhosePC: ; 0x15a2c
; Access whose PC?
text_jump UnknownText_0x1c1462
db "@"
; 0x15a31
-UnknownText_0x15a31: ; 0x15a31
+PokeCenterPCText_AccessedBillsPC: ; 0x15a31
; BILL's PC accessed. #MON Storage System opened.
text_jump UnknownText_0x1c1474
db "@"
; 0x15a36
-UnknownText_0x15a36: ; 0x15a36
+PokeCenterPCText_AccessedOwnPC: ; 0x15a36
; Accessed own PC. Item Storage System opened.
text_jump UnknownText_0x1c14a4
db "@"
; 0x15a3b
-UnknownText_0x15a3b: ; 0x15a3b
+PokeCenterPCText_AccessedOaksPC: ; 0x15a3b
; PROF.OAK's PC accessed. #DEX Rating System opened.
text_jump UnknownText_0x1c14d2
db "@"
; 0x15a40
-UnknownText_0x15a40: ; 0x15a40
+PokeCenterPCText_LinkClosed: ; 0x15a40
; … Link closed…
text_jump UnknownText_0x1c1505
db "@"
diff --git a/engine/pokegear.asm b/engine/pokegear.asm
index 44127fafc..c6829adbe 100755
--- a/engine/pokegear.asm
+++ b/engine/pokegear.asm
@@ -2841,7 +2841,7 @@ TownMapPals: ; 91f13
; The palette data is condensed to nybbles,
; least-significant first.
- ld hl, TownMapPalMap
+ ld hl, .PalMap
srl a
jr c, .odd
; Even-numbered tile ids take the bottom nybble...
@@ -2878,13 +2878,20 @@ TownMapPals: ; 91f13
jr nz, .loop
ret
-TownMapPalMap:
- dn 1, 1, 2, 1, 2, 2, 0, 0, 1, 1, 1, 3, 5, 4, 5, 4
- dn 1, 1, 2, 1, 2, 2, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0
- dn 1, 1, 2, 1, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
- dn 0, 0, 0, 0, 4, 4, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0
- dn 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 3
- dn 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0
+.PalMap
+townmappals: MACRO
+rept _NARG / 2
+ dn \2, \1
+ shift
+ shift
+endr
+endm
+ townmappals 1, 1, 1, 2, 2, 2, 0, 0, 1, 1, 3, 1, 4, 5, 4, 5
+ townmappals 1, 1, 1, 2, 2, 2, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0
+ townmappals 1, 1, 1, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ townmappals 0, 0, 0, 0, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ townmappals 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0
+ townmappals 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0
; 91f7b
TownMapMon: ; 91f7b
diff --git a/engine/printnum.asm b/engine/printnum.asm
new file mode 100755
index 000000000..4ef7721c8
--- /dev/null
+++ b/engine/printnum.asm
@@ -0,0 +1,300 @@
+_PrintNum:: ; c4c7
+; Print c digits of the b-byte value from de to hl.
+; Allows 2 to 7 digits. For 1-digit numbers, add
+; the value to char "0" instead of calling PrintNum.
+; Some extra flags can be given in bits 5-7 of b.
+; Bit 5: money if set (unless left-aligned without leading zeros)
+; Bit 6: right-aligned if set
+; Bit 7: print leading zeros if set
+
+ push bc
+
+ bit 5, b
+ jr z, .main
+ bit 7, b
+ jr nz, .moneyflag
+ bit 6, b
+ jr z, .main
+
+.moneyflag ; 101xxxxx or 011xxxxx
+ ld a, "¥"
+ ld [hli], a
+ res 5, b ; 100xxxxx or 010xxxxx
+
+.main
+ xor a
+ ld [hPrintNum1], a
+ ld [hPrintNum2], a
+ ld [hPrintNum3], a
+ ld a, b
+ and $f
+ cp 1
+ jr z, .byte
+ cp 2
+ jr z, .word
+; maximum 3 bytes
+.long
+ ld a, [de]
+ ld [hPrintNum2], a
+ inc de
+ ld a, [de]
+ ld [hPrintNum3], a
+ inc de
+ ld a, [de]
+ ld [hPrintNum4], a
+ jr .start
+
+.word
+ ld a, [de]
+ ld [hPrintNum3], a
+ inc de
+ ld a, [de]
+ ld [hPrintNum4], a
+ jr .start
+
+.byte
+ ld a, [de]
+ ld [hPrintNum4], a
+
+.start
+ push de
+
+ ld d, b
+ ld a, c
+ swap a
+ and $f
+ ld e, a
+ ld a, c
+ and $f
+ ld b, a
+ ld c, 0
+ cp 2
+ jr z, .two
+ cp 3
+ jr z, .three
+ cp 4
+ jr z, .four
+ cp 5
+ jr z, .five
+ cp 6
+ jr z, .six
+
+.seven
+ ld a, 1000000 / $10000 % $100
+ ld [hPrintNum5], a
+ ld a, 1000000 / $100 % $100
+ ld [hPrintNum6], a
+ ld a, 1000000 % $100
+ ld [hPrintNum7], a
+ call .PrintDigit
+ call .AdvancePointer
+
+.six
+ ld a, 100000 / $10000 % $100
+ ld [hPrintNum5], a
+ ld a, 100000 / $100 % $100
+ ld [hPrintNum6], a
+ ld a, 100000 % $100
+ ld [hPrintNum7], a
+ call .PrintDigit
+ call .AdvancePointer
+
+.five
+ xor a
+ ld [hPrintNum5], a
+ ld a, 10000 / $100
+ ld [hPrintNum6], a
+ ld a, 10000 % $100
+ ld [hPrintNum7], a
+ call .PrintDigit
+ call .AdvancePointer
+
+.four
+ xor a
+ ld [hPrintNum5], a
+ ld a, 1000 / $100
+ ld [hPrintNum6], a
+ ld a, 1000 % $100
+ ld [hPrintNum7], a
+ call .PrintDigit
+ call .AdvancePointer
+
+.three
+ xor a
+ ld [hPrintNum5], a
+ xor a
+ ld [hPrintNum6], a
+ ld a, 100
+ ld [hPrintNum7], a
+ call .PrintDigit
+ call .AdvancePointer
+
+.two
+ dec e
+ jr nz, .two_skip
+ ld a, "0"
+ ld [hPrintNum1], a
+.two_skip
+
+ ld c, 0
+ ld a, [hPrintNum4]
+.mod_10
+ cp 10
+ jr c, .modded_10
+ sub 10
+ inc c
+ jr .mod_10
+.modded_10
+
+ ld b, a
+ ld a, [hPrintNum1]
+ or c
+ jr nz, .money
+ call .PrintLeadingZero
+ jr .money_leading_zero
+
+.money
+ call .PrintYen
+ push af
+ ld a, "0"
+ add c
+ ld [hl], a
+ pop af
+ ld [hPrintNum1], a
+ inc e
+ dec e
+ jr nz, .money_leading_zero
+ inc hl
+ ld [hl], $f2 ; XXX
+
+.money_leading_zero
+ call .AdvancePointer
+ call .PrintYen
+ ld a, "0"
+ add b
+ ld [hli], a
+
+ pop de
+ pop bc
+ ret
+
+.PrintYen: ; c5ba
+ push af
+ ld a, [hPrintNum1]
+ and a
+ jr nz, .stop
+ bit 5, d
+ jr z, .stop
+ ld a, "¥"
+ ld [hli], a
+ res 5, d
+
+.stop
+ pop af
+ ret
+
+.PrintDigit: ; c5cb (3:45cb)
+ dec e
+ jr nz, .ok
+ ld a, "0"
+ ld [hPrintNum1], a
+.ok
+ ld c, 0
+.loop
+ ld a, [hPrintNum5]
+ ld b, a
+ ld a, [hPrintNum2]
+ ld [hPrintNum8], a
+ cp b
+ jr c, .skip1
+ sub b
+ ld [hPrintNum2], a
+ ld a, [hPrintNum6]
+ ld b, a
+ ld a, [hPrintNum3]
+ ld [hPrintNum9], a
+ cp b
+ jr nc, .skip2
+ ld a, [hPrintNum2]
+ or 0
+ jr z, .skip3
+ dec a
+ ld [hPrintNum2], a
+ ld a, [hPrintNum3]
+.skip2
+ sub b
+ ld [hPrintNum3], a
+ ld a, [hPrintNum7]
+ ld b, a
+ ld a, [hPrintNum4]
+ ld [hPrintNum10], a
+ cp b
+ jr nc, .skip4
+ ld a, [hPrintNum3]
+ and a
+ jr nz, .skip5
+ ld a, [hPrintNum2]
+ and a
+ jr z, .skip6
+ dec a
+ ld [hPrintNum2], a
+ xor a
+.skip5
+ dec a
+ ld [hPrintNum3], a
+ ld a, [hPrintNum4]
+.skip4
+ sub b
+ ld [hPrintNum4], a
+ inc c
+ jr .loop
+.skip6
+ ld a, [hPrintNum9]
+ ld [hPrintNum3], a
+.skip3
+ ld a, [hPrintNum8]
+ ld [hPrintNum2], a
+.skip1
+ ld a, [hPrintNum1]
+ or c
+ jr z, .PrintLeadingZero
+ ld a, [hPrintNum1]
+ and a
+ jr nz, .done
+ bit 5, d
+ jr z, .done
+ ld a, "¥"
+ ld [hli], a
+ res 5, d
+.done
+ ld a, "0"
+ add c
+ ld [hl], a
+ ld [hPrintNum1], a
+ inc e
+ dec e
+ ret nz
+ inc hl
+ ld [hl], "·"
+ ret
+
+.PrintLeadingZero: ; c644
+; prints a leading zero unless they are turned off in the flags
+ bit 7, d ; print leading zeroes?
+ ret z
+ ld [hl], "0"
+ ret
+
+.AdvancePointer: ; c64a
+; increments the pointer unless leading zeroes are not being printed,
+; the number is left-aligned, and no nonzero digits have been printed yet
+ bit 7, d ; print leading zeroes?
+ jr nz, .inc
+ bit 6, d ; left alignment or right alignment?
+ jr z, .inc
+ ld a, [hPrintNum1]
+ and a
+ ret z
+.inc
+ inc hl
+ ret
diff --git a/engine/scrolling_menu.asm b/engine/scrolling_menu.asm
index b09453239..001beb71b 100755
--- a/engine/scrolling_menu.asm
+++ b/engine/scrolling_menu.asm
@@ -210,17 +210,17 @@ ScrollingMenu_GetCursorPosition: ; 246fc
ret
; 24706
-Function24706: ; 24706 (9:4706)
+ScrollingMenu_ClearLeftColumn: ; 24706 (9:4706)
call MenuBoxCoord2Tile
ld de, SCREEN_WIDTH
add hl, de
ld de, 2 * SCREEN_WIDTH
ld a, [wMenuData2_ScrollingMenuHeight]
-.asm_24713
+.loop
ld [hl], " "
add hl, de
dec a
- jr nz, .asm_24713
+ jr nz, .loop
ret
InitScrollingMenuCursor: ; 2471a
diff --git a/engine/sine.asm b/engine/sine.asm
new file mode 100755
index 000000000..b5da8059c
--- /dev/null
+++ b/engine/sine.asm
@@ -0,0 +1,50 @@
+_Sine:: ; 84d9
+; A simple sine function.
+; Return d * sin(e) in hl.
+
+; e is a signed 6-bit value.
+ ld a, e
+ and %111111
+ cp %100000
+ jr nc, .negative
+
+ call .ApplySineWave
+ ld a, h
+ ret
+
+.negative
+ and %011111
+ call .ApplySineWave
+ ld a, h
+ xor -1
+ inc a
+ ret
+
+.ApplySineWave: ; 84ef
+ ld e, a
+ ld a, d
+ ld d, 0
+ ld hl, .sinewave
+ add hl, de
+ add hl, de
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ ld hl, 0
+
+; Factor amplitude
+.multiply
+ srl a
+ jr nc, .even
+ add hl, de
+.even
+ sla e
+ rl d
+ and a
+ jr nz, .multiply
+ ret
+
+.sinewave: ; 850b
+; A $20-word table representing a sine wave.
+; 90 degrees is index $10 at a base amplitude of $100.
+ sine_wave $100
diff --git a/engine/startmenu.asm b/engine/startmenu.asm
index 25a3eee39..acad9bb88 100755
--- a/engine/startmenu.asm
+++ b/engine/startmenu.asm
@@ -91,7 +91,7 @@ StartMenu:: ; 125cd
ld [MenuSelection], a
.loop
call .PrintMenuAccount
- call Function1f1a
+ call GetScrollingMenuJoypad
ld a, [wMenuJoypad]
cp B_BUTTON
jr z, .b
@@ -591,70 +591,66 @@ HasNoItems: ; 129d5
and a
ret
-Function129f4: ; 129f4
+TossItemFromPC: ; 129f4
push de
call PartyMonItemName
callba _CheckTossableItem
ld a, [wItemAttributeParamBuffer]
and a
- jr nz, .asm_12a3f
- ld hl, UnknownText_0x12a45
+ jr nz, .key_item
+ ld hl, .TossHowMany
call MenuTextBox
callba SelectQuantityToToss
push af
call CloseWindow
call ExitMenu
pop af
- jr c, .asm_12a42
- ld hl, UnknownText_0x12a4a
+ jr c, .quit
+ ld hl, .ConfirmToss
call MenuTextBox
call YesNoBox
push af
call ExitMenu
pop af
- jr c, .asm_12a42
+ jr c, .quit
pop hl
ld a, [wd107]
call TossItem
call PartyMonItemName
- ld hl, UnknownText_0x12a4f
+ ld hl, .TossedThisMany
call MenuTextBox
call ExitMenu
and a
ret
-.asm_12a3f
- call Function12a54
-.asm_12a42
+
+.key_item
+ call .CantToss
+.quit
pop hl
scf
ret
-; 12a45 (4:6a45)
-UnknownText_0x12a45: ; 0x12a45
+.TossHowMany
; Toss out how many @ (S)?
text_jump UnknownText_0x1c1a90
db "@"
-; 0x12a4a
-UnknownText_0x12a4a: ; 0x12a4a
+.ConfirmToss
; Throw away @ @ (S)?
text_jump UnknownText_0x1c1aad
db "@"
-; 0x12a4f
-UnknownText_0x12a4f: ; 0x12a4f
+.TossedThisMany
; Discarded @ (S).
text_jump UnknownText_0x1c1aca
db "@"
-; 0x12a54
-Function12a54: ; 12a54 (4:6a54)
- ld hl, UnknownText_0x12a5b
+.CantToss
+ ld hl, .TooImportantToToss
call MenuTextBoxBackup
ret
-; 12a5b (4:6a5b)
-UnknownText_0x12a5b: ; 0x12a5b
+.TooImportantToToss
; That's too impor- tant to toss out!
text_jump UnknownText_0x1c1adf
db "@"
@@ -830,7 +826,7 @@ GiveTakePartyMonItem: ; 12b60
; 12ba9
-.GiveItem: ; 12ba9
+.GiveItem
callba DepositSellInitPackBuffers
@@ -1168,7 +1164,7 @@ MonMailAction: ; 12d45
; 12dc9
-.MenuDataHeader: ; 0x12dc9
+.MenuDataHeader
db $40 ; flags
db 10, 12 ; start coords
db 17, 19 ; end coords
@@ -1176,7 +1172,7 @@ MonMailAction: ; 12d45
db 1 ; default option
; 0x12dd1
-.MenuData2: ; 0x12dd1
+.MenuData2
db $80 ; flags
db 3 ; items
db "READ@"
@@ -1185,37 +1181,37 @@ MonMailAction: ; 12d45
; 0x12de2
-.mailwilllosemessagetext: ; 0x12de2
+.mailwilllosemessagetext
; The MAIL will lose its message. OK?
text_jump UnknownText_0x1c1c22
db "@"
; 0x12de7
-.tookmailfrommontext: ; 0x12de7
+.tookmailfrommontext
; MAIL detached from <POKEMON>.
text_jump UnknownText_0x1c1c47
db "@"
; 0x12dec
-.bagfulltext: ; 0x12dec
+.bagfulltext
; There's no space for removing MAIL.
text_jump UnknownText_0x1c1c62
db "@"
; 0x12df1
-.sendmailtopctext: ; 0x12df1
+.sendmailtopctext
; Send the removed MAIL to your PC?
text_jump UnknownText_0x1c1c86
db "@"
; 0x12df6
-.mailboxfulltext: ; 0x12df6
+.mailboxfulltext
; Your PC's MAILBOX is full.
text_jump UnknownText_0x1c1ca9
db "@"
; 0x12dfb
-.sentmailtopctext: ; 0x12dfb
+.sentmailtopctext
; The MAIL was sent to your PC.
text_jump UnknownText_0x1c1cc4
db "@"
@@ -1392,13 +1388,13 @@ MonMenu_Softboiled_MilkDrink: ; 12ee6
ret
; 12f00
-.Text_NotEnoughHP: ; 0x12f00
+.Text_NotEnoughHP
; Not enough HP!
text_jump UnknownText_0x1c1ce3
db "@"
; 0x12f05
-.CheckMonHasEnoughHP: ; 12f05
+.CheckMonHasEnoughHP
; Need to have at least (MaxHP / 5) HP left.
ld a, MON_MAXHP
call GetPartyParamLocation
@@ -1471,7 +1467,7 @@ ChooseMoveToDelete: ; 12f5b
ret
; 12f73
-.asm_12f73: ; 12f73
+.asm_12f73
call SetUpMoveScreenBG
ld de, DeleteMoveScreenAttrs
call SetMenuAttributes
@@ -1480,27 +1476,27 @@ ChooseMoveToDelete: ; 12f5b
set 6, [hl]
jr .asm_12f93
-.asm_12f86: ; 12f86
+.asm_12f86
call ScrollingMenuJoypad
bit 1, a
jp nz, .asm_12f9f
bit 0, a
jp nz, .asm_12f9c
-.asm_12f93: ; 12f93
+.asm_12f93
call PrepareToPlaceMoveData
call PlaceMoveData
jp .asm_12f86
; 12f9c
-.asm_12f9c: ; 12f9c
+.asm_12f9c
and a
jr .asm_12fa0
-.asm_12f9f: ; 12f9f
+.asm_12f9f
scf
-.asm_12fa0: ; 12fa0
+.asm_12fa0
push af
xor a
ld [wSwitchMon], a
@@ -1583,7 +1579,7 @@ MoveScreenLoop: ; 12fd5
ld de, String_1316b
call PlaceString
jp .joy_loop
-.b_button: ; 13038
+.b_button
call PlayClickSFX
call WaitSFX
ld a, [wMoveSwapBuffer]
@@ -1600,7 +1596,7 @@ MoveScreenLoop: ; 12fd5
jp .loop
; 1305b
-.d_right: ; 1305b
+.d_right
ld a, [wMoveSwapBuffer]
and a
jp nz, .joy_loop
@@ -1615,7 +1611,7 @@ MoveScreenLoop: ; 12fd5
jp z, .joy_loop
jp MoveScreenLoop
-.d_left: ; 13075
+.d_left
ld a, [wMoveSwapBuffer]
and a
jp nz, .joy_loop
@@ -1665,7 +1661,7 @@ MoveScreenLoop: ; 12fd5
jr .cycle_left_loop
; 130c6
-.a_button: ; 130c6
+.a_button
call PlayClickSFX
call WaitSFX
ld a, [wMoveSwapBuffer]
@@ -1716,7 +1712,7 @@ MoveScreenLoop: ; 12fd5
jp .loop
; 1313a
-.copy_move: ; 1313a
+.copy_move
push hl
ld a, [wMenuCursorY]
dec a
@@ -1739,7 +1735,7 @@ MoveScreenLoop: ; 12fd5
ret
; 13154
-.exit: ; 13154
+.exit
xor a
ld [wMoveSwapBuffer], a
ld hl, w2DMenuFlags1
@@ -1776,7 +1772,7 @@ SetUpMoveScreenBG: ; 13172
ld a, [hl]
ld [wd265], a
ld e, $2
- callba Function8e83f
+ callba LoadMenuMonIcon
hlcoord 0, 1
ld b, 9
ld c, 18
diff --git a/engine/tile_events.asm b/engine/tile_events.asm
index a6794e817..77f267b4f 100755
--- a/engine/tile_events.asm
+++ b/engine/tile_events.asm
@@ -21,17 +21,17 @@ CheckDirectionalWarp:: ; 149af
; Else, set carry (immediate warp).
ld a, [PlayerStandingTile]
cp $70 ; Warp on down
- jr z, .not_warp
+ jr z, .directional
cp $76 ; Warp on left
- jr z, .not_warp
+ jr z, .directional
cp $78 ; Warp on up
- jr z, .not_warp
+ jr z, .directional
cp $7e ; Warp on right
- jr z, .not_warp
+ jr z, .directional
scf
ret
-.not_warp
+.directional
xor a
ret
; 149c6
diff --git a/engine/time.asm b/engine/time.asm
index 4240522c2..29670afdc 100755
--- a/engine/time.asm
+++ b/engine/time.asm
@@ -124,16 +124,14 @@ endr
jr z, .RestartKenjiBreakCountdown
dec [hl]
jr nz, .DontRestartKenjiBreakCountdown
-
.RestartKenjiBreakCountdown
call Special_SampleKenjiBreakCountdown
-
.DontRestartKenjiBreakCountdown
jr RestartDailyResetTimer
; 11485
Special_SampleKenjiBreakCountdown: ; 11485
-; Generate a random number between 3 and 5
+; Generate a random number between 3 and 6
call Random
and 3
add 3
diff --git a/engine/trade/animation.asm b/engine/trade/animation.asm
index 719a230ff..be5318b2e 100755
--- a/engine/trade/animation.asm
+++ b/engine/trade/animation.asm
@@ -1440,7 +1440,7 @@ LoadTradeBallAndCableGFX: ; 2982b
LoadTradeBubbleGFX: ; 2985a
call DelayFrame
ld e, $3
- callab Function8e83f
+ callab LoadMenuMonIcon
ld de, TradeBubbleGFX
ld hl, VTiles0 tile $72
lb bc, BANK(TradeBubbleGFX), $4
diff --git a/event/happiness_egg.asm b/event/happiness_egg.asm
new file mode 100755
index 000000000..810b8527d
--- /dev/null
+++ b/event/happiness_egg.asm
@@ -0,0 +1,238 @@
+GetFirstPokemonHappiness: ; 718d
+ ld hl, PartyMon1Happiness
+ ld bc, PARTYMON_STRUCT_LENGTH
+ ld de, PartySpecies
+.loop
+ ld a, [de]
+ cp EGG
+ jr nz, .done
+ inc de
+ add hl, bc
+ jr .loop
+
+.done
+ ld [wd265], a
+ ld a, [hl]
+ ld [ScriptVar], a
+ call GetPokemonName
+ jp CopyPokemonName_Buffer1_Buffer3
+
+CheckFirstMonIsEgg: ; 71ac
+ ld a, [PartySpecies]
+ ld [wd265], a
+ cp EGG
+ ld a, $1
+ jr z, .egg
+ xor a
+
+.egg
+ ld [ScriptVar], a
+ call GetPokemonName
+ jp CopyPokemonName_Buffer1_Buffer3
+
+ChangeHappiness: ; 71c2
+; Perform happiness action c on CurPartyMon
+
+ ld a, [CurPartyMon]
+ inc a
+ ld e, a
+ ld d, 0
+ ld hl, PartySpecies - 1
+ add hl, de
+ ld a, [hl]
+ cp EGG
+ ret z
+
+ push bc
+ ld hl, PartyMon1Happiness
+ ld bc, PARTYMON_STRUCT_LENGTH
+ ld a, [CurPartyMon]
+ call AddNTimes
+ pop bc
+
+ ld d, h
+ ld e, l
+
+ push de
+ ld a, [de]
+ cp 100
+ ld e, 0
+ jr c, .ok
+ inc e
+ cp 200
+ jr c, .ok
+ inc e
+
+.ok
+ dec c
+ ld b, 0
+ ld hl, .Actions
+rept 3
+ add hl, bc
+endr
+ ld d, 0
+ add hl, de
+ ld a, [hl]
+ cp 100
+ pop de
+
+ ld a, [de]
+ jr nc, .negative
+ add [hl]
+ jr nc, .done
+ ld a, -1
+ jr .done
+
+.negative
+ add [hl]
+ jr c, .done
+ xor a
+
+.done
+ ld [de], a
+ ld a, [wBattleMode]
+ and a
+ ret z
+ ld a, [CurPartyMon]
+ ld b, a
+ ld a, [wPartyMenuCursor]
+ cp b
+ ret nz
+ ld a, [de]
+ ld [BattleMonHappiness], a
+ ret
+
+.Actions
+ db +5, +3, +2 ; Gained a level
+ db +5, +3, +2 ; Vitamin
+ db +1, +1, +0 ; X Item
+ db +3, +2, +1 ; Battled a Gym Leader
+ db +1, +1, +0 ; Learned a move
+ db -1, -1, -1 ; Lost to an enemy
+ db -5, -5, -10 ; Fainted due to poison
+ db -5, -5, -10 ; Lost to a much stronger enemy
+ db +1, +1, +1 ; Haircut (Y1)
+ db +3, +3, +1 ; Haircut (Y2)
+ db +5, +5, +2 ; Haircut (Y3)
+ db +1, +1, +1 ; Haircut (O1)
+ db +3, +3, +1 ; Haircut (O2)
+ db +10, +10, +4 ; Haircut (O3)
+ db -5, -5, -10 ; Used Heal Powder or Energypowder (bitter)
+ db -10, -10, -15 ; Used Energy Root (bitter)
+ db -15, -15, -20 ; Used Revival Herb (bitter)
+ db +3, +3, +1 ; Grooming
+ db +10, +6, +4 ; Gained a level in the place where it was caught
+
+StepHappiness:: ; 725a
+; Raise the party's happiness by 1 point every other step cycle.
+
+ ld hl, wHappinessStepCount
+ ld a, [hl]
+ inc a
+ and 1
+ ld [hl], a
+ ret nz
+
+ ld de, PartyCount
+ ld a, [de]
+ and a
+ ret z
+
+ ld c, a
+ ld hl, PartyMon1Happiness
+.loop
+ inc de
+ ld a, [de]
+ cp EGG
+ jr z, .next
+ inc [hl]
+ jr nz, .next
+ ld [hl], $ff
+
+.next
+ push de
+ ld de, PARTYMON_STRUCT_LENGTH
+ add hl, de
+ pop de
+ dec c
+ jr nz, .loop
+ ret
+
+DaycareStep:: ; 7282
+
+ ld a, [wDaycareMan]
+ bit 0, a
+ jr z, .daycare_lady
+
+ ld a, [wBreedMon1Level] ; level
+ cp 100
+ jr nc, .daycare_lady
+ ld hl, wBreedMon1Exp + 2 ; exp
+ inc [hl]
+ jr nz, .daycare_lady
+ dec hl
+ inc [hl]
+ jr nz, .daycare_lady
+ dec hl
+ inc [hl]
+ ld a, [hl]
+ cp 5242880 / $10000
+ jr c, .daycare_lady
+ ld a, 5242880 / $10000
+ ld [hl], a
+
+.daycare_lady
+ ld a, [wDaycareLady]
+ bit 0, a
+ jr z, .check_egg
+
+ ld a, [wBreedMon2Level] ; level
+ cp 100
+ jr nc, .check_egg
+ ld hl, wBreedMon2Exp + 2 ; exp
+ inc [hl]
+ jr nz, .check_egg
+ dec hl
+ inc [hl]
+ jr nz, .check_egg
+ dec hl
+ inc [hl]
+ ld a, [hl]
+ cp 5242880 / $10000
+ jr c, .check_egg
+ ld a, 5242880 / $10000
+ ld [hl], a
+
+.check_egg
+ ld hl, wDaycareMan
+ bit 5, [hl] ; egg
+ ret z
+ ld hl, wStepsToEgg
+ dec [hl]
+ ret nz
+
+ call Random
+ ld [hl], a
+ callab CheckBreedmonCompatibility
+ ld a, [wd265]
+ cp 230
+ ld b, -1 + 32 percent
+ jr nc, .okay
+ ld a, [wd265]
+ cp 170
+ ld b, 16 percent
+ jr nc, .okay
+ ld a, [wd265]
+ cp 110
+ ld b, 12 percent
+ jr nc, .okay
+ ld b, 4 percent
+
+.okay
+ call Random
+ cp b
+ ret nc
+ ld hl, wDaycareMan
+ res 5, [hl]
+ set 6, [hl]
+ ret
diff --git a/event/mom.asm b/event/mom.asm
index ab405a27c..4102ee771 100644
--- a/event/mom.asm
+++ b/event/mom.asm
@@ -480,7 +480,7 @@ Function1651a: ; 1651a
lb bc, PRINTNUM_MONEY | PRINTNUM_LEADINGZEROS | 3, 6
call PrintNum
call UpdateSprites
- call Function3238
+ call CGBOnly_LoadEDTile
ret
; 1656b
diff --git a/event/overworld.asm b/event/overworld.asm
new file mode 100755
index 000000000..43be63238
--- /dev/null
+++ b/event/overworld.asm
@@ -0,0 +1,1890 @@
+FieldMoveJumptableReset: ; c6ea
+ xor a
+ ld hl, Buffer1
+ ld bc, 7
+ call ByteFill
+ ret
+
+FieldMoveJumptable: ; c6f5
+ ld a, [Buffer1]
+ rst JumpTable
+ ld [Buffer1], a
+ bit 7, a
+ jr nz, .okay
+ and a
+ ret
+
+.okay
+ and $7f
+ scf
+ ret
+
+GetPartyNick: ; c706
+; write CurPartyMon nickname to StringBuffer1-3
+ ld hl, PartyMonNicknames
+ ld a, BOXMON
+ ld [MonType], a
+ ld a, [CurPartyMon]
+ call GetNick
+ call CopyName1
+; copy text from StringBuffer2 to StringBuffer3
+ ld de, StringBuffer2
+ ld hl, StringBuffer3
+ call CopyName2
+ ret
+
+CheckEngineFlag: ; c721
+; Check engine flag de
+; Return carry if flag is not set
+ ld b, CHECK_FLAG
+ callba EngineFlagAction
+ ld a, c
+ and a
+ jr nz, .isset
+ scf
+ ret
+.isset
+ xor a
+ ret
+
+CheckBadge: ; c731
+; Check engine flag a (ENGINE_ZEPHYRBADGE thru ENGINE_EARTHBADGE)
+; Display "Badge required" text and return carry if the badge is not owned
+ call CheckEngineFlag
+ ret nc
+ ld hl, .BadgeRequiredText
+ call MenuTextBoxBackup ; push text to queue
+ scf
+ ret
+
+.BadgeRequiredText: ; c73d
+ ; Sorry! A new BADGE
+ ; is required.
+ text_jump _BadgeRequiredText
+ db "@"
+
+CheckPartyMove: ; c742
+; Check if a monster in your party has move d.
+
+ ld e, 0
+ xor a
+ ld [CurPartyMon], a
+.loop
+ ld c, e
+ ld b, 0
+ ld hl, PartySpecies
+ add hl, bc
+ ld a, [hl]
+ and a
+ jr z, .no
+ cp a, -1
+ jr z, .no
+ cp a, EGG
+ jr z, .next
+
+ ld bc, PARTYMON_STRUCT_LENGTH
+ ld hl, PartyMon1Moves
+ ld a, e
+ call AddNTimes
+ ld b, NUM_MOVES
+.check
+ ld a, [hli]
+ cp d
+ jr z, .yes
+ dec b
+ jr nz, .check
+
+.next
+ inc e
+ jr .loop
+
+.yes
+ ld a, e
+ ld [CurPartyMon], a ; which mon has the move
+ xor a
+ ret
+.no
+ scf
+ ret
+
+FieldMoveFailed: ; c779
+ ld hl, .CantUseHere
+ call MenuTextBoxBackup
+ ret
+
+.CantUseHere: ; 0xc780
+ ; Can't use that here.
+ text_jump UnknownText_0x1c05c8
+ db "@"
+
+CutFunction: ; c785
+ call FieldMoveJumptableReset
+.loop
+ ld hl, .Jumptable
+ call FieldMoveJumptable
+ jr nc, .loop
+ and $7f
+ ld [wFieldMoveSucceeded], a
+ ret
+
+.Jumptable: ; c796 (3:4796)
+
+ dw .CheckAble
+ dw .DoCut
+ dw .FailCut
+
+.CheckAble: ; c79c (3:479c)
+ ld de, ENGINE_HIVEBADGE
+ call CheckBadge
+ jr c, .nohivebadge
+ call CheckMapForSomethingToCut
+ jr c, .nothingtocut
+ ld a, $1
+ ret
+
+.nohivebadge
+ ld a, $80
+ ret
+
+.nothingtocut
+ ld a, $2
+ ret
+
+.DoCut: ; c7b2 (3:47b2)
+ ld hl, Script_CutFromMenu
+ call QueueScript
+ ld a, $81
+ ret
+
+.FailCut: ; c7bb (3:47bb)
+ ld hl, Text_NothingToCut
+ call MenuTextBoxBackup
+ ld a, $80
+ ret
+
+Text_UsedCut: ; 0xc7c4
+ ; used CUT!
+ text_jump UnknownText_0x1c05dd
+ db "@"
+
+Text_NothingToCut: ; 0xc7c9
+ ; There's nothing to CUT here.
+ text_jump UnknownText_0x1c05ec
+ db "@"
+
+CheckMapForSomethingToCut: ; c7ce
+ ; Does the collision data of the facing tile permit cutting?
+ call GetFacingTileCoord
+ ld c, a
+ push de
+ callba CheckCutCollision
+ pop de
+ jr nc, .fail
+ ; Get the location of the current block in OverworldMap.
+ call GetBlockLocation
+ ld c, [hl]
+ ; See if that block contains something that can be cut.
+ push hl
+ ld hl, CutTreeBlockPointers
+ call CheckOverworldTileArrays
+ pop hl
+ jr nc, .fail
+ ; Back up the OverworldMap address to Buffer3
+ ld a, l
+ ld [Buffer3], a
+ ld a, h
+ ld [Buffer4], a
+ ; Back up the replacement tile to Buffer5
+ ld a, b
+ ld [Buffer5], a
+ ; Back up the animation index to Buffer6
+ ld a, c
+ ld [Buffer6], a
+ xor a
+ ret
+
+.fail
+ scf
+ ret
+
+Script_CutFromMenu: ; c7fe
+ reloadmappart
+ special UpdateTimePals
+
+Script_Cut: ; 0xc802
+ callasm GetPartyNick
+ writetext Text_UsedCut
+ reloadmappart
+ callasm CutDownTreeOrGrass
+ closetext
+ end
+
+CutDownTreeOrGrass: ; c810
+ ld hl, Buffer3 ; OverworldMapTile
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld a, [Buffer5] ; ReplacementTile
+ ld [hl], a
+ xor a
+ ld [hBGMapMode], a
+ call OverworldTextModeSwitch
+ call UpdateSprites
+ call DelayFrame
+ ld a, [Buffer6] ; Animation type
+ ld e, a
+ callba OWCutAnimation
+ call BufferScreen
+ call GetMovementPermissions
+ call UpdateSprites
+ call DelayFrame
+ call LoadStandardFont
+ ret
+
+CheckOverworldTileArrays: ; c840
+ ; Input: c contains the tile you're facing
+ ; Output: Replacement tile in b and effect on wild encounters in c, plus carry set.
+ ; Carry is not set if the facing tile cannot be replaced, or if the tileset
+ ; does not contain a tile you can replace.
+
+ ; Dictionary lookup for pointer to tile replacement table
+ push bc
+ ld a, [wTileset]
+ ld de, 3
+ call IsInArray
+ pop bc
+ jr nc, .nope
+ ; Load the pointer
+ inc hl
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ; Look up the tile you're facing
+ ld de, 3
+ ld a, c
+ call IsInArray
+ jr nc, .nope
+ ; Load the replacement to b
+ inc hl
+ ld b, [hl]
+ ; Load the animation type parameter to c
+ inc hl
+ ld c, [hl]
+ scf
+ ret
+
+.nope
+ xor a
+ ret
+
+CutTreeBlockPointers: ; c862
+; Which tileset are we in?
+ dbw TILESET_JOHTO_1, .johto1
+ dbw TILESET_JOHTO_2, .johto2
+ dbw TILESET_KANTO, .kanto
+ dbw TILESET_PARK, .park
+ dbw TILESET_ILEX_FOREST, .ilex
+ db -1
+
+.johto1: ; Johto OW
+; Which meta tile are we facing, which should we replace it with, and which animation?
+ db $03, $02, $01 ; grass
+ db $5b, $3c, $00 ; tree
+ db $5f, $3d, $00 ; tree
+ db $63, $3f, $00 ; tree
+ db $67, $3e, $00 ; tree
+ db -1
+
+.johto2: ; Goldenrod area
+ db $03, $02, $01 ; grass
+ db -1
+
+.kanto: ; Kanto OW
+ db $0b, $0a, $01 ; grass
+ db $32, $6d, $00 ; tree
+ db $33, $6c, $00 ; tree
+ db $34, $6f, $00 ; tree
+ db $35, $4c, $00 ; tree
+ db $60, $6e, $00 ; tree
+ db -1
+
+.park: ; National Park
+ db $13, $03, $01 ; grass
+ db $03, $04, $01 ; grass
+ db -1
+
+.ilex: ; Ilex Forest
+ db $0f, $17, $00
+ db -1
+
+WhirlpoolBlockPointers: ; c8a4
+ dbw TILESET_JOHTO_1, .johto
+ db -1
+
+.johto: ; c8a8
+ db $07, $36, $00
+ db -1
+
+OWFlash: ; c8ac
+ call .CheckUseFlash
+ and $7f
+ ld [wFieldMoveSucceeded], a
+ ret
+
+.CheckUseFlash: ; c8b5
+; Flash
+ ld de, ENGINE_ZEPHYRBADGE
+ callba CheckBadge
+ jr c, .nozephyrbadge
+ push hl
+ callba SpecialAerodactylChamber
+ pop hl
+ jr c, .useflash
+ ld a, [wTimeOfDayPalset]
+ cp %11111111 ; 3, 3, 3, 3
+ jr nz, .notadarkcave
+.useflash
+ call UseFlash
+ ld a, $81
+ ret
+
+.notadarkcave
+ call FieldMoveFailed
+ ld a, $80
+ ret
+
+.nozephyrbadge
+ ld a, $80
+ ret
+
+UseFlash: ; c8e0
+ ld hl, Script_UseFlash
+ jp QueueScript
+
+Script_UseFlash: ; 0xc8e6
+ reloadmappart
+ special UpdateTimePals
+ writetext UnknownText_0xc8f3
+ callasm BlindingFlash
+ closetext
+ end
+
+UnknownText_0xc8f3: ; 0xc8f3
+ text_jump UnknownText_0x1c0609
+ start_asm
+ call WaitSFX
+ ld de, SFX_FLASH
+ call PlaySFX
+ call WaitSFX
+ ld hl, .BlankText
+ ret
+
+.BlankText: ; 0xc908
+ db "@"
+
+SurfFunction: ; c909
+ call FieldMoveJumptableReset
+.loop
+ ld hl, .Jumptable
+ call FieldMoveJumptable
+ jr nc, .loop
+ and $7f
+ ld [wFieldMoveSucceeded], a
+ ret
+
+.Jumptable: ; c91a (3:491a)
+ dw .TrySurf
+ dw .DoSurf
+ dw .FailSurf
+ dw .AlreadySurfing
+
+.TrySurf: ; c922 (3:4922)
+ ld de, ENGINE_FOGBADGE
+ call CheckBadge
+ jr c, .asm_c956
+ ld hl, BikeFlags
+ bit 1, [hl] ; always on bike
+ jr nz, .cannotsurf
+ ld a, [PlayerState]
+ cp PLAYER_SURF
+ jr z, .alreadyfail
+ cp PLAYER_SURF_PIKA
+ jr z, .alreadyfail
+ call GetFacingTileCoord
+ call GetTileCollision
+ cp $1
+ jr nz, .cannotsurf
+ call CheckDirection
+ jr c, .cannotsurf
+ callba CheckFacingObject
+ jr c, .cannotsurf
+ ld a, $1
+ ret
+.asm_c956
+ ld a, $80
+ ret
+.alreadyfail
+ ld a, $3
+ ret
+.cannotsurf
+ ld a, $2
+ ret
+
+.DoSurf: ; c95f (3:495f)
+ call GetSurfType
+ ld [Buffer2], a ; wd1eb (aliases: MovementType)
+ call GetPartyNick
+ ld hl, SurfFromMenuScript
+ call QueueScript
+ ld a, $81
+ ret
+
+.FailSurf: ; c971 (3:4971)
+ ld hl, CantSurfText
+ call MenuTextBoxBackup
+ ld a, $80
+ ret
+
+.AlreadySurfing: ; c97a (3:497a)
+ ld hl, AlreadySurfingText
+ call MenuTextBoxBackup
+ ld a, $80
+ ret
+
+SurfFromMenuScript: ; c983
+ special UpdateTimePals
+
+UsedSurfScript: ; c986
+ writetext UsedSurfText ; "used SURF!"
+ waitbutton
+ closetext
+
+ callasm .empty_fn ; empty function
+
+ copybytetovar Buffer2
+ writevarcode VAR_MOVEMENT
+
+ special ReplaceKrisSprite
+ special PlayMapMusic
+; step into the water
+ special Special_SurfStartStep ; (slow_step_x, step_end)
+ applymovement PLAYER, MovementBuffer ; PLAYER, MovementBuffer
+ end
+
+.empty_fn: ; c9a2
+ callba MobileFn_1060bb ; empty
+ ret
+
+UsedSurfText: ; c9a9
+ text_jump _UsedSurfText
+ db "@"
+
+CantSurfText: ; c9ae
+ text_jump _CantSurfText
+ db "@"
+
+AlreadySurfingText: ; c9b3
+ text_jump _AlreadySurfingText
+ db "@"
+
+GetSurfType: ; c9b8
+; Surfing on Pikachu uses an alternate sprite.
+; This is done by using a separate movement type.
+
+ ld a, [CurPartyMon]
+ ld e, a
+ ld d, 0
+ ld hl, PartySpecies
+ add hl, de
+
+ ld a, [hl]
+ cp PIKACHU
+ ld a, PLAYER_SURF_PIKA
+ ret z
+ ld a, PLAYER_SURF
+ ret
+
+CheckDirection: ; c9cb
+; Return carry if a tile permission prevents you
+; from moving in the direction you're facing.
+
+; Get player direction
+ ld a, [PlayerDirection]
+ and a, %00001100 ; bits 2 and 3 contain direction
+ rrca
+ rrca
+ ld e, a
+ ld d, 0
+ ld hl, .Directions
+ add hl, de
+
+; Can you walk in this direction?
+ ld a, [TilePermissions]
+ and [hl]
+ jr nz, .quit
+ xor a
+ ret
+
+.quit
+ scf
+ ret
+
+.Directions
+ db FACE_DOWN
+ db FACE_UP
+ db FACE_LEFT
+ db FACE_RIGHT
+
+TrySurfOW:: ; c9e7
+; Checking a tile in the overworld.
+; Return carry if fail is allowed.
+
+; Don't ask to surf if already fail.
+ ld a, [PlayerState]
+ cp PLAYER_SURF_PIKA
+ jr z, .quit
+ cp PLAYER_SURF
+ jr z, .quit
+
+; Must be facing water.
+ ld a, [EngineBuffer1]
+ call GetTileCollision
+ cp 1 ; surfable
+ jr nz, .quit
+
+; Check tile permissions.
+ call CheckDirection
+ jr c, .quit
+
+ ld de, ENGINE_FOGBADGE
+ call CheckEngineFlag
+ jr c, .quit
+
+ ld d, SURF
+ call CheckPartyMove
+ jr c, .quit
+
+ ld hl, BikeFlags
+ bit 1, [hl] ; always on bike (can't surf)
+ jr nz, .quit
+
+ call GetSurfType
+ ld [MovementType], a
+ call GetPartyNick
+
+ ld a, BANK(AskSurfScript)
+ ld hl, AskSurfScript
+ call CallScript
+
+ scf
+ ret
+
+.quit
+ xor a
+ ret
+
+AskSurfScript: ; ca2c
+ opentext
+ writetext AskSurfText
+ yesorno
+ iftrue UsedSurfScript
+ closetext
+ end
+
+AskSurfText: ; ca36
+ text_jump _AskSurfText ; The water is calm.
+ db "@" ; Want to SURF?
+
+FlyFunction: ; ca3b
+ call FieldMoveJumptableReset
+.loop
+ ld hl, .Jumptable
+ call FieldMoveJumptable
+ jr nc, .loop
+ and $7f
+ ld [wFieldMoveSucceeded], a
+ ret
+
+.Jumptable
+ dw .TryFly
+ dw .DoFly
+ dw .FailFly
+
+.TryFly: ; ca52
+; Fly
+ ld de, ENGINE_STORMBADGE
+ call CheckBadge
+ jr c, .nostormbadge
+ call GetMapPermission
+ call CheckOutdoorMap
+ jr z, .outdoors
+ jr .indoors
+
+.outdoors
+ xor a
+ ld [hMapAnims], a
+ call LoadStandardMenuDataHeader
+ call ClearSprites
+ callba _FlyMap
+ ld a, e
+ cp -1
+ jr z, .illegal
+ cp NUM_SPAWNS
+ jr nc, .illegal
+
+ ld [wd001], a
+ call CloseWindow
+ ld a, $1
+ ret
+
+.nostormbadge
+ ld a, $82
+ ret
+
+.indoors
+ ld a, $2
+ ret
+
+.illegal
+ call CloseWindow
+ call WaitBGMap
+ ld a, $80
+ ret
+
+.DoFly: ; ca94
+ ld hl, .FlyScript
+ call QueueScript
+ ld a, $81
+ ret
+
+.FailFly: ; ca9d
+ call FieldMoveFailed
+ ld a, $82
+ ret
+
+.FlyScript: ; 0xcaa3
+ reloadmappart
+ callasm HideSprites
+ special UpdateTimePals
+ callasm FlyFromAnim
+ farscall Script_AbortBugContest
+ special WarpToSpawnPoint
+ callasm DelayLoadingNewSprites
+ writecode VAR_MOVEMENT, PLAYER_NORMAL
+ newloadmap MAPSETUP_FLY
+ callasm FlyToAnim
+ special WaitSFX
+ callasm .ReturnFromFly
+ end
+
+.ReturnFromFly: ; cacb
+ callba Function561d
+ call DelayFrame
+ call ReplaceKrisSprite
+ callba LoadOverworldFont
+ ret
+
+WaterfallFunction: ; cade
+ call .TryWaterfall
+ and $7f
+ ld [wFieldMoveSucceeded], a
+ ret
+
+.TryWaterfall: ; cae7
+; Waterfall
+ ld de, ENGINE_RISINGBADGE
+ callba CheckBadge
+ ld a, $80
+ ret c
+ call CheckMapCanWaterfall
+ jr c, .failed
+ ld hl, Script_WaterfallFromMenu
+ call QueueScript
+ ld a, $81
+ ret
+
+.failed
+ call FieldMoveFailed
+ ld a, $80
+ ret
+
+CheckMapCanWaterfall: ; cb07
+ ld a, [PlayerDirection]
+ and $c
+ cp FACE_UP
+ jr nz, .failed
+ ld a, [TileUp]
+ call CheckWaterfallTile
+ jr nz, .failed
+ xor a
+ ret
+
+.failed
+ scf
+ ret
+
+Script_WaterfallFromMenu: ; 0xcb1c
+ reloadmappart
+ special UpdateTimePals
+
+Script_UsedWaterfall: ; 0xcb20
+ callasm GetPartyNick
+ writetext .Text_UsedWaterfall
+ waitbutton
+ closetext
+ playsound SFX_BUBBLEBEAM
+.loop
+ applymovement PLAYER, .WaterfallStep
+ callasm .CheckContinueWaterfall
+ iffalse .loop
+ end
+
+.CheckContinueWaterfall: ; cb38
+ xor a
+ ld [ScriptVar], a
+ ld a, [PlayerStandingTile]
+ call CheckWaterfallTile
+ ret z
+ callba MobileFn_1060c1
+ ld a, $1
+ ld [ScriptVar], a
+ ret
+
+.WaterfallStep: ; cb4f
+ turn_waterfall_up
+ step_end
+
+.Text_UsedWaterfall: ; 0xcb51
+ ; used WATERFALL!
+ text_jump UnknownText_0x1c068e
+ db "@"
+
+TryWaterfallOW:: ; cb56
+ ld d, WATERFALL
+ call CheckPartyMove
+ jr c, .failed
+ ld de, ENGINE_RISINGBADGE
+ call CheckEngineFlag
+ jr c, .failed
+ call CheckMapCanWaterfall
+ jr c, .failed
+ ld a, BANK(Script_AskWaterfall)
+ ld hl, Script_AskWaterfall
+ call CallScript
+ scf
+ ret
+
+.failed
+ ld a, BANK(Script_CantDoWaterfall)
+ ld hl, Script_CantDoWaterfall
+ call CallScript
+ scf
+ ret
+
+Script_CantDoWaterfall: ; 0xcb7e
+ jumptext .Text_CantDoWaterfall
+
+.Text_CantDoWaterfall: ; 0xcb81
+ ; Wow, it's a huge waterfall.
+ text_jump UnknownText_0x1c06a3
+ db "@"
+
+Script_AskWaterfall: ; 0xcb86
+ opentext
+ writetext .AskUseWaterfall
+ yesorno
+ iftrue Script_UsedWaterfall
+ closetext
+ end
+
+.AskUseWaterfall: ; 0xcb90
+ ; Do you want to use WATERFALL?
+ text_jump UnknownText_0x1c06bf
+ db "@"
+
+EscapeRopeFunction: ; cb95
+ call FieldMoveJumptableReset
+ ld a, $1
+ jr dig_incave
+
+DigFunction: ; cb9c
+ call FieldMoveJumptableReset
+ ld a, $2
+
+dig_incave
+ ld [Buffer2], a
+.loop
+ ld hl, .DigTable
+ call FieldMoveJumptable
+ jr nc, .loop
+ and $7f
+ ld [wFieldMoveSucceeded], a
+ ret
+
+.DigTable: ; cbb2
+ dw .CheckCanDig
+ dw .DoDig
+ dw .FailDig
+
+.CheckCanDig: ; cbb8
+ call GetMapPermission
+ cp CAVE
+ jr z, .incave
+ cp DUNGEON
+ jr z, .incave
+.fail
+ ld a, $2
+ ret
+
+.incave
+ ld hl, wDigWarp
+ ld a, [hli]
+ and a
+ jr z, .fail
+ ld a, [hli]
+ and a
+ jr z, .fail
+ ld a, [hl]
+ and a
+ jr z, .fail
+ ld a, $1
+ ret
+
+.DoDig: ; cbd8
+ ld hl, wDigWarp
+ ld de, wNextWarp
+ ld bc, 3
+ call CopyBytes
+ call GetPartyNick
+ ld a, [Buffer2]
+ cp $2
+ jr nz, .escaperope
+ ld hl, .UsedDigScript
+ call QueueScript
+ ld a, $81
+ ret
+
+.escaperope
+ callba SpecialKabutoChamber
+ ld hl, .UsedEscapeRopeScript
+ call QueueScript
+ ld a, $81
+ ret
+
+.FailDig: ; cc06
+ ld a, [Buffer2]
+ cp $2
+ jr nz, .failescaperope
+ ld hl, .Text_CantUseHere
+ call MenuTextBox
+ call WaitPressAorB_BlinkCursor
+ call CloseWindow
+
+.failescaperope
+ ld a, $80
+ ret
+
+.Text_UsedDig: ; 0xcc1c
+ ; used DIG!
+ text_jump UnknownText_0x1c06de
+ db "@"
+
+.Text_UsedEscapeRope: ; 0xcc21
+ ; used an ESCAPE ROPE.
+ text_jump UnknownText_0x1c06ed
+ db "@"
+
+.Text_CantUseHere: ; 0xcc26
+ ; Can't use that here.
+ text_jump UnknownText_0x1c0705
+ db "@"
+
+.UsedEscapeRopeScript: ; 0xcc2b
+ reloadmappart
+ special UpdateTimePals
+ writetext .Text_UsedEscapeRope
+ jump .UsedDigOrEscapeRopeScript
+
+.UsedDigScript: ; 0xcc35
+ reloadmappart
+ special UpdateTimePals
+ writetext .Text_UsedDig
+
+.UsedDigOrEscapeRopeScript: ; 0xcc3c
+ waitbutton
+ closetext
+ playsound SFX_WARP_TO
+ applymovement PLAYER, .DigOut
+ farscall Script_AbortBugContest
+ special WarpToSpawnPoint
+ writecode VAR_MOVEMENT, PLAYER_NORMAL
+ newloadmap MAPSETUP_DOOR
+ playsound SFX_WARP_FROM
+ applymovement PLAYER, .DigReturn
+ end
+
+.DigOut: ; 0xcc59
+ step_dig 32
+ hide_person
+ step_end
+
+.DigReturn: ; 0xcc5d
+ show_person
+ return_dig 32
+ step_end
+
+TeleportFunction: ; cc61
+ call FieldMoveJumptableReset
+.loop
+ ld hl, .Jumptable
+ call FieldMoveJumptable
+ jr nc, .loop
+ and $7f
+ ld [wFieldMoveSucceeded], a
+ ret
+
+.Jumptable: ; cc72
+ dw .TryTeleport
+ dw .DoTeleport
+ dw .FailTeleport
+
+.TryTeleport: ; cc78
+ call GetMapPermission
+ call CheckOutdoorMap
+ jr z, .CheckIfSpawnPoint
+ jr .nope
+
+.CheckIfSpawnPoint
+ ld a, [wLastSpawnMapGroup]
+ ld d, a
+ ld a, [wLastSpawnMapNumber]
+ ld e, a
+ callba IsSpawnPoint
+ jr nc, .nope
+ ld a, c
+ ld [wd001], a
+ ld a, $1
+ ret
+
+.nope
+ ld a, $2
+ ret
+
+.DoTeleport: ; cc9c
+ call GetPartyNick
+ ld hl, .TeleportScript
+ call QueueScript
+ ld a, $81
+ ret
+
+.FailTeleport: ; cca8
+ ld hl, .Text_CantUseHere
+ call MenuTextBoxBackup
+ ld a, $80
+ ret
+
+.Text_ReturnToLastMonCenter: ; 0xccb1
+ ; Return to the last #MON CENTER.
+ text_jump UnknownText_0x1c071a
+ db "@"
+
+.Text_CantUseHere: ; 0xccb6
+ ; Can't use that here.
+ text_jump UnknownText_0x1c073b
+ db "@"
+
+.TeleportScript: ; 0xccbb
+ reloadmappart
+ special UpdateTimePals
+ writetext .Text_ReturnToLastMonCenter
+ pause 60
+ reloadmappart
+ closetext
+ playsound SFX_WARP_TO
+ applymovement PLAYER, .TeleportFrom
+ farscall Script_AbortBugContest
+ special WarpToSpawnPoint
+ writecode VAR_MOVEMENT, PLAYER_NORMAL
+ newloadmap MAPSETUP_TELEPORT
+ playsound SFX_WARP_FROM
+ applymovement PLAYER, .TeleportTo
+ end
+
+.TeleportFrom: ; cce1
+ teleport_from
+ step_end
+
+.TeleportTo: ; cce3
+ teleport_to
+ step_end
+
+StrengthFunction: ; cce5
+ call .TryStrength
+ and $7f
+ ld [wFieldMoveSucceeded], a
+ ret
+
+.TryStrength: ; ccee
+; Strength
+ ld de, ENGINE_PLAINBADGE
+ call CheckBadge
+ jr c, .Failed
+ jr .UseStrength
+
+.AlreadyUsing: ; unreferenced
+ ld hl, .JumpText
+ call MenuTextBoxBackup
+ ld a, $80
+ ret
+
+.JumpText: ; 0xcd01
+ text_jump UnknownText_0x1c0751
+ db "@"
+
+.Failed: ; cd06
+ ld a, $80
+ ret
+
+.UseStrength: ; cd09
+ ld hl, Script_StrengthFromMenu
+ call QueueScript
+ ld a, $81
+ ret
+
+SetStrengthFlag: ; cd12
+ ld hl, BikeFlags
+ set 0, [hl]
+ ld a, [CurPartyMon]
+ ld e, a
+ ld d, 0
+ ld hl, PartySpecies
+ add hl, de
+ ld a, [hl]
+ ld [Buffer6], a
+ call GetPartyNick
+ ret
+
+Script_StrengthFromMenu: ; 0xcd29
+ reloadmappart
+ special UpdateTimePals
+
+Script_UsedStrength: ; 0xcd2d
+ callasm SetStrengthFlag
+ writetext .UsedStrength
+ copybytetovar Buffer6
+ cry 0
+ pause 3
+ writetext .StrengthAllowedItToMoveBoulders
+ closetext
+ end
+
+.UsedStrength: ; 0xcd41
+ text_jump UnknownText_0x1c0774
+ db "@"
+
+.StrengthAllowedItToMoveBoulders: ; 0xcd46
+ text_jump UnknownText_0x1c0788
+ db "@"
+
+AskStrengthScript:
+ callasm TryStrengthOW
+ iffalse .AskStrength
+ if_equal $1, .DontMeetRequirements
+ jump .AlreadyUsedStrength
+
+.DontMeetRequirements: ; 0xcd59
+ jumptext UnknownText_0xcd73
+
+.AlreadyUsedStrength: ; 0xcd5c
+ jumptext UnknownText_0xcd6e
+
+.AskStrength: ; 0xcd5f
+ opentext
+ writetext UnknownText_0xcd69
+ yesorno
+ iftrue Script_UsedStrength
+ closetext
+ end
+
+UnknownText_0xcd69: ; 0xcd69
+ ; A #MON may be able to move this. Want to use STRENGTH?
+ text_jump UnknownText_0x1c07a0
+ db "@"
+
+UnknownText_0xcd6e: ; 0xcd6e
+ ; Boulders may now be moved!
+ text_jump UnknownText_0x1c07d8
+ db "@"
+
+UnknownText_0xcd73: ; 0xcd73
+ ; A #MON may be able to move this.
+ text_jump UnknownText_0x1c07f4
+ db "@"
+
+TryStrengthOW: ; cd78
+ ld d, STRENGTH
+ call CheckPartyMove
+ jr c, .nope
+
+ ld de, ENGINE_PLAINBADGE
+ call CheckEngineFlag
+ jr c, .nope
+
+ ld hl, BikeFlags
+ bit 0, [hl]
+ jr z, .already_using
+
+ ld a, 2
+ jr .done
+
+.nope
+ ld a, 1
+ jr .done
+
+.already_using
+ xor a
+ jr .done
+
+.done
+ ld [ScriptVar], a
+ ret
+
+WhirlpoolFunction: ; cd9d
+ call FieldMoveJumptableReset
+.loop
+ ld hl, Jumptable_cdae
+ call FieldMoveJumptable
+ jr nc, .loop
+ and $7f
+ ld [wFieldMoveSucceeded], a
+ ret
+
+Jumptable_cdae: ; cdae
+ dw .TryWhirlpool
+ dw .DoWhirlpool
+ dw .FailWhirlpool
+
+.TryWhirlpool: ; cdb4
+ ld de, ENGINE_GLACIERBADGE
+ call CheckBadge
+ jr c, .noglacierbadge
+ call TryWhirlpoolMenu
+ jr c, .failed
+ ld a, $1
+ ret
+
+.failed
+ ld a, $2
+ ret
+
+.noglacierbadge
+ ld a, $80
+ ret
+
+.DoWhirlpool: ; cdca
+ ld hl, Script_WhirlpoolFromMenu
+ call QueueScript
+ ld a, $81
+ ret
+
+.FailWhirlpool: ; cdd3
+ call FieldMoveFailed
+ ld a, $80
+ ret
+
+Text_UsedWhirlpool: ; 0xcdd9
+ ; used WHIRLPOOL!
+ text_jump UnknownText_0x1c0816
+ db "@"
+
+TryWhirlpoolMenu: ; cdde
+ call GetFacingTileCoord
+ ld c, a
+ push de
+ call CheckWhirlpoolTile
+ pop de
+ jr c, .failed
+ call GetBlockLocation
+ ld c, [hl]
+ push hl
+ ld hl, WhirlpoolBlockPointers
+ call CheckOverworldTileArrays
+ pop hl
+ jr nc, .failed
+ ld a, l
+ ld [Buffer3], a
+ ld a, h
+ ld [Buffer4], a
+ ld a, b
+ ld [Buffer5], a
+ ld a, c
+ ld [Buffer6], a
+ xor a
+ ret
+
+.failed
+ scf
+ ret
+
+Script_WhirlpoolFromMenu: ; 0xce0b
+ reloadmappart
+ special UpdateTimePals
+
+Script_UsedWhirlpool: ; 0xce0f
+ callasm GetPartyNick
+ writetext Text_UsedWhirlpool
+ reloadmappart
+ callasm DisappearWhirlpool
+ closetext
+ end
+
+DisappearWhirlpool: ; ce1d
+ ld hl, Buffer3
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld a, [Buffer5]
+ ld [hl], a
+ xor a
+ ld [hBGMapMode], a
+ call OverworldTextModeSwitch
+ ld a, [Buffer6]
+ ld e, a
+ callba PlayWhirlpoolSound
+ call BufferScreen
+ call GetMovementPermissions
+ ret
+
+TryWhirlpoolOW:: ; ce3e
+ ld d, WHIRLPOOL
+ call CheckPartyMove
+ jr c, .failed
+ ld de, ENGINE_GLACIERBADGE
+ call CheckEngineFlag
+ jr c, .failed
+ call TryWhirlpoolMenu
+ jr c, .failed
+ ld a, BANK(Script_AskWhirlpoolOW)
+ ld hl, Script_AskWhirlpoolOW
+ call CallScript
+ scf
+ ret
+
+.failed
+ ld a, BANK(Script_MightyWhirlpool)
+ ld hl, Script_MightyWhirlpool
+ call CallScript
+ scf
+ ret
+
+Script_MightyWhirlpool: ; 0xce66
+ jumptext .MightyWhirlpoolText
+
+.MightyWhirlpoolText: ; 0xce69
+ text_jump UnknownText_0x1c082b
+ db "@"
+
+Script_AskWhirlpoolOW: ; 0xce6e
+ opentext
+ writetext UnknownText_0xce78
+ yesorno
+ iftrue Script_UsedWhirlpool
+ closetext
+ end
+
+UnknownText_0xce78: ; 0xce78
+ text_jump UnknownText_0x1c0864
+ db "@"
+
+HeadbuttFunction: ; ce7d
+ call TryHeadbuttFromMenu
+ and $7f
+ ld [wFieldMoveSucceeded], a
+ ret
+
+TryHeadbuttFromMenu: ; ce86
+ call GetFacingTileCoord
+ call CheckHeadbuttTreeTile
+ jr nz, .no_tree
+
+ ld hl, HeadbuttFromMenuScript
+ call QueueScript
+ ld a, $81
+ ret
+
+.no_tree
+ call FieldMoveFailed
+ ld a, $80
+ ret
+
+UnknownText_0xce9d: ; 0xce9d
+ ; did a HEADBUTT!
+ text_jump UnknownText_0x1c0897
+ db "@"
+
+UnknownText_0xcea2: ; 0xcea2
+ ; Nope. Nothing…
+ text_jump UnknownText_0x1c08ac
+ db "@"
+
+HeadbuttFromMenuScript: ; 0xcea7
+ reloadmappart
+ special UpdateTimePals
+
+HeadbuttScript: ; 0xceab
+ callasm GetPartyNick
+ writetext UnknownText_0xce9d
+
+ reloadmappart
+ callasm ShakeHeadbuttTree
+
+ callasm TreeMonEncounter
+ iffalse .no_battle
+ closetext
+ randomwildmon
+ startbattle
+ reloadmapafterbattle
+ end
+
+.no_battle
+ writetext UnknownText_0xcea2
+ waitbutton
+ closetext
+ end
+
+TryHeadbuttOW:: ; cec9
+ ld d, HEADBUTT
+ call CheckPartyMove
+ jr c, .no
+
+ ld a, BANK(AskHeadbuttScript)
+ ld hl, AskHeadbuttScript
+ call CallScript
+ scf
+ ret
+
+.no
+ xor a
+ ret
+
+AskHeadbuttScript: ; 0xcedc
+ opentext
+ writetext UnknownText_0xcee6
+ yesorno
+ iftrue HeadbuttScript
+ closetext
+ end
+
+UnknownText_0xcee6: ; 0xcee6
+ ; A #MON could be in this tree. Want to HEADBUTT it?
+ text_jump UnknownText_0x1c08bc
+ db "@"
+
+RockSmashFunction: ; ceeb
+ call TryRockSmashFromMenu
+ and $7f
+ ld [wFieldMoveSucceeded], a
+ ret
+
+TryRockSmashFromMenu: ; cef4
+ call GetFacingObject
+ jr c, .no_rock
+ ld a, d
+ cp $18
+ jr nz, .no_rock
+
+ ld hl, RockSmashFromMenuScript
+ call QueueScript
+ ld a, $81
+ ret
+
+.no_rock
+ call FieldMoveFailed
+ ld a, $80
+ ret
+
+GetFacingObject: ; cf0d
+ callba CheckFacingObject
+ jr nc, .fail
+
+ ld a, [hObjectStructIndexBuffer]
+ call GetObjectStruct
+ ld hl, OBJECT_MAP_OBJECT_INDEX
+ add hl, bc
+ ld a, [hl]
+ ld [hLastTalked], a
+ call GetMapObject
+ ld hl, MAPOBJECT_MOVEMENT
+ add hl, bc
+ ld a, [hl]
+ ld d, a
+ and a
+ ret
+
+.fail
+ scf
+ ret
+
+RockSmashFromMenuScript: ; 0xcf2e
+ reloadmappart
+ special UpdateTimePals
+
+RockSmashScript: ; cf32
+ callasm GetPartyNick
+ writetext UnknownText_0xcf58
+ closetext
+ special WaitSFX
+ playsound SFX_STRENGTH
+ earthquake 84
+ applymovement2 MovementData_0xcf55
+ disappear -2
+
+ callasm RockMonEncounter
+ copybytetovar TempWildMonSpecies
+ iffalse .done
+ randomwildmon
+ startbattle
+ reloadmapafterbattle
+.done
+ end
+
+MovementData_0xcf55: ; 0xcf55
+ rock_smash 10
+ step_end
+
+UnknownText_0xcf58: ; 0xcf58
+ text_jump UnknownText_0x1c08f0
+ db "@"
+
+AskRockSmashScript: ; 0xcf5d
+ callasm HasRockSmash
+ if_equal 1, .no
+
+ opentext
+ writetext UnknownText_0xcf77
+ yesorno
+ iftrue RockSmashScript
+ closetext
+ end
+.no
+ jumptext UnknownText_0xcf72
+
+UnknownText_0xcf72: ; 0xcf72
+ ; Maybe a #MON can break this.
+ text_jump UnknownText_0x1c0906
+ db "@"
+
+UnknownText_0xcf77: ; 0xcf77
+ ; This rock looks breakable. Want to use ROCK SMASH?
+ text_jump UnknownText_0x1c0924
+ db "@"
+
+HasRockSmash: ; cf7c
+ ld d, ROCK_SMASH
+ call CheckPartyMove
+ jr nc, .yes
+.no
+ ld a, 1
+ jr .done
+.yes
+ xor a
+ jr .done
+.done
+ ld [ScriptVar], a
+ ret
+
+FishFunction: ; cf8e
+ ld a, e
+ push af
+ call FieldMoveJumptableReset
+ pop af
+ ld [Buffer2], a
+.loop
+ ld hl, .FishTable
+ call FieldMoveJumptable
+ jr nc, .loop
+ and $7f
+ ld [wFieldMoveSucceeded], a
+ ret
+
+.FishTable: ; cfa5
+ dw .TryFish
+ dw .FishNoBite
+ dw .FishGotSomething
+ dw .FailFish
+ dw .FishNoFish
+
+.TryFish: ; cfaf
+ ld a, [PlayerState]
+ cp PLAYER_SURF
+ jr z, .fail
+ cp PLAYER_SURF_PIKA
+ jr z, .fail
+ call GetFacingTileCoord
+ call GetTileCollision
+ cp $1
+ jr z, .facingwater
+.fail
+ ld a, $3
+ ret
+
+.facingwater
+ call GetFishingGroup
+ and a
+ jr nz, .goodtofish
+ ld a, $4
+ ret
+
+.goodtofish
+ ld d, a
+ ld a, [Buffer2]
+ ld e, a
+ callba Fish
+ ld a, d
+ and a
+ jr z, .nonibble
+ ld [TempWildMonSpecies], a
+ ld a, e
+ ld [CurPartyLevel], a
+ ld a, BATTLETYPE_FISH
+ ld [BattleType], a
+ ld a, $2
+ ret
+
+.nonibble
+ ld a, $1
+ ret
+
+.FailFish: ; cff1
+ ld a, $80
+ ret
+
+.FishGotSomething: ; cff4
+ ld a, $1
+ ld [Buffer6], a
+ ld hl, Script_GotABite
+ call QueueScript
+ ld a, $81
+ ret
+
+.FishNoBite: ; d002
+ ld a, $2
+ ld [Buffer6], a
+ ld hl, Script_NotEvenANibble
+ call QueueScript
+ ld a, $81
+ ret
+
+.FishNoFish: ; d010
+ ld a, $0
+ ld [Buffer6], a
+ ld hl, Script_NotEvenANibble2
+ call QueueScript
+ ld a, $81
+ ret
+
+Script_NotEvenANibble: ; 0xd01e
+ scall Script_FishCastRod
+ writetext UnknownText_0xd0a9
+ jump Script_NotEvenANibble_FallThrough
+
+Script_NotEvenANibble2: ; 0xd027
+ scall Script_FishCastRod
+ writetext UnknownText_0xd0a9
+
+Script_NotEvenANibble_FallThrough: ; 0xd02d
+ loademote EMOTE_SHADOW
+ callasm PutTheRodAway
+ closetext
+ end
+
+Script_GotABite: ; 0xd035
+ scall Script_FishCastRod
+ callasm Fishing_CheckFacingUp
+ iffalse .NotFacingUp
+ applymovement PLAYER, .Movement_FacingUp
+ jump .FightTheHookedPokemon
+
+.NotFacingUp: ; 0xd046
+ applymovement PLAYER, .Movement_NotFacingUp
+
+.FightTheHookedPokemon: ; 0xd04a
+ pause 40
+ applymovement PLAYER, .Movement_RestoreRod
+ writetext UnknownText_0xd0a4
+ callasm PutTheRodAway
+ closetext
+ randomwildmon
+ startbattle
+ reloadmapafterbattle
+ end
+
+.Movement_NotFacingUp: ; d05c
+ fish_got_bite
+ fish_got_bite
+ fish_got_bite
+ fish_got_bite
+ show_emote
+ step_end
+
+.Movement_FacingUp: ; d062
+ fish_got_bite
+ fish_got_bite
+ fish_got_bite
+ fish_got_bite
+ step_sleep_1
+ show_emote
+ step_end
+
+.Movement_RestoreRod: ; d069
+ hide_emote
+ fish_cast_rod
+ step_end
+
+Fishing_CheckFacingUp: ; d06c
+ ld a, [PlayerDirection]
+ and $c
+ cp OW_UP
+ ld a, $1
+ jr z, .up
+ xor a
+
+.up
+ ld [ScriptVar], a
+ ret
+
+Script_FishCastRod: ; 0xd07c
+ reloadmappart
+ loadvar hBGMapMode, $0
+ special UpdateTimePals
+ loademote EMOTE_ROD
+ callasm LoadFishingGFX
+ loademote EMOTE_SHOCK
+ applymovement PLAYER, MovementData_0xd093
+ pause 40
+ end
+
+MovementData_0xd093: ; d093
+ fish_cast_rod
+ step_end
+
+PutTheRodAway: ; d095
+ xor a
+ ld [hBGMapMode], a
+ ld a, $1
+ ld [PlayerAction], a
+ call UpdateSprites
+ call ReplaceKrisSprite
+ ret
+
+UnknownText_0xd0a4: ; 0xd0a4
+ ; Oh! A bite!
+ text_jump UnknownText_0x1c0958
+ db "@"
+
+UnknownText_0xd0a9: ; 0xd0a9
+ ; Not even a nibble!
+ text_jump UnknownText_0x1c0965
+ db "@"
+
+UnknownText_0xd0ae: ; unused
+ ; Looks like there's nothing here.
+ text_jump UnknownText_0x1c0979
+ db "@"
+
+BikeFunction: ; d0b3
+ call .TryBike
+ and $7f
+ ld [wFieldMoveSucceeded], a
+ ret
+
+.TryBike: ; d0bc
+ call .CheckEnvironment
+ jr c, .CannotUseBike
+ ld a, [PlayerState]
+ cp PLAYER_NORMAL
+ jr z, .GetOnBike
+ cp PLAYER_BIKE
+ jr z, .GetOffBike
+ jr .CannotUseBike
+
+.GetOnBike
+ ld hl, Script_GetOnBike
+ ld de, Script_GetOnBike_Register
+ call .CheckIfRegistered
+ call QueueScript
+ xor a
+ ld [MusicFade], a
+ ld de, MUSIC_NONE
+ call PlayMusic
+ call DelayFrame
+ call MaxVolume
+ ld de, MUSIC_BICYCLE
+ ld a, e
+ ld [wMapMusic], a
+ call PlayMusic
+ ld a, $1
+ ret
+
+.GetOffBike
+ ld hl, BikeFlags
+ bit 1, [hl]
+ jr nz, .CantGetOffBike
+ ld hl, Script_GetOffBike
+ ld de, Script_GetOffBike_Register
+ call .CheckIfRegistered
+ ld a, BANK(Script_GetOffBike)
+ jr .done
+
+.CantGetOffBike
+ ld hl, Script_CantGetOffBike
+ jr .done
+
+.CannotUseBike
+ ld a, $0
+ ret
+
+.done
+ call QueueScript
+ ld a, $1
+ ret
+
+.CheckIfRegistered: ; d119
+ ld a, [wUsingItemWithSelect]
+ and a
+ ret z
+ ld h, d
+ ld l, e
+ ret
+
+.CheckEnvironment: ; d121
+ call GetMapPermission
+ call CheckOutdoorMap
+ jr z, .ok
+ cp CAVE
+ jr z, .ok
+ cp GATE
+ jr z, .ok
+ jr .nope
+
+.ok
+ call GetPlayerStandingTile
+ and $f ; can't use our bike in a wall or on water
+ jr nz, .nope
+ xor a
+ ret
+
+.nope
+ scf
+ ret
+
+Script_GetOnBike: ; 0xd13e
+ reloadmappart
+ special UpdateTimePals
+ writecode VAR_MOVEMENT, PLAYER_BIKE
+ writetext GotOnTheBikeText
+ waitbutton
+ closetext
+ special ReplaceKrisSprite
+ end
+
+Script_GetOnBike_Register: ; 0xd14e
+ writecode VAR_MOVEMENT, PLAYER_BIKE
+ closetext
+ special ReplaceKrisSprite
+ end
+
+; XXX
+ nop
+ ret
+
+Script_GetOffBike: ; 0xd158
+ reloadmappart
+ special UpdateTimePals
+ writecode VAR_MOVEMENT, PLAYER_NORMAL
+ writetext GotOffTheBikeText
+ waitbutton
+
+FinishGettingOffBike:
+ closetext
+ special ReplaceKrisSprite
+ special PlayMapMusic
+ end
+
+Script_GetOffBike_Register: ; 0xd16b
+ writecode VAR_MOVEMENT, PLAYER_NORMAL
+ jump FinishGettingOffBike
+
+Script_CantGetOffBike: ; 0xd171
+ writetext .CantGetOffBikeText
+ waitbutton
+ closetext
+ end
+
+.CantGetOffBikeText: ; 0xd177
+ ; You can't get off here!
+ text_jump UnknownText_0x1c099a
+ db "@"
+
+GotOnTheBikeText: ; 0xd17c
+ ; got on the @ .
+ text_jump UnknownText_0x1c09b2
+ db "@"
+
+GotOffTheBikeText: ; 0xd181
+ ; got off the @ .
+ text_jump UnknownText_0x1c09c7
+ db "@"
+
+TryCutOW:: ; d186
+ ld d, CUT
+ call CheckPartyMove
+ jr c, .cant_cut
+
+ ld de, ENGINE_HIVEBADGE
+ call CheckEngineFlag
+ jr c, .cant_cut
+
+ ld a, BANK(AskCutScript)
+ ld hl, AskCutScript
+ call CallScript
+ scf
+ ret
+
+.cant_cut
+ ld a, BANK(CantCutScript)
+ ld hl, CantCutScript
+ call CallScript
+ scf
+ ret
+
+AskCutScript: ; 0xd1a9
+ opentext
+ writetext UnknownText_0xd1c8
+ yesorno
+ iffalse .script_d1b8
+ callasm .CheckMap
+ iftrue Script_Cut
+.script_d1b8
+ closetext
+ end
+
+.CheckMap: ; d1ba
+ xor a
+ ld [ScriptVar], a
+ call CheckMapForSomethingToCut
+ ret c
+ ld a, TRUE
+ ld [ScriptVar], a
+ ret
+
+UnknownText_0xd1c8: ; 0xd1c8
+ text_jump UnknownText_0x1c09dd
+ db "@"
+
+CantCutScript: ; 0xd1cd
+ jumptext UnknownText_0xd1d0
+
+UnknownText_0xd1d0: ; 0xd1d0
+ text_jump UnknownText_0x1c0a05
+ db "@"
diff --git a/event/poke_seer.asm b/event/poke_seer.asm
index 08d0924c9..c033a0944 100644
--- a/event/poke_seer.asm
+++ b/event/poke_seer.asm
@@ -163,6 +163,7 @@ GetCaughtLevel: ; 4f18c
call ByteFill
; caught level
+ ; Limited to between 1 and 63 for some reason.
ld a, [wSeerCaughtData]
and $3f
jr z, .unknown
diff --git a/event/special.asm b/event/special.asm
new file mode 100755
index 000000000..602e56e62
--- /dev/null
+++ b/event/special.asm
@@ -0,0 +1,231 @@
+SpecialGiveShuckle: ; 7305
+
+; Adding to the party.
+ xor a
+ ld [MonType], a
+
+; Level 15 Shuckle.
+ ld a, SHUCKLE
+ ld [CurPartySpecies], a
+ ld a, 15
+ ld [CurPartyLevel], a
+
+ predef TryAddMonToParty
+ jr nc, .NotGiven
+
+; Caught data.
+ ld b, 0
+ callba SetGiftPartyMonCaughtData
+
+; Holding a Berry.
+ ld bc, PARTYMON_STRUCT_LENGTH
+ ld a, [PartyCount]
+ dec a
+ push af
+ push bc
+ ld hl, PartyMon1Item
+ call AddNTimes
+ ld [hl], BERRY
+ pop bc
+ pop af
+
+; OT ID.
+ ld hl, PartyMon1ID
+ call AddNTimes
+ ld a, $2
+ ld [hli], a
+ ld [hl], $6
+
+; Nickname.
+ ld a, [PartyCount]
+ dec a
+ ld hl, PartyMonNicknames
+ call SkipNames
+ ld de, SpecialShuckleNick
+ call CopyName2
+
+; OT.
+ ld a, [PartyCount]
+ dec a
+ ld hl, PartyMonOT
+ call SkipNames
+ ld de, SpecialShuckleOT
+ call CopyName2
+
+; Engine flag for this event.
+ ld hl, DailyFlags
+ set 5, [hl]
+; setflag ENGINE_SHUCKLE_GIVEN
+ ld a, 1
+ ld [ScriptVar], a
+ ret
+
+.NotGiven
+ xor a
+ ld [ScriptVar], a
+ ret
+
+SpecialShuckleOT:
+ db "MANIA@"
+SpecialShuckleNick:
+ db "SHUCKIE@"
+
+SpecialReturnShuckle: ; 737e
+ callba SelectMonFromParty
+ jr c, .refused
+
+ ld a, [CurPartySpecies]
+ cp SHUCKLE
+ jr nz, .DontReturn
+
+ ld a, [CurPartyMon]
+ ld hl, PartyMon1ID
+ ld bc, PARTYMON_STRUCT_LENGTH
+ call AddNTimes
+
+; OT ID
+ ld a, [hli]
+ cp 00518 / $100
+ jr nz, .DontReturn
+ ld a, [hl]
+ cp 00518 % $100
+ jr nz, .DontReturn
+
+; OT
+ ld a, [CurPartyMon]
+ ld hl, PartyMonOT
+ call SkipNames
+ ld de, SpecialShuckleOT
+.CheckOT
+ ld a, [de]
+ cp [hl]
+ jr nz, .DontReturn
+ cp "@"
+ jr z, .done
+ inc de
+ inc hl
+ jr .CheckOT
+
+.done
+ callba CheckCurPartyMonFainted
+ jr c, .fainted
+ ld a, [CurPartyMon]
+ ld hl, PartyMon1Happiness
+ ld bc, PARTYMON_STRUCT_LENGTH
+ call AddNTimes
+ ld a, [hl]
+ cp 150
+ ld a, $3
+ jr nc, .HappyToStayWithYou
+ xor a ; take from pc
+ ld [wPokemonWithdrawDepositParameter], a
+ callab RemoveMonFromPartyOrBox
+ ld a, $2
+.HappyToStayWithYou
+ ld [ScriptVar], a
+ ret
+
+.refused
+ ld a, $1
+ ld [ScriptVar], a
+ ret
+
+.DontReturn
+ xor a
+ ld [ScriptVar], a
+ ret
+
+.fainted
+ ld a, $4
+ ld [ScriptVar], a
+ ret
+
+Special_BillsGrandfather: ; 73f7
+ callba SelectMonFromParty
+ jr c, .cancel
+ ld a, [CurPartySpecies]
+ ld [ScriptVar], a
+ ld [wNamedObjectIndexBuffer], a
+ call GetPokemonName
+ jp CopyPokemonName_Buffer1_Buffer3
+
+.cancel
+ xor a
+ ld [ScriptVar], a
+ ret
+
+Special_YoungerHaircutBrother: ; 7413
+ ld hl, Data_YoungerHaircutBrother
+ jr MassageOrHaircut
+
+Special_OlderHaircutBrother: ; 7418
+ ld hl, Data_OlderHaircutBrother
+ jr MassageOrHaircut
+
+Special_DaisyMassage: ; 741d
+ ld hl, Data_DaisyMassage
+
+MassageOrHaircut: ; 7420
+ push hl
+ callba SelectMonFromParty
+ pop hl
+ jr c, .nope
+ ld a, [CurPartySpecies]
+ cp EGG
+ jr z, .egg
+ push hl
+ call GetCurNick
+ call CopyPokemonName_Buffer1_Buffer3
+ pop hl
+ call Random
+; Bug: Subtracting $ff from $ff fails to set c.
+; This can result in overflow into the next data array.
+; In the case of getting a massage from Daisy, we bleed
+; into CopyPokemonName_Buffer1_Buffer3, which passes
+; $d0 to ChangeHappiness and returns $73 to the script.
+; The end result is that there is a 0.4% chance your
+; Pokemon's happiness will not change at all.
+.loop
+ sub [hl]
+ jr c, .ok
+rept 3
+ inc hl
+endr
+ jr .loop
+
+.ok
+ inc hl
+ ld a, [hli]
+ ld [ScriptVar], a
+ ld c, [hl]
+ call ChangeHappiness
+ ret
+
+.nope
+ xor a
+ ld [ScriptVar], a
+ ret
+
+.egg
+ ld a, 1
+ ld [ScriptVar], a
+ ret
+
+Data_YoungerHaircutBrother: ; 7459
+ db $4c, 2, HAPPINESS_YOUNGCUT1 ; 30% chance
+ db $80, 3, HAPPINESS_YOUNGCUT2 ; 20% chance
+ db $ff, 4, HAPPINESS_YOUNGCUT3 ; 50% chance
+
+Data_OlderHaircutBrother: ; 7462
+ db $9a, 2, HAPPINESS_OLDERCUT1 ; 60% chance
+ db $4c, 3, HAPPINESS_OLDERCUT2 ; 10% chance
+ db $ff, 4, HAPPINESS_OLDERCUT3 ; 30% chance
+
+Data_DaisyMassage: ; 746b
+ db $ff, 2, HAPPINESS_MASSAGE ; 99.6% chance
+
+CopyPokemonName_Buffer1_Buffer3: ; 746e
+ ld hl, StringBuffer1
+ ld de, StringBuffer3
+ ld bc, PKMN_NAME_LENGTH
+ jp CopyBytes
diff --git a/extras b/extras
-Subproject 68edf51f1070b056c281471242220f9c6142e1b
+Subproject adbc204d741bec7a68c1e6cd67751f226d0347c
diff --git a/home.asm b/home.asm
index 8cb0d25b3..b747d10cf 100644
--- a/home.asm
+++ b/home.asm
@@ -560,7 +560,7 @@ ApplyTilemap:: ; 321c
ret
; 3238
-Function3238:: ; 3238
+CGBOnly_LoadEDTile:: ; 3238
ld a, [hCGB]
and a
jr z, WaitBGMap
diff --git a/home/map.asm b/home/map.asm
index c51f9c48a..b3c62b33a 100644
--- a/home/map.asm
+++ b/home/map.asm
@@ -1593,7 +1593,14 @@ GetMovementPermissions:: ; 2914
; 2945
.MovementPermissionsData ; 2945
- db 1, 2, 4, 8, 9, 10, 5, 6
+ db 1 << DOWN
+ db 1 << UP
+ db 1 << LEFT
+ db 1 << RIGHT
+ db (1 << DOWN) | (1 << RIGHT)
+ db (1 << UP) | (1 << RIGHT)
+ db (1 << DOWN) | (1 << LEFT)
+ db (1 << UP) | (1 << LEFT)
; 294d
.UpDown
@@ -1805,7 +1812,7 @@ GetBlockLocation:: ; 2a66
add 6
ld c, a
ld b, 0
- ld hl, wc801
+ ld hl, OverworldMap + 1
add hl, bc
ld a, e
srl a
diff --git a/home/menu.asm b/home/menu.asm
index 3e04af8cf..a8c2bb0b7 100644
--- a/home/menu.asm
+++ b/home/menu.asm
@@ -232,7 +232,7 @@ DoNthMenu:: ; 1e5d
call MenuFunc_1e7f
call MenuWriteText
call Function1eff
- call Function1f23
+ call GetStaticMenuJoypad
call GetMenuJoypad
call MenuClickSound
ret
@@ -360,20 +360,20 @@ Function1eff:: ; 1eff
; 1f1a
-Function1f1a:: ; 1f1a
+GetScrollingMenuJoypad:: ; 1f1a
call ScrollingMenuJoypad
ld hl, wMenuJoypadFilter
and [hl]
- jr Function1f2a
+ jr ContinueGettingMenuJoypad
; 1f23
-Function1f23:: ; 1f23
+GetStaticMenuJoypad:: ; 1f23
xor a
ld [wMenuJoypad], a
call StaticMenuJoypad
; 1f2a
-Function1f2a:: ; 1f2a
+ContinueGettingMenuJoypad:
bit A_BUTTON_F, a
jr nz, .a_button
bit B_BUTTON_F, a
diff --git a/home/movement.asm b/home/movement.asm
index f962c8316..5353bbe4a 100644
--- a/home/movement.asm
+++ b/home/movement.asm
@@ -4,9 +4,9 @@ InitMovementBuffer:: ; 1b1e
ld [wMovementBufferCount], a
ld a, $0 ; useless
ld [wd004], a
- ld a, $7
+ ld a, MovementBuffer % $100
ld [wd005], a
- ld a, $d0
+ ld a, MovementBuffer / $100
ld [wd006], a
ret
; 1b35
diff --git a/items/item_effects.asm b/items/item_effects.asm
index aa6c8f795..fb8e030bc 100644
--- a/items/item_effects.asm
+++ b/items/item_effects.asm
@@ -338,11 +338,13 @@ endr
; catch rate than BRN/PSN/PAR, which in turn provide a higher catch rate than
; no status effect at all. But instead, it makes BRN/PSN/PAR provide no
; benefit.
+; Uncomment the line below to fix this.
ld b, a
ld a, [EnemyMonStatus]
and 1 << FRZ | SLP
ld c, 10
jr nz, .addstatus
+ ; ld a, [EnemyMonStatus]
and a
ld c, 5
jr nz, .addstatus
@@ -3315,3 +3317,5 @@ GetMthMoveOfCurrentMon: ; f969
add hl, bc
ret
; f971
+
+INCLUDE "items/pokeball_wobble.asm"
diff --git a/items/pokeball_wobble.asm b/items/pokeball_wobble.asm
new file mode 100755
index 000000000..7fb4d3e38
--- /dev/null
+++ b/items/pokeball_wobble.asm
@@ -0,0 +1,88 @@
+GetPokeBallWobble: ; f971 (3:7971)
+; Returns whether a Poke Ball will wobble in the catch animation.
+; Whether a Pokemon is caught is determined beforehand.
+
+ push de
+
+ ld a, [rSVBK]
+ ld d, a
+ push de
+
+ ld a, 1 ; BANK(Buffer2)
+ ld [rSVBK], a
+
+ ld a, [Buffer2]
+ inc a
+ ld [Buffer2], a
+
+; Wobble up to 3 times.
+ cp 3 + 1
+ jr z, .finished
+
+ ld a, [wWildMon]
+ and a
+ ld c, 0 ; next
+ jr nz, .done
+
+ ld hl, .WobbleProbabilities
+ ld a, [Buffer1]
+ ld b, a
+.loop
+ ld a, [hli]
+ cp b
+ jr nc, .checkwobble
+ inc hl
+ jr .loop
+
+.checkwobble
+ ld b, [hl]
+ call Random
+ cp b
+ ld c, 0 ; next
+ jr c, .done
+ ld c, 2 ; escaped
+ jr .done
+
+.finished
+ ld a, [wWildMon]
+ and a
+ ld c, 1 ; caught
+ jr nz, .done
+ ld c, 2 ; escaped
+
+.done
+ pop de
+ ld e, a
+ ld a, d
+ ld [rSVBK], a
+ ld a, e
+ pop de
+ ret
+
+.WobbleProbabilities: ; f9ba
+; catch rate, chance of wobbling / 255
+; nLeft/255 = (nRight/255) ** 4
+ db 1, 63
+ db 2, 75
+ db 3, 84
+ db 4, 90
+ db 5, 95
+ db 7, 103
+ db 10, 113
+ db 15, 126
+ db 20, 134
+ db 30, 149
+ db 40, 160
+ db 50, 169
+ db 60, 177
+ db 80, 191
+ db 100, 201
+ db 120, 211
+ db 140, 220
+ db 160, 227
+ db 180, 234
+ db 200, 240
+ db 220, 246
+ db 240, 251
+ db 254, 253
+ db 255, 255
diff --git a/macros/move_effect.asm b/macros/move_effect.asm
index d25db45bd..d3761c9a1 100644
--- a/macros/move_effect.asm
+++ b/macros/move_effect.asm
@@ -5,181 +5,181 @@ endm
enum_start 1
- command checkturn
- command checkobedience
- command usedmovetext
- command doturn
- command critical
- command damagestats
- command stab
- command damagevariation
- command checkhit
- command lowersub
- command hittargetnosub
- command raisesub
- command failuretext
- command checkfaint
- command criticaltext
- command supereffectivetext
- command checkdestinybond
- command buildopponentrage
- command poisontarget
- command sleeptarget
- command draintarget
- command eatdream
- command burntarget
- command freezetarget
- command paralyzetarget
- command selfdestruct
- command mirrormove
- command statup
- command statdown
- command payday
- command conversion
- command resetstats
- command storeenergy
- command unleashenergy
- command forceswitch
- command endloop
- command flinchtarget
- command ohko
- command recoil
- command mist
- command focusenergy
- command confuse
- command confusetarget
- command heal
- command transform
- command screen
- command poison
- command paralyze
- command substitute
- command rechargenextturn
- command mimic
- command metronome
- command leechseed
- command splash
- command disable
- command cleartext
- command charge
- command checkcharge
- command traptarget
- command effect0x3c
- command rampage
- command checkrampage
- command constantdamage
- command counter
- command encore
- command painsplit
- command snore
- command conversion2
- command lockon
- command sketch
- command defrostopponent
- command sleeptalk
- command destinybond
- command spite
- command falseswipe
- command healbell
- command kingsrock
- command triplekick
- command kickcounter
- command thief
- command arenatrap
- command nightmare
- command defrost
- command curse
- command protect
- command spikes
- command foresight
- command perishsong
- command startsandstorm
- command endure
- command checkcurl
- command rolloutpower
- command effect0x5d
- command furycutter
- command attract
- command happinesspower
- command present
- command damagecalc
- command frustrationpower
- command safeguard
- command checksafeguard
- command getmagnitude
- command batonpass
- command pursuit
- command clearhazards
- command healmorn
- command healday
- command healnite
- command hiddenpower
- command startrain
- command startsun
- command attackup
- command defenseup
- command speedup
- command specialattackup
- command specialdefenseup
- command accuracyup
- command evasionup
- command attackup2
- command defenseup2
- command speedup2
- command specialattackup2
- command specialdefenseup2
- command accuracyup2
- command evasionup2
- command attackdown
- command defensedown
- command speeddown
- command specialattackdown
- command specialdefensedown
- command accuracydown
- command evasiondown
- command attackdown2
- command defensedown2
- command speeddown2
- command specialattackdown2
- command specialdefensedown2
- command accuracydown2
- command evasiondown2
- command statupmessage
- command statdownmessage
- command statupfailtext
- command statdownfailtext
- command effectchance
- command statdownanim
- command statupanim
- command switchturn
- command fakeout
- command bellydrum
- command psychup
- command rage
- command doubleflyingdamage
- command doubleundergrounddamage
- command mirrorcoat
- command checkfuturesight
- command futuresight
- command doubleminimizedamage
- command skipsuncharge
- command thunderaccuracy
- command teleport
- command beatup
- command ragedamage
- command resettypematchup
- command allstatsup
- command effect0xa5
- command raisesubnoanim
- command lowersubnoanim
- command effect0xa8
- command clearmissdamage
- command movedelay
- command hittarget
- command tristatuschance
- command supereffectivelooptext
- command startloop
- command curl
+ command checkturn ; 01
+ command checkobedience ; 02
+ command usedmovetext ; 03
+ command doturn ; 04
+ command critical ; 05
+ command damagestats ; 06
+ command stab ; 07
+ command damagevariation ; 08
+ command checkhit ; 09
+ command lowersub ; 0a
+ command hittargetnosub ; 0b
+ command raisesub ; 0c
+ command failuretext ; 0d
+ command checkfaint ; 0e
+ command criticaltext ; 0f
+ command supereffectivetext ; 10
+ command checkdestinybond ; 11
+ command buildopponentrage ; 12
+ command poisontarget ; 13
+ command sleeptarget ; 14
+ command draintarget ; 15
+ command eatdream ; 16
+ command burntarget ; 17
+ command freezetarget ; 18
+ command paralyzetarget ; 19
+ command selfdestruct ; 1a
+ command mirrormove ; 1b
+ command statup ; 1c
+ command statdown ; 1d
+ command payday ; 1e
+ command conversion ; 1f
+ command resetstats ; 20
+ command storeenergy ; 21
+ command unleashenergy ; 22
+ command forceswitch ; 23
+ command endloop ; 24
+ command flinchtarget ; 25
+ command ohko ; 26
+ command recoil ; 27
+ command mist ; 28
+ command focusenergy ; 29
+ command confuse ; 2a
+ command confusetarget ; 2b
+ command heal ; 2c
+ command transform ; 2d
+ command screen ; 2e
+ command poison ; 2f
+ command paralyze ; 30
+ command substitute ; 31
+ command rechargenextturn ; 32
+ command mimic ; 33
+ command metronome ; 34
+ command leechseed ; 35
+ command splash ; 36
+ command disable ; 37
+ command cleartext ; 38
+ command charge ; 39
+ command checkcharge ; 3a
+ command traptarget ; 3b
+ command effect0x3c ; 3c
+ command rampage ; 3d
+ command checkrampage ; 3e
+ command constantdamage ; 3f
+ command counter ; 40
+ command encore ; 41
+ command painsplit ; 42
+ command snore ; 43
+ command conversion2 ; 44
+ command lockon ; 45
+ command sketch ; 46
+ command defrostopponent ; 47
+ command sleeptalk ; 48
+ command destinybond ; 49
+ command spite ; 4a
+ command falseswipe ; 4b
+ command healbell ; 4c
+ command kingsrock ; 4d
+ command triplekick ; 4e
+ command kickcounter ; 4f
+ command thief ; 50
+ command arenatrap ; 51
+ command nightmare ; 52
+ command defrost ; 53
+ command curse ; 54
+ command protect ; 55
+ command spikes ; 56
+ command foresight ; 57
+ command perishsong ; 58
+ command startsandstorm ; 59
+ command endure ; 5a
+ command checkcurl ; 5b
+ command rolloutpower ; 5c
+ command effect0x5d ; 5d
+ command furycutter ; 5e
+ command attract ; 5f
+ command happinesspower ; 60
+ command present ; 61
+ command damagecalc ; 62
+ command frustrationpower ; 63
+ command safeguard ; 64
+ command checksafeguard ; 65
+ command getmagnitude ; 66
+ command batonpass ; 67
+ command pursuit ; 68
+ command clearhazards ; 69
+ command healmorn ; 6a
+ command healday ; 6b
+ command healnite ; 6c
+ command hiddenpower ; 6d
+ command startrain ; 6e
+ command startsun ; 6f
+ command attackup ; 70
+ command defenseup ; 71
+ command speedup ; 72
+ command specialattackup ; 73
+ command specialdefenseup ; 74
+ command accuracyup ; 75
+ command evasionup ; 76
+ command attackup2 ; 77
+ command defenseup2 ; 78
+ command speedup2 ; 79
+ command specialattackup2 ; 7a
+ command specialdefenseup2 ; 7b
+ command accuracyup2 ; 7c
+ command evasionup2 ; 7d
+ command attackdown ; 7e
+ command defensedown ; 7f
+ command speeddown ; 80
+ command specialattackdown ; 81
+ command specialdefensedown ; 82
+ command accuracydown ; 83
+ command evasiondown ; 84
+ command attackdown2 ; 85
+ command defensedown2 ; 86
+ command speeddown2 ; 87
+ command specialattackdown2 ; 88
+ command specialdefensedown2 ; 89
+ command accuracydown2 ; 8a
+ command evasiondown2 ; 8b
+ command statupmessage ; 8c
+ command statdownmessage ; 8d
+ command statupfailtext ; 8e
+ command statdownfailtext ; 8f
+ command effectchance ; 90
+ command statdownanim ; 91
+ command statupanim ; 92
+ command switchturn ; 93
+ command fakeout ; 94
+ command bellydrum ; 95
+ command psychup ; 96
+ command rage ; 97
+ command doubleflyingdamage ; 98
+ command doubleundergrounddamage ; 99
+ command mirrorcoat ; 9a
+ command checkfuturesight ; 9b
+ command futuresight ; 9c
+ command doubleminimizedamage ; 9d
+ command skipsuncharge ; 9e
+ command thunderaccuracy ; 9f
+ command teleport ; a0
+ command beatup ; a1
+ command ragedamage ; a2
+ command resettypematchup ; a3
+ command allstatsup ; a4
+ command effect0xa5 ; a5
+ command raisesubnoanim ; a6
+ command lowersubnoanim ; a7
+ command effect0xa8 ; a8
+ command clearmissdamage ; a9
+ command movedelay ; aa
+ command hittarget ; ab
+ command tristatuschance ; ac
+ command supereffectivelooptext ; ad
+ command startloop ; ae
+ command curl ; af
enum_start -1, -1
command endmove
diff --git a/macros/movement.asm b/macros/movement.asm
index fd4852e8a..1d3ad42dd 100644
--- a/macros/movement.asm
+++ b/macros/movement.asm
@@ -281,7 +281,15 @@ fast_jump_step_right: macro
db movement_fast_jump_step_right ; $37
endm
-__enum__ = $3a
+ enum movement_remove_sliding
+remove_sliding: macro
+ db movement_remove_sliding ; $38
+ endm
+
+ enum movement_set_sliding
+set_sliding: macro
+ db movement_set_sliding ; $39
+ endm
enum movement_remove_fixed_facing
remove_fixed_facing: macro
diff --git a/macros/sound.asm b/macros/sound.asm
index b5a33994b..64fe309cb 100644
--- a/macros/sound.asm
+++ b/macros/sound.asm
@@ -15,7 +15,7 @@ noise: macro
endm
musicheader: macro
- ; number of tracks, ??, address
+ ; number of tracks, track idx, address
dbw ((\1 - 1) << 6) + (\2 - 1), \3
endm
diff --git a/main.asm b/main.asm
index 8a6b4f9ad..a9668986d 100644
--- a/main.asm
+++ b/main.asm
@@ -238,477 +238,8 @@ INCLUDE "engine/math.asm"
ItemAttributes: ; 67c1
INCLUDE "items/item_attributes.asm"
INCLUDE "engine/npc_movement.asm"
-
-GetFirstPokemonHappiness: ; 718d
- ld hl, PartyMon1Happiness
- ld bc, PARTYMON_STRUCT_LENGTH
- ld de, PartySpecies
-.loop
- ld a, [de]
- cp EGG
- jr nz, .done
- inc de
- add hl, bc
- jr .loop
-
-.done
- ld [wd265], a
- ld a, [hl]
- ld [ScriptVar], a
- call GetPokemonName
- jp CopyPokemonName_Buffer1_Buffer3
-
-CheckFirstMonIsEgg: ; 71ac
- ld a, [PartySpecies]
- ld [wd265], a
- cp EGG
- ld a, $1
- jr z, .egg
- xor a
-
-.egg
- ld [ScriptVar], a
- call GetPokemonName
- jp CopyPokemonName_Buffer1_Buffer3
-
-ChangeHappiness: ; 71c2
-; Perform happiness action c on CurPartyMon
-
- ld a, [CurPartyMon]
- inc a
- ld e, a
- ld d, 0
- ld hl, PartySpecies - 1
- add hl, de
- ld a, [hl]
- cp EGG
- ret z
-
- push bc
- ld hl, PartyMon1Happiness
- ld bc, PARTYMON_STRUCT_LENGTH
- ld a, [CurPartyMon]
- call AddNTimes
- pop bc
-
- ld d, h
- ld e, l
-
- push de
- ld a, [de]
- cp 100
- ld e, 0
- jr c, .ok
- inc e
- cp 200
- jr c, .ok
- inc e
-
-.ok
- dec c
- ld b, 0
- ld hl, .Actions
-rept 3
- add hl, bc
-endr
- ld d, 0
- add hl, de
- ld a, [hl]
- cp 100
- pop de
-
- ld a, [de]
- jr nc, .negative
- add [hl]
- jr nc, .done
- ld a, -1
- jr .done
-
-.negative
- add [hl]
- jr c, .done
- xor a
-
-.done
- ld [de], a
- ld a, [wBattleMode]
- and a
- ret z
- ld a, [CurPartyMon]
- ld b, a
- ld a, [wPartyMenuCursor]
- cp b
- ret nz
- ld a, [de]
- ld [BattleMonHappiness], a
- ret
-
-.Actions
- db +5, +3, +2 ; Gained a level
- db +5, +3, +2 ; Vitamin
- db +1, +1, +0 ; X Item
- db +3, +2, +1 ; Battled a Gym Leader
- db +1, +1, +0 ; Learned a move
- db -1, -1, -1 ; Lost to an enemy
- db -5, -5, -10 ; Fainted due to poison
- db -5, -5, -10 ; Lost to a much stronger enemy
- db +1, +1, +1 ; Haircut (Y1)
- db +3, +3, +1 ; Haircut (Y2)
- db +5, +5, +2 ; Haircut (Y3)
- db +1, +1, +1 ; Haircut (O1)
- db +3, +3, +1 ; Haircut (O2)
- db +10, +10, +4 ; Haircut (O3)
- db -5, -5, -10 ; Used Heal Powder or Energypowder (bitter)
- db -10, -10, -15 ; Used Energy Root (bitter)
- db -15, -15, -20 ; Used Revival Herb (bitter)
- db +3, +3, +1 ; Grooming
- db +10, +6, +4 ; Gained a level in the place where it was caught
-
-StepHappiness:: ; 725a
-; Raise the party's happiness by 1 point every other step cycle.
-
- ld hl, wHappinessStepCount
- ld a, [hl]
- inc a
- and 1
- ld [hl], a
- ret nz
-
- ld de, PartyCount
- ld a, [de]
- and a
- ret z
-
- ld c, a
- ld hl, PartyMon1Happiness
-.loop
- inc de
- ld a, [de]
- cp EGG
- jr z, .next
- inc [hl]
- jr nz, .next
- ld [hl], $ff
-
-.next
- push de
- ld de, PARTYMON_STRUCT_LENGTH
- add hl, de
- pop de
- dec c
- jr nz, .loop
- ret
-
-DaycareStep:: ; 7282
-
- ld a, [wDaycareMan]
- bit 0, a
- jr z, .daycare_lady
-
- ld a, [wBreedMon1Level] ; level
- cp 100
- jr nc, .daycare_lady
- ld hl, wBreedMon1Exp + 2 ; exp
- inc [hl]
- jr nz, .daycare_lady
- dec hl
- inc [hl]
- jr nz, .daycare_lady
- dec hl
- inc [hl]
- ld a, [hl]
- cp 5242880 / $10000
- jr c, .daycare_lady
- ld a, 5242880 / $10000
- ld [hl], a
-
-.daycare_lady
- ld a, [wDaycareLady]
- bit 0, a
- jr z, .check_egg
-
- ld a, [wBreedMon2Level] ; level
- cp 100
- jr nc, .check_egg
- ld hl, wBreedMon2Exp + 2 ; exp
- inc [hl]
- jr nz, .check_egg
- dec hl
- inc [hl]
- jr nz, .check_egg
- dec hl
- inc [hl]
- ld a, [hl]
- cp 5242880 / $10000
- jr c, .check_egg
- ld a, 5242880 / $10000
- ld [hl], a
-
-.check_egg
- ld hl, wDaycareMan
- bit 5, [hl] ; egg
- ret z
- ld hl, wStepsToEgg
- dec [hl]
- ret nz
-
- call Random
- ld [hl], a
- callab CheckBreedmonCompatibility
- ld a, [wd265]
- cp 230
- ld b, -1 + 32 percent
- jr nc, .okay
- ld a, [wd265]
- cp 170
- ld b, 16 percent
- jr nc, .okay
- ld a, [wd265]
- cp 110
- ld b, 12 percent
- jr nc, .okay
- ld b, 4 percent
-
-.okay
- call Random
- cp b
- ret nc
- ld hl, wDaycareMan
- res 5, [hl]
- set 6, [hl]
- ret
-
-SpecialGiveShuckle: ; 7305
-
-; Adding to the party.
- xor a
- ld [MonType], a
-
-; Level 15 Shuckle.
- ld a, SHUCKLE
- ld [CurPartySpecies], a
- ld a, 15
- ld [CurPartyLevel], a
-
- predef TryAddMonToParty
- jr nc, .NotGiven
-
-; Caught data.
- ld b, 0
- callba SetGiftPartyMonCaughtData
-
-; Holding a Berry.
- ld bc, PARTYMON_STRUCT_LENGTH
- ld a, [PartyCount]
- dec a
- push af
- push bc
- ld hl, PartyMon1Item
- call AddNTimes
- ld [hl], BERRY
- pop bc
- pop af
-
-; OT ID.
- ld hl, PartyMon1ID
- call AddNTimes
- ld a, $2
- ld [hli], a
- ld [hl], $6
-
-; Nickname.
- ld a, [PartyCount]
- dec a
- ld hl, PartyMonNicknames
- call SkipNames
- ld de, SpecialShuckleNick
- call CopyName2
-
-; OT.
- ld a, [PartyCount]
- dec a
- ld hl, PartyMonOT
- call SkipNames
- ld de, SpecialShuckleOT
- call CopyName2
-
-; Engine flag for this event.
- ld hl, DailyFlags
- set 5, [hl]
-; setflag ENGINE_SHUCKLE_GIVEN
- ld a, 1
- ld [ScriptVar], a
- ret
-
-.NotGiven
- xor a
- ld [ScriptVar], a
- ret
-
-SpecialShuckleOT:
- db "MANIA@"
-SpecialShuckleNick:
- db "SHUCKIE@"
-
-SpecialReturnShuckle: ; 737e
- callba SelectMonFromParty
- jr c, .refused
-
- ld a, [CurPartySpecies]
- cp SHUCKLE
- jr nz, .DontReturn
-
- ld a, [CurPartyMon]
- ld hl, PartyMon1ID
- ld bc, PARTYMON_STRUCT_LENGTH
- call AddNTimes
-
-; OT ID
- ld a, [hli]
- cp 00518 / $100
- jr nz, .DontReturn
- ld a, [hl]
- cp 00518 % $100
- jr nz, .DontReturn
-
-; OT
- ld a, [CurPartyMon]
- ld hl, PartyMonOT
- call SkipNames
- ld de, SpecialShuckleOT
-.CheckOT
- ld a, [de]
- cp [hl]
- jr nz, .DontReturn
- cp "@"
- jr z, .done
- inc de
- inc hl
- jr .CheckOT
-
-.done
- callba CheckCurPartyMonFainted
- jr c, .fainted
- ld a, [CurPartyMon]
- ld hl, PartyMon1Happiness
- ld bc, PARTYMON_STRUCT_LENGTH
- call AddNTimes
- ld a, [hl]
- cp 150
- ld a, $3
- jr nc, .HappyToStayWithYou
- xor a ; take from pc
- ld [wPokemonWithdrawDepositParameter], a
- callab RemoveMonFromPartyOrBox
- ld a, $2
-.HappyToStayWithYou
- ld [ScriptVar], a
- ret
-
-.refused
- ld a, $1
- ld [ScriptVar], a
- ret
-
-.DontReturn
- xor a
- ld [ScriptVar], a
- ret
-
-.fainted
- ld a, $4
- ld [ScriptVar], a
- ret
-
-Special_BillsGrandfather: ; 73f7
- callba SelectMonFromParty
- jr c, .cancel
- ld a, [CurPartySpecies]
- ld [ScriptVar], a
- ld [wNamedObjectIndexBuffer], a
- call GetPokemonName
- jp CopyPokemonName_Buffer1_Buffer3
-
-.cancel
- xor a
- ld [ScriptVar], a
- ret
-
-Special_YoungerHaircutBrother: ; 7413
- ld hl, Data_YoungerHaircutBrother
- jr MassageOrHaircut
-
-Special_OlderHaircutBrother: ; 7418
- ld hl, Data_OlderHaircutBrother
- jr MassageOrHaircut
-
-Special_DaisyMassage: ; 741d
- ld hl, Data_DaisyMassage
-
-MassageOrHaircut: ; 7420
- push hl
- callba SelectMonFromParty
- pop hl
- jr c, .nope
- ld a, [CurPartySpecies]
- cp EGG
- jr z, .egg
- push hl
- call GetCurNick
- call CopyPokemonName_Buffer1_Buffer3
- pop hl
- call Random
-; Bug: Subtracting $ff from $ff fails to set c.
-; This can result in overflow into the next data array.
-; In the case of getting a massage from Daisy, we bleed
-; into CopyPokemonName_Buffer1_Buffer3, which passes
-; $d0 to ChangeHappiness and returns $73 to the script.
-; The end result is that there is a 0.4% chance your
-; Pokemon's happiness will not change at all.
-.loop
- sub [hl]
- jr c, .ok
-rept 3
- inc hl
-endr
- jr .loop
-
-.ok
- inc hl
- ld a, [hli]
- ld [ScriptVar], a
- ld c, [hl]
- call ChangeHappiness
- ret
-
-.nope
- xor a
- ld [ScriptVar], a
- ret
-
-.egg
- ld a, 1
- ld [ScriptVar], a
- ret
-
-Data_YoungerHaircutBrother: ; 7459
- db $4c, 2, HAPPINESS_YOUNGCUT1 ; 30% chance
- db $80, 3, HAPPINESS_YOUNGCUT2 ; 20% chance
- db $ff, 4, HAPPINESS_YOUNGCUT3 ; 50% chance
-
-Data_OlderHaircutBrother: ; 7462
- db $9a, 2, HAPPINESS_OLDERCUT1 ; 60% chance
- db $4c, 3, HAPPINESS_OLDERCUT2 ; 10% chance
- db $ff, 4, HAPPINESS_OLDERCUT3 ; 30% chance
-
-Data_DaisyMassage: ; 746b
- db $ff, 2, HAPPINESS_MASSAGE ; 99.6% chance
-
-CopyPokemonName_Buffer1_Buffer3: ; 746e
- ld hl, StringBuffer1
- ld de, StringBuffer3
- ld bc, PKMN_NAME_LENGTH
- jp CopyBytes
+INCLUDE "event/happiness_egg.asm"
+INCLUDE "event/special.asm"
Predef1: ; 747a
; not used
@@ -716,916 +247,9 @@ Predef1: ; 747a
SECTION "bank2", ROMX, BANK[$2]
-BlankScreen: ; 8000
- call DisableSpriteUpdates
- xor a
- ld [hBGMapMode], a
- call ClearBGPalettes
- call ClearSprites
- hlcoord 0, 0
- ld bc, TileMapEnd - TileMap
- ld a, " "
- call ByteFill
- hlcoord 0, 0, AttrMap
- ld bc, AttrMapEnd - AttrMap
- ld a, $7
- call ByteFill
- call WaitBGMap2
- call SetPalettes
- ret
-
-SpawnPlayer: ; 8029
- ld a, -1
- ld [wObjectFollow_Leader], a
- ld [wObjectFollow_Follower], a
- ld a, $0
- ld hl, PlayerObjectTemplate
- call CopyPlayerObjectTemplate
- ld b, $0
- call PlayerSpawn_ConvertCoords
- ld a, $0
- call GetMapObject
- ld hl, MAPOBJECT_COLOR
- add hl, bc
- ln e, (1 << 3) | PAL_OW_RED, PERSONTYPE_SCRIPT
- ld a, [wPlayerSpriteSetupFlags]
- bit 2, a
- jr nz, .ok
- ld a, [PlayerGender]
- bit 0, a
- jr z, .ok
- ln e, (1 << 3) | PAL_OW_BLUE, PERSONTYPE_SCRIPT
-
-.ok
- ld [hl], e
- ld a, $0
- ld [hMapObjectIndexBuffer], a
- ld bc, MapObjects
- ld a, $0
- ld [hObjectStructIndexBuffer], a
- ld de, ObjectStructs
- call CopyMapObjectToObjectStruct
- ld a, PLAYER
- ld [wCenteredObject], a
- ret
-
-PlayerObjectTemplate: ; 8071
-; A dummy map object used to initialize the player object.
-; Shorter than the actual amount copied by two bytes.
-; Said bytes seem to be unused.
- person_event SPRITE_CHRIS, -4, -4, SPRITEMOVEDATA_PLAYER, 15, 15, -1, -1, 0, PERSONTYPE_SCRIPT, 0, 0, -1
-
-CopyDECoordsToMapObject:: ; 807e
- push de
- ld a, b
- call GetMapObject
- pop de
- ld hl, MAPOBJECT_X_COORD
- add hl, bc
- ld [hl], d
- ld hl, MAPOBJECT_Y_COORD
- add hl, bc
- ld [hl], e
- ret
-
-PlayerSpawn_ConvertCoords: ; 808f
- push bc
- ld a, [XCoord]
- add 4
- ld d, a
- ld a, [YCoord]
- add 4
- ld e, a
- pop bc
- call CopyDECoordsToMapObject
- ret
-
-WritePersonXY:: ; 80a1
- ld a, b
- call CheckObjectVisibility
- ret c
-
- ld hl, OBJECT_NEXT_MAP_X
- add hl, bc
- ld d, [hl]
- ld hl, OBJECT_NEXT_MAP_Y
- add hl, bc
- ld e, [hl]
- ld a, [hMapObjectIndexBuffer]
- ld b, a
- call CopyDECoordsToMapObject
- and a
- ret
-
-RefreshPlayerCoords: ; 80b8
- ld a, [XCoord]
- add 4
- ld d, a
- ld hl, PlayerStandingMapX
- sub [hl]
- ld [hl], d
- ld hl, MapObjects + MAPOBJECT_X_COORD
- ld [hl], d
- ld hl, PlayerLastMapX
- ld [hl], d
- ld d, a
- ld a, [YCoord]
- add 4
- ld e, a
- ld hl, PlayerStandingMapY
- sub [hl]
- ld [hl], e
- ld hl, MapObjects + MAPOBJECT_Y_COORD
- ld [hl], e
- ld hl, PlayerLastMapY
- ld [hl], e
- ld e, a
- ld a, [wObjectFollow_Leader]
- cp $0
- ret nz ; wtf
- ret
-
-CopyObjectStruct:: ; 80e7
- call CheckObjectMask
- and a
- ret nz ; masked
-
- ld hl, ObjectStructs + OBJECT_STRUCT_LENGTH * 1
- ld a, 1
- ld de, OBJECT_STRUCT_LENGTH
-.loop
- ld [hObjectStructIndexBuffer], a
- ld a, [hl]
- and a
- jr z, .done
- add hl, de
- ld a, [hObjectStructIndexBuffer]
- inc a
- cp NUM_OBJECT_STRUCTS
- jr nz, .loop
- scf
- ret ; overflow
-
-.done
- ld d, h
- ld e, l
- call CopyMapObjectToObjectStruct
- ld hl, VramState
- bit 7, [hl]
- ret z
-
- ld hl, OBJECT_FLAGS2
- add hl, de
- set 5, [hl]
- ret
-
-CopyMapObjectToObjectStruct: ; 8116
- call .CopyMapObjectToTempObject
- call CopyTempObjectToObjectStruct
- ret
-
-.CopyMapObjectToTempObject: ; 811d
- ld a, [hObjectStructIndexBuffer]
- ld hl, MAPOBJECT_OBJECT_STRUCT_ID
- add hl, bc
- ld [hl], a
-
- ld a, [hMapObjectIndexBuffer]
- ld [wTempObjectCopyMapObjectIndex], a
-
- ld hl, MAPOBJECT_SPRITE
- add hl, bc
- ld a, [hl]
- ld [wTempObjectCopySprite], a
-
- call GetSpriteVTile
- ld [wTempObjectCopySpriteVTile], a
-
- ld a, [hl]
- call GetSpritePalette
- ld [wTempObjectCopyPalette], a
-
- ld hl, MAPOBJECT_COLOR
- add hl, bc
- ld a, [hl]
- and $f0
- jr z, .skip_color_override
- swap a
- and $7 ; OAM_PALETTE
- ld [wTempObjectCopyPalette], a
-
-.skip_color_override
- ld hl, MAPOBJECT_MOVEMENT
- add hl, bc
- ld a, [hl]
- ld [wTempObjectCopyMovement], a
-
- ld hl, MAPOBJECT_RANGE
- add hl, bc
- ld a, [hl]
- ld [wTempObjectCopyRange], a
-
- ld hl, MAPOBJECT_X_COORD
- add hl, bc
- ld a, [hl]
- ld [wTempObjectCopyX], a
-
- ld hl, MAPOBJECT_Y_COORD
- add hl, bc
- ld a, [hl]
- ld [wTempObjectCopyY], a
-
- ld hl, MAPOBJECT_RADIUS
- add hl, bc
- ld a, [hl]
- ld [wTempObjectCopyRadius], a
- ret
-
-InitializeVisibleSprites: ; 8177
- ld bc, MapObjects + OBJECT_LENGTH
- ld a, 1
-.loop
- ld [hMapObjectIndexBuffer], a
- ld hl, MAPOBJECT_SPRITE
- add hl, bc
- ld a, [hl]
- and a
- jr z, .next
-
- ld hl, MAPOBJECT_OBJECT_STRUCT_ID
- add hl, bc
- ld a, [hl]
- cp -1
- jr nz, .next
-
- ld a, [XCoord]
- ld d, a
- ld a, [YCoord]
- ld e, a
-
- ld hl, MAPOBJECT_X_COORD
- add hl, bc
- ld a, [hl]
- add 1
- sub d
- jr c, .next
-
- cp MAPOBJECT_SCREEN_WIDTH
- jr nc, .next
-
- ld hl, MAPOBJECT_Y_COORD
- add hl, bc
- ld a, [hl]
- add 1
- sub e
- jr c, .next
-
- cp MAPOBJECT_SCREEN_HEIGHT
- jr nc, .next
-
- push bc
- call CopyObjectStruct
- pop bc
- jp c, .ret
-
-.next
- ld hl, OBJECT_LENGTH
- add hl, bc
- ld b, h
- ld c, l
- ld a, [hMapObjectIndexBuffer]
- inc a
- cp NUM_OBJECTS
- jr nz, .loop
- ret
-
-.ret: ; 81c9
- ret
-
-CheckObjectEnteringVisibleRange:: ; 81ca
- nop
- ld a, [wPlayerStepDirection]
- cp STANDING
- ret z
- ld hl, .dw
- rst JumpTable
- ret
-
-.dw: ; 81d6
- dw .Down
- dw .Up
- dw .Left
- dw .Right
-
-.Up: ; 81de
- ld a, [YCoord]
- sub 1
- jr .Vertical
-
-.Down: ; 81e5
- ld a, [YCoord]
- add 9
-.Vertical: ; 81ea
- ld d, a
- ld a, [XCoord]
- ld e, a
- ld bc, MapObjects + OBJECT_LENGTH
- ld a, 1
-.loop_v
- ld [hMapObjectIndexBuffer], a
- ld hl, MAPOBJECT_SPRITE
- add hl, bc
- ld a, [hl]
- and a
- jr z, .next_v
- ld hl, MAPOBJECT_Y_COORD
- add hl, bc
- ld a, d
- cp [hl]
- jr nz, .next_v
- ld hl, MAPOBJECT_OBJECT_STRUCT_ID
- add hl, bc
- ld a, [hl]
- cp -1
- jr nz, .next_v
- ld hl, MAPOBJECT_X_COORD
- add hl, bc
- ld a, [hl]
- add 1
- sub e
- jr c, .next_v
- cp MAPOBJECT_SCREEN_WIDTH
- jr nc, .next_v
- push de
- push bc
- call CopyObjectStruct
- pop bc
- pop de
-
-.next_v
- ld hl, OBJECT_LENGTH
- add hl, bc
- ld b, h
- ld c, l
- ld a, [hMapObjectIndexBuffer]
- inc a
- cp NUM_OBJECTS
- jr nz, .loop_v
- ret
-
-.Left: ; 8232
- ld a, [XCoord]
- sub 1
- jr .Horizontal
-
-.Right: ; 8239
- ld a, [XCoord]
- add 10
-.Horizontal: ; 823e
- ld e, a
- ld a, [YCoord]
- ld d, a
- ld bc, MapObjects + OBJECT_LENGTH
- ld a, 1
-.loop_h
- ld [hMapObjectIndexBuffer], a
- ld hl, MAPOBJECT_SPRITE
- add hl, bc
- ld a, [hl]
- and a
- jr z, .next_h
- ld hl, MAPOBJECT_X_COORD
- add hl, bc
- ld a, e
- cp [hl]
- jr nz, .next_h
- ld hl, MAPOBJECT_OBJECT_STRUCT_ID
- add hl, bc
- ld a, [hl]
- cp -1
- jr nz, .next_h
- ld hl, MAPOBJECT_Y_COORD
- add hl, bc
- ld a, [hl]
- add 1
- sub d
- jr c, .next_h
- cp MAPOBJECT_SCREEN_HEIGHT
- jr nc, .next_h
- push de
- push bc
- call CopyObjectStruct
- pop bc
- pop de
-
-.next_h
- ld hl, OBJECT_LENGTH
- add hl, bc
- ld b, h
- ld c, l
- ld a, [hMapObjectIndexBuffer]
- inc a
- cp NUM_OBJECTS
- jr nz, .loop_h
- ret
-
-CopyTempObjectToObjectStruct: ; 8286
- ld a, [wTempObjectCopyMapObjectIndex]
- ld hl, OBJECT_MAP_OBJECT_INDEX
- add hl, de
- ld [hl], a
-
- ld a, [wTempObjectCopyMovement]
- call CopySpriteMovementData
-
- ld a, [wTempObjectCopyPalette]
- ld hl, OBJECT_PALETTE
- add hl, de
- or [hl]
- ld [hl], a
-
- ld a, [wTempObjectCopyY]
- call .InitYCoord
-
- ld a, [wTempObjectCopyX]
- call .InitXCoord
-
- ld a, [wTempObjectCopySprite]
- ld hl, OBJECT_SPRITE
- add hl, de
- ld [hl], a
-
- ld a, [wTempObjectCopySpriteVTile]
- ld hl, OBJECT_SPRITE_TILE
- add hl, de
- ld [hl], a
-
- ld hl, OBJECT_STEP_TYPE
- add hl, de
- ld [hl], STEP_TYPE_00
-
- ld hl, OBJECT_FACING_STEP
- add hl, de
- ld [hl], STANDING
-
- ld a, [wTempObjectCopyRadius]
- call .InitRadius
-
- ld a, [wTempObjectCopyRange]
- ld hl, OBJECT_RANGE
- add hl, de
- ld [hl], a
-
- and a
- ret
-
-.InitYCoord: ; 82d5
- ld hl, OBJECT_INIT_Y
- add hl, de
- ld [hl], a
-
- ld hl, OBJECT_NEXT_MAP_Y
- add hl, de
- ld [hl], a
-
- ld hl, YCoord
- sub [hl]
- and $f
- swap a
- ld hl, wFollowNotExactPersonY
- sub [hl]
- ld hl, OBJECT_SPRITE_Y
- add hl, de
- ld [hl], a
- ret
-
-.InitXCoord: ; 82f1
- ld hl, OBJECT_INIT_X
- add hl, de
- ld [hl], a
- ld hl, OBJECT_NEXT_MAP_X
- add hl, de
- ld [hl], a
- ld hl, XCoord
- sub [hl]
- and $f
- swap a
- ld hl, wFollowNotExactPersonX
- sub [hl]
- ld hl, OBJECT_SPRITE_X
- add hl, de
- ld [hl], a
- ret
-
-.InitRadius: ; 830d
- ld h, a
- inc a
- and $f
- ld l, a
- ld a, h
- add $10
- and $f0
- or l
- ld hl, OBJECT_RADIUS
- add hl, de
- ld [hl], a
- ret
-
-TrainerWalkToPlayer: ; 831e
- ld a, [hLastTalked]
- call InitMovementBuffer
- ld a, movement_step_sleep_1
- call AppendToMovementBuffer
- ld a, [wd03f]
- dec a
- jr z, .TerminateStep
- ld a, [hLastTalked]
- ld b, a
- ld c, PLAYER
- ld d, 1
- call .GetPathToPlayer
- call DecrementMovementBufferCount
-
-.TerminateStep
- ld a, movement_step_end
- call AppendToMovementBuffer
- ret
-
-.GetPathToPlayer: ; 8341
- push de
- push bc
-; get player object struct, load to de
- ld a, c
- call GetMapObject
- ld hl, MAPOBJECT_OBJECT_STRUCT_ID
- add hl, bc
- ld a, [hl]
- call GetObjectStruct
- ld d, b
- ld e, c
-
-; get last talked object struct, load to bc
- pop bc
- ld a, b
- call GetMapObject
- ld hl, MAPOBJECT_OBJECT_STRUCT_ID
- add hl, bc
- ld a, [hl]
- call GetObjectStruct
-
-; get last talked coords, load to bc
- ld hl, OBJECT_NEXT_MAP_X
- add hl, bc
- ld a, [hl]
- ld hl, OBJECT_NEXT_MAP_Y
- add hl, bc
- ld c, [hl]
- ld b, a
-
-; get player coords, load to de
- ld hl, OBJECT_NEXT_MAP_X
- add hl, de
- ld a, [hl]
- ld hl, OBJECT_NEXT_MAP_Y
- add hl, de
- ld e, [hl]
- ld d, a
-
- pop af
- call ComputePathToWalkToPlayer
- ret
-
-Special_SurfStartStep: ; 8379
- call InitMovementBuffer
- call .GetMovementData
- call AppendToMovementBuffer
- ld a, movement_step_end
- call AppendToMovementBuffer
- ret
-
-.GetMovementData: ; 8388
- ld a, [PlayerDirection]
- srl a
- srl a
- and 3
- ld e, a
- ld d, 0
- ld hl, .movement_data
- add hl, de
- ld a, [hl]
- ret
-
-.movement_data
- slow_step_down
- slow_step_up
- slow_step_left
- slow_step_right
-
-FollowNotExact:: ; 839e
- push bc
- ld a, c
- call CheckObjectVisibility
- ld d, b
- ld e, c
- pop bc
- ret c
-
- ld a, b
- call CheckObjectVisibility
- ret c
-
-; Person 2 is now in bc, person 1 is now in de
- ld hl, OBJECT_NEXT_MAP_X
- add hl, bc
- ld a, [hl]
- ld hl, OBJECT_NEXT_MAP_Y
- add hl, bc
- ld c, [hl]
- ld b, a
-
- ld hl, OBJECT_NEXT_MAP_X
- add hl, de
- ld a, [hl]
- cp b
- jr z, .same_x
- jr c, .to_the_left
- inc b
- jr .continue
-
-.to_the_left
- dec b
- jr .continue
-
-.same_x
- ld hl, OBJECT_NEXT_MAP_Y
- add hl, de
- ld a, [hl]
- cp c
- jr z, .continue
- jr c, .below
- inc c
- jr .continue
-
-.below
- dec c
-
-.continue
- ld hl, OBJECT_NEXT_MAP_X
- add hl, de
- ld [hl], b
- ld a, b
- ld hl, XCoord
- sub [hl]
- and $f
- swap a
- ld hl, wFollowNotExactPersonX
- sub [hl]
- ld hl, OBJECT_SPRITE_X
- add hl, de
- ld [hl], a
- ld hl, OBJECT_NEXT_MAP_Y
- add hl, de
- ld [hl], c
- ld a, c
- ld hl, YCoord
- sub [hl]
- and $f
- swap a
- ld hl, wFollowNotExactPersonY
- sub [hl]
- ld hl, OBJECT_SPRITE_Y
- add hl, de
- ld [hl], a
- ld a, [hObjectStructIndexBuffer]
- ld hl, OBJECT_RANGE
- add hl, de
- ld [hl], a
- ld hl, OBJECT_MOVEMENTTYPE
- add hl, de
- ld [hl], SPRITEMOVEDATA_FOLLOWNOTEXACT
- ld hl, OBJECT_STEP_TYPE
- add hl, de
- ld [hl], STEP_TYPE_00
- ret
-
-GetRelativeFacing:: ; 8417
-; Determines which way map object e would have to turn to face map object d. Returns carry if it's impossible for whatever reason.
- ld a, d
- call GetMapObject
- ld hl, MAPOBJECT_OBJECT_STRUCT_ID
- add hl, bc
- ld a, [hl]
- cp NUM_OBJECT_STRUCTS
- jr nc, .carry
- ld d, a
- ld a, e
- call GetMapObject
- ld hl, MAPOBJECT_OBJECT_STRUCT_ID
- add hl, bc
- ld a, [hl]
- cp NUM_OBJECT_STRUCTS
- jr nc, .carry
- ld e, a
- call .GetFacing_e_relativeto_d
- ret
-
-.carry
- scf
- ret
-
-.GetFacing_e_relativeto_d: ; 8439
-; Determines which way object e would have to turn to face object d. Returns carry if it's impossible.
-; load the coordinates of object d into bc
- ld a, d
- call GetObjectStruct
- ld hl, OBJECT_NEXT_MAP_X
- add hl, bc
- ld a, [hl]
- ld hl, OBJECT_NEXT_MAP_Y
- add hl, bc
- ld c, [hl]
- ld b, a
- push bc
-; load the coordinates of object e into de
- ld a, e
- call GetObjectStruct
- ld hl, OBJECT_NEXT_MAP_X
- add hl, bc
- ld d, [hl]
- ld hl, OBJECT_NEXT_MAP_Y
- add hl, bc
- ld e, [hl]
- pop bc
-; |x1 - x2|
- ld a, b
- sub d
- jr z, .same_x_1
- jr nc, .b_right_of_d_1
- cpl
- inc a
-
-.b_right_of_d_1
-; |y1 - y2|
- ld h, a
- ld a, c
- sub e
- jr z, .same_y_1
- jr nc, .c_below_e_1
- cpl
- inc a
-
-.c_below_e_1
-; |y1 - y2| - |x1 - x2|
- sub h
- jr c, .same_y_1
-
-.same_x_1
-; compare the y coordinates
- ld a, c
- cp e
- jr z, .same_x_and_y
- jr c, .c_directly_below_e
-; c directly above e
- ld d, DOWN
- and a
- ret
-
-.c_directly_below_e
- ld d, UP
- and a
- ret
-
-.same_y_1
- ld a, b
- cp d
- jr z, .same_x_and_y
- jr c, .b_directly_right_of_d
-; b directly left of d
- ld d, RIGHT
- and a
- ret
-
-.b_directly_right_of_d
- ld d, LEFT
- and a
- ret
-
-.same_x_and_y
- scf
- ret
-
-QueueFollowerFirstStep: ; 848a
- call .QueueFirstStep
- jr c, .same
- ld [wFollowMovementQueue], a
- xor a
- ld [wFollowerMovementQueueLength], a
- ret
-
-.same
- ld a, -1
- ld [wFollowerMovementQueueLength], a
- ret
-
-.QueueFirstStep
- ld a, [wObjectFollow_Leader]
- call GetObjectStruct
- ld hl, OBJECT_NEXT_MAP_X
- add hl, bc
- ld d, [hl]
- ld hl, OBJECT_NEXT_MAP_Y
- add hl, bc
- ld e, [hl]
- ld a, [wObjectFollow_Follower]
- call GetObjectStruct
- ld hl, OBJECT_NEXT_MAP_X
- add hl, bc
- ld a, d
- cp [hl]
- jr z, .check_y
- jr c, .left
- and a
- ld a, movement_step_right
- ret
-
-.left
- and a
- ld a, movement_step_left
- ret
-
-.check_y
- ld hl, OBJECT_NEXT_MAP_Y
- add hl, bc
- ld a, e
- cp [hl]
- jr z, .same_xy
- jr c, .up
- and a
- ld a, movement_step_down
- ret
-
-.up
- and a
- ld a, movement_step_up
- ret
-
-.same_xy
- scf
- ret
-
-_Sine:: ; 84d9
-; A simple sine function.
-; Return d * sin(e) in hl.
-
-; e is a signed 6-bit value.
- ld a, e
- and %111111
- cp %100000
- jr nc, .negative
-
- call .ApplySineWave
- ld a, h
- ret
-
-.negative
- and %011111
- call .ApplySineWave
- ld a, h
- xor -1
- inc a
- ret
-
-.ApplySineWave: ; 84ef
- ld e, a
- ld a, d
- ld d, 0
- ld hl, .sinewave
- add hl, de
- add hl, de
- ld e, [hl]
- inc hl
- ld d, [hl]
- ld hl, 0
-
-; Factor amplitude
-.multiply
- srl a
- jr nc, .even
- add hl, de
-.even
- sla e
- rl d
- and a
- jr nz, .multiply
- ret
-
-.sinewave: ; 850b
-; A $20-word table representing a sine wave.
-; 90 degrees is index $10 at a base amplitude of $100.
- sine_wave $100
-
+INCLUDE "engine/player_object.asm"
+INCLUDE "engine/sine.asm"
INCLUDE "engine/predef.asm"
-
INCLUDE "engine/color.asm"
SECTION "bank3", ROMX, BANK[$3]
@@ -1651,3287 +275,14 @@ TimeOfDayTable: ; c012
db -1
INCLUDE "engine/specials.asm"
-
-_PrintNum:: ; c4c7
-; Print c digits of the b-byte value from de to hl.
-; Allows 2 to 7 digits. For 1-digit numbers, add
-; the value to char "0" instead of calling PrintNum.
-; Some extra flags can be given in bits 5-7 of b.
-; Bit 5: money if set (unless left-aligned without leading zeros)
-; Bit 6: right-aligned if set
-; Bit 7: print leading zeros if set
-
- push bc
-
- bit 5, b
- jr z, .main
- bit 7, b
- jr nz, .moneyflag
- bit 6, b
- jr z, .main
-
-.moneyflag ; 101xxxxx or 011xxxxx
- ld a, "¥"
- ld [hli], a
- res 5, b ; 100xxxxx or 010xxxxx
-
-.main
- xor a
- ld [hPrintNum1], a
- ld [hPrintNum2], a
- ld [hPrintNum3], a
- ld a, b
- and $f
- cp 1
- jr z, .byte
- cp 2
- jr z, .word
-; maximum 3 bytes
-.long
- ld a, [de]
- ld [hPrintNum2], a
- inc de
- ld a, [de]
- ld [hPrintNum3], a
- inc de
- ld a, [de]
- ld [hPrintNum4], a
- jr .start
-
-.word
- ld a, [de]
- ld [hPrintNum3], a
- inc de
- ld a, [de]
- ld [hPrintNum4], a
- jr .start
-
-.byte
- ld a, [de]
- ld [hPrintNum4], a
-
-.start
- push de
-
- ld d, b
- ld a, c
- swap a
- and $f
- ld e, a
- ld a, c
- and $f
- ld b, a
- ld c, 0
- cp 2
- jr z, .two
- cp 3
- jr z, .three
- cp 4
- jr z, .four
- cp 5
- jr z, .five
- cp 6
- jr z, .six
-
-.seven
- ld a, 1000000 / $10000 % $100
- ld [hPrintNum5], a
- ld a, 1000000 / $100 % $100
- ld [hPrintNum6], a
- ld a, 1000000 % $100
- ld [hPrintNum7], a
- call .PrintDigit
- call .AdvancePointer
-
-.six
- ld a, 100000 / $10000 % $100
- ld [hPrintNum5], a
- ld a, 100000 / $100 % $100
- ld [hPrintNum6], a
- ld a, 100000 % $100
- ld [hPrintNum7], a
- call .PrintDigit
- call .AdvancePointer
-
-.five
- xor a
- ld [hPrintNum5], a
- ld a, 10000 / $100
- ld [hPrintNum6], a
- ld a, 10000 % $100
- ld [hPrintNum7], a
- call .PrintDigit
- call .AdvancePointer
-
-.four
- xor a
- ld [hPrintNum5], a
- ld a, 1000 / $100
- ld [hPrintNum6], a
- ld a, 1000 % $100
- ld [hPrintNum7], a
- call .PrintDigit
- call .AdvancePointer
-
-.three
- xor a
- ld [hPrintNum5], a
- xor a
- ld [hPrintNum6], a
- ld a, 100
- ld [hPrintNum7], a
- call .PrintDigit
- call .AdvancePointer
-
-.two
- dec e
- jr nz, .two_skip
- ld a, "0"
- ld [hPrintNum1], a
-.two_skip
-
- ld c, 0
- ld a, [hPrintNum4]
-.mod_10
- cp 10
- jr c, .modded_10
- sub 10
- inc c
- jr .mod_10
-.modded_10
-
- ld b, a
- ld a, [hPrintNum1]
- or c
- jr nz, .money
- call .PrintLeadingZero
- jr .money_leading_zero
-
-.money
- call .PrintYen
- push af
- ld a, "0"
- add c
- ld [hl], a
- pop af
- ld [hPrintNum1], a
- inc e
- dec e
- jr nz, .money_leading_zero
- inc hl
- ld [hl], $f2 ; XXX
-
-.money_leading_zero
- call .AdvancePointer
- call .PrintYen
- ld a, "0"
- add b
- ld [hli], a
-
- pop de
- pop bc
- ret
-
-.PrintYen: ; c5ba
- push af
- ld a, [hPrintNum1]
- and a
- jr nz, .stop
- bit 5, d
- jr z, .stop
- ld a, "¥"
- ld [hli], a
- res 5, d
-
-.stop
- pop af
- ret
-
-.PrintDigit: ; c5cb (3:45cb)
- dec e
- jr nz, .ok
- ld a, "0"
- ld [hPrintNum1], a
-.ok
- ld c, 0
-.loop
- ld a, [hPrintNum5]
- ld b, a
- ld a, [hPrintNum2]
- ld [hPrintNum8], a
- cp b
- jr c, .skip1
- sub b
- ld [hPrintNum2], a
- ld a, [hPrintNum6]
- ld b, a
- ld a, [hPrintNum3]
- ld [hPrintNum9], a
- cp b
- jr nc, .skip2
- ld a, [hPrintNum2]
- or 0
- jr z, .skip3
- dec a
- ld [hPrintNum2], a
- ld a, [hPrintNum3]
-.skip2
- sub b
- ld [hPrintNum3], a
- ld a, [hPrintNum7]
- ld b, a
- ld a, [hPrintNum4]
- ld [hPrintNum10], a
- cp b
- jr nc, .skip4
- ld a, [hPrintNum3]
- and a
- jr nz, .skip5
- ld a, [hPrintNum2]
- and a
- jr z, .skip6
- dec a
- ld [hPrintNum2], a
- xor a
-.skip5
- dec a
- ld [hPrintNum3], a
- ld a, [hPrintNum4]
-.skip4
- sub b
- ld [hPrintNum4], a
- inc c
- jr .loop
-.skip6
- ld a, [hPrintNum9]
- ld [hPrintNum3], a
-.skip3
- ld a, [hPrintNum8]
- ld [hPrintNum2], a
-.skip1
- ld a, [hPrintNum1]
- or c
- jr z, .PrintLeadingZero
- ld a, [hPrintNum1]
- and a
- jr nz, .done
- bit 5, d
- jr z, .done
- ld a, "¥"
- ld [hli], a
- res 5, d
-.done
- ld a, "0"
- add c
- ld [hl], a
- ld [hPrintNum1], a
- inc e
- dec e
- ret nz
- inc hl
- ld [hl], "·"
- ret
-
-.PrintLeadingZero: ; c644
-; prints a leading zero unless they are turned off in the flags
- bit 7, d ; print leading zeroes?
- ret z
- ld [hl], "0"
- ret
-
-.AdvancePointer: ; c64a
-; increments the pointer unless leading zeroes are not being printed,
-; the number is left-aligned, and no nonzero digits have been printed yet
- bit 7, d ; print leading zeroes?
- jr nz, .inc
- bit 6, d ; left alignment or right alignment?
- jr z, .inc
- ld a, [hPrintNum1]
- and a
- ret z
-.inc
- inc hl
- ret
-
-HealParty: ; c658
- xor a
- ld [CurPartyMon], a
- ld hl, PartySpecies
-.loop
- ld a, [hli]
- cp -1
- jr z, .done
- cp EGG
- jr z, .next
-
- push hl
- call HealPartyMon
- pop hl
-
-.next
- ld a, [CurPartyMon]
- inc a
- ld [CurPartyMon], a
- jr .loop
-
-.done
- ret
-
-HealPartyMon: ; c677
- ld a, MON_SPECIES
- call GetPartyParamLocation
- ld d, h
- ld e, l
-
- ld hl, MON_STATUS
- add hl, de
- xor a
- ld [hli], a
- ld [hl], a
-
- ld hl, MON_MAXHP
- add hl, de
-
- ; bc = MON_HP
- ld b, h
- ld c, l
- dec bc
- dec bc
-
- ld a, [hli]
- ld [bc], a
- inc bc
- ld a, [hl]
- ld [bc], a
-
- callba RestoreAllPP
- ret
-
-ComputeHPBarPixels: ; c699
-; bc * (6 * 8) / de
- ld a, b
- or c
- jr z, .zero
- push hl
- xor a
- ld [hMultiplicand + 0], a
- ld a, b
- ld [hMultiplicand + 1], a
- ld a, c
- ld [hMultiplicand + 2], a
- ld a, 6 * 8
- ld [hMultiplier], a
- call Multiply
- ; We need de to be under 256 because hDivisor is only 1 byte.
- ld a, d
- and a
- jr z, .divide
- ; divide de and hProduct by 4
- srl d
- rr e
- srl d
- rr e
- ld a, [hProduct + 2]
- ld b, a
- ld a, [hProduct + 3]
- srl b
- rr a
- srl b
- rr a
- ld [hDividend + 3], a
- ld a, b
- ld [hDividend + 2], a
-.divide
- ld a, e
- ld [hDivisor], a
- ld b, 4
- call Divide
- ld a, [hQuotient + 2]
- ld e, a
- pop hl
- and a
- ret nz
- ld e, 1
- ret
-
-.zero
- ld e, 0
- ret
-
-AnimateHPBar: ; c6e0
- call WaitBGMap
- call _AnimateHPBar
- call WaitBGMap
- ret
-
-ClearBuffer1: ; c6ea
- xor a
- ld hl, Buffer1
- ld bc, 7
- call ByteFill
- ret
-
-FieldMoveJumptable: ; c6f5
- ld a, [Buffer1]
- rst JumpTable
- ld [Buffer1], a
- bit 7, a
- jr nz, .okay
- and a
- ret
-
-.okay
- and $7f
- scf
- ret
-
-GetPartyNick: ; c706
-; write CurPartyMon nickname to StringBuffer1-3
- ld hl, PartyMonNicknames
- ld a, BOXMON
- ld [MonType], a
- ld a, [CurPartyMon]
- call GetNick
- call CopyName1
-; copy text from StringBuffer2 to StringBuffer3
- ld de, StringBuffer2
- ld hl, StringBuffer3
- call CopyName2
- ret
-
-CheckEngineFlag: ; c721
-; Check engine flag de
-; Return carry if flag is not set
- ld b, CHECK_FLAG
- callba EngineFlagAction
- ld a, c
- and a
- jr nz, .isset
- scf
- ret
-.isset
- xor a
- ret
-
-CheckBadge: ; c731
-; Check engine flag a (ENGINE_ZEPHYRBADGE thru ENGINE_EARTHBADGE)
-; Display "Badge required" text and return carry if the badge is not owned
- call CheckEngineFlag
- ret nc
- ld hl, .BadgeRequiredText
- call MenuTextBoxBackup ; push text to queue
- scf
- ret
-
-.BadgeRequiredText: ; c73d
- ; Sorry! A new BADGE
- ; is required.
- text_jump _BadgeRequiredText
- db "@"
-
-CheckPartyMove: ; c742
-; Check if a monster in your party has move d.
-
- ld e, 0
- xor a
- ld [CurPartyMon], a
-.loop
- ld c, e
- ld b, 0
- ld hl, PartySpecies
- add hl, bc
- ld a, [hl]
- and a
- jr z, .no
- cp a, -1
- jr z, .no
- cp a, EGG
- jr z, .next
-
- ld bc, PARTYMON_STRUCT_LENGTH
- ld hl, PartyMon1Moves
- ld a, e
- call AddNTimes
- ld b, NUM_MOVES
-.check
- ld a, [hli]
- cp d
- jr z, .yes
- dec b
- jr nz, .check
-
-.next
- inc e
- jr .loop
-
-.yes
- ld a, e
- ld [CurPartyMon], a ; which mon has the move
- xor a
- ret
-.no
- scf
- ret
-
-FieldMoveFailed: ; c779
- ld hl, .CantUseHere
- call MenuTextBoxBackup
- ret
-
-.CantUseHere: ; 0xc780
- ; Can't use that here.
- text_jump UnknownText_0x1c05c8
- db "@"
-
-CutFunction: ; c785
- call ClearBuffer1
-.loop
- ld hl, .Jumptable
- call FieldMoveJumptable
- jr nc, .loop
- and $7f
- ld [wFieldMoveSucceeded], a
- ret
-
-.Jumptable: ; c796 (3:4796)
-
- dw .CheckAble
- dw .DoCut
- dw .FailCut
-
-.CheckAble: ; c79c (3:479c)
- ld de, ENGINE_HIVEBADGE
- call CheckBadge
- jr c, .nohivebadge
- call CheckMapForSomethingToCut
- jr c, .nothingtocut
- ld a, $1
- ret
-
-.nohivebadge
- ld a, $80
- ret
-
-.nothingtocut
- ld a, $2
- ret
-
-.DoCut: ; c7b2 (3:47b2)
- ld hl, Script_CutFromMenu
- call QueueScript
- ld a, $81
- ret
-
-.FailCut: ; c7bb (3:47bb)
- ld hl, Text_NothingToCut
- call MenuTextBoxBackup
- ld a, $80
- ret
-
-Text_UsedCut: ; 0xc7c4
- ; used CUT!
- text_jump UnknownText_0x1c05dd
- db "@"
-
-Text_NothingToCut: ; 0xc7c9
- ; There's nothing to CUT here.
- text_jump UnknownText_0x1c05ec
- db "@"
-
-CheckMapForSomethingToCut: ; c7ce
- ; Does the collision data of the facing tile permit cutting?
- call GetFacingTileCoord
- ld c, a
- push de
- callba CheckCutCollision
- pop de
- jr nc, .fail
- ; Get the location of the current block in OverworldMap.
- call GetBlockLocation
- ld c, [hl]
- ; See if that block contains something that can be cut.
- push hl
- ld hl, CutTreeBlockPointers
- call CheckOverworldTileArrays
- pop hl
- jr nc, .fail
- ; Back up the OverworldMap address to Buffer3
- ld a, l
- ld [Buffer3], a
- ld a, h
- ld [Buffer4], a
- ; Back up the replacement tile to Buffer5
- ld a, b
- ld [Buffer5], a
- ; Back up the animation index to Buffer6
- ld a, c
- ld [Buffer6], a
- xor a
- ret
-
-.fail
- scf
- ret
-
-Script_CutFromMenu: ; c7fe
- reloadmappart
- special UpdateTimePals
-
-Script_Cut: ; 0xc802
- callasm GetPartyNick
- writetext Text_UsedCut
- reloadmappart
- callasm CutDownTreeOrGrass
- closetext
- end
-
-CutDownTreeOrGrass: ; c810
- ld hl, Buffer3 ; OverworldMapTile
- ld a, [hli]
- ld h, [hl]
- ld l, a
- ld a, [Buffer5] ; ReplacementTile
- ld [hl], a
- xor a
- ld [hBGMapMode], a
- call OverworldTextModeSwitch
- call UpdateSprites
- call DelayFrame
- ld a, [Buffer6] ; Animation type
- ld e, a
- callba OWCutAnimation
- call BufferScreen
- call GetMovementPermissions
- call UpdateSprites
- call DelayFrame
- call LoadStandardFont
- ret
-
-CheckOverworldTileArrays: ; c840
- ; Input: c contains the tile you're facing
- ; Output: Replacement tile in b and effect on wild encounters in c, plus carry set.
- ; Carry is not set if the facing tile cannot be replaced, or if the tileset
- ; does not contain a tile you can replace.
-
- ; Dictionary lookup for pointer to tile replacement table
- push bc
- ld a, [wTileset]
- ld de, 3
- call IsInArray
- pop bc
- jr nc, .nope
- ; Load the pointer
- inc hl
- ld a, [hli]
- ld h, [hl]
- ld l, a
- ; Look up the tile you're facing
- ld de, 3
- ld a, c
- call IsInArray
- jr nc, .nope
- ; Load the replacement to b
- inc hl
- ld b, [hl]
- ; Load the animation type parameter to c
- inc hl
- ld c, [hl]
- scf
- ret
-
-.nope
- xor a
- ret
-
-CutTreeBlockPointers: ; c862
-; Which tileset are we in?
- dbw TILESET_JOHTO_1, .johto1
- dbw TILESET_JOHTO_2, .johto2
- dbw TILESET_KANTO, .kanto
- dbw TILESET_PARK, .park
- dbw TILESET_ILEX_FOREST, .ilex
- db -1
-
-.johto1: ; Johto OW
-; Which meta tile are we facing, which should we replace it with, and which animation?
- db $03, $02, $01 ; grass
- db $5b, $3c, $00 ; tree
- db $5f, $3d, $00 ; tree
- db $63, $3f, $00 ; tree
- db $67, $3e, $00 ; tree
- db -1
-
-.johto2: ; Goldenrod area
- db $03, $02, $01 ; grass
- db -1
-
-.kanto: ; Kanto OW
- db $0b, $0a, $01 ; grass
- db $32, $6d, $00 ; tree
- db $33, $6c, $00 ; tree
- db $34, $6f, $00 ; tree
- db $35, $4c, $00 ; tree
- db $60, $6e, $00 ; tree
- db -1
-
-.park: ; National Park
- db $13, $03, $01 ; grass
- db $03, $04, $01 ; grass
- db -1
-
-.ilex: ; Ilex Forest
- db $0f, $17, $00
- db -1
-
-WhirlpoolBlockPointers: ; c8a4
- dbw TILESET_JOHTO_1, .johto
- db -1
-
-.johto: ; c8a8
- db $07, $36, $00
- db -1
-
-OWFlash: ; c8ac
- call .CheckUseFlash
- and $7f
- ld [wFieldMoveSucceeded], a
- ret
-
-.CheckUseFlash: ; c8b5
-; Flash
- ld de, ENGINE_ZEPHYRBADGE
- callba CheckBadge
- jr c, .nozephyrbadge
- push hl
- callba SpecialAerodactylChamber
- pop hl
- jr c, .useflash
- ld a, [wTimeOfDayPalset]
- cp %11111111 ; 3, 3, 3, 3
- jr nz, .notadarkcave
-.useflash
- call UseFlash
- ld a, $81
- ret
-
-.notadarkcave
- call FieldMoveFailed
- ld a, $80
- ret
-
-.nozephyrbadge
- ld a, $80
- ret
-
-UseFlash: ; c8e0
- ld hl, Script_UseFlash
- jp QueueScript
-
-Script_UseFlash: ; 0xc8e6
- reloadmappart
- special UpdateTimePals
- writetext UnknownText_0xc8f3
- callasm BlindingFlash
- closetext
- end
-
-UnknownText_0xc8f3: ; 0xc8f3
- text_jump UnknownText_0x1c0609
- start_asm
- call WaitSFX
- ld de, SFX_FLASH
- call PlaySFX
- call WaitSFX
- ld hl, .BlankText
- ret
-
-.BlankText: ; 0xc908
- db "@"
-
-SurfFunction: ; c909
- call ClearBuffer1
-.loop
- ld hl, .Jumptable
- call FieldMoveJumptable
- jr nc, .loop
- and $7f
- ld [wFieldMoveSucceeded], a
- ret
-
-.Jumptable: ; c91a (3:491a)
- dw .TrySurf
- dw .DoSurf
- dw .FailSurf
- dw .AlreadySurfing
-
-.TrySurf: ; c922 (3:4922)
- ld de, ENGINE_FOGBADGE
- call CheckBadge
- jr c, .asm_c956
- ld hl, BikeFlags
- bit 1, [hl] ; always on bike
- jr nz, .cannotsurf
- ld a, [PlayerState]
- cp PLAYER_SURF
- jr z, .alreadyfail
- cp PLAYER_SURF_PIKA
- jr z, .alreadyfail
- call GetFacingTileCoord
- call GetTileCollision
- cp $1
- jr nz, .cannotsurf
- call CheckDirection
- jr c, .cannotsurf
- callba CheckFacingObject
- jr c, .cannotsurf
- ld a, $1
- ret
-.asm_c956
- ld a, $80
- ret
-.alreadyfail
- ld a, $3
- ret
-.cannotsurf
- ld a, $2
- ret
-
-.DoSurf: ; c95f (3:495f)
- call GetSurfType
- ld [Buffer2], a ; wd1eb (aliases: MovementType)
- call GetPartyNick
- ld hl, SurfFromMenuScript
- call QueueScript
- ld a, $81
- ret
-
-.FailSurf: ; c971 (3:4971)
- ld hl, CantSurfText
- call MenuTextBoxBackup
- ld a, $80
- ret
-
-.AlreadySurfing: ; c97a (3:497a)
- ld hl, AlreadySurfingText
- call MenuTextBoxBackup
- ld a, $80
- ret
-
-SurfFromMenuScript: ; c983
- special UpdateTimePals
-
-UsedSurfScript: ; c986
- writetext UsedSurfText ; "used SURF!"
- waitbutton
- closetext
-
- callasm .empty_fn ; empty function
-
- copybytetovar Buffer2
- writevarcode VAR_MOVEMENT
-
- special ReplaceKrisSprite
- special PlayMapMusic
-; step into the water
- special Special_SurfStartStep ; (slow_step_x, step_end)
- applymovement PLAYER, MovementBuffer ; PLAYER, MovementBuffer
- end
-
-.empty_fn: ; c9a2
- callba MobileFn_1060bb ; empty
- ret
-
-UsedSurfText: ; c9a9
- text_jump _UsedSurfText
- db "@"
-
-CantSurfText: ; c9ae
- text_jump _CantSurfText
- db "@"
-
-AlreadySurfingText: ; c9b3
- text_jump _AlreadySurfingText
- db "@"
-
-GetSurfType: ; c9b8
-; Surfing on Pikachu uses an alternate sprite.
-; This is done by using a separate movement type.
-
- ld a, [CurPartyMon]
- ld e, a
- ld d, 0
- ld hl, PartySpecies
- add hl, de
-
- ld a, [hl]
- cp PIKACHU
- ld a, PLAYER_SURF_PIKA
- ret z
- ld a, PLAYER_SURF
- ret
-
-CheckDirection: ; c9cb
-; Return carry if a tile permission prevents you
-; from moving in the direction you're facing.
-
-; Get player direction
- ld a, [PlayerDirection]
- and a, %00001100 ; bits 2 and 3 contain direction
- rrca
- rrca
- ld e, a
- ld d, 0
- ld hl, .Directions
- add hl, de
-
-; Can you walk in this direction?
- ld a, [TilePermissions]
- and [hl]
- jr nz, .quit
- xor a
- ret
-
-.quit
- scf
- ret
-
-.Directions
- db FACE_DOWN
- db FACE_UP
- db FACE_LEFT
- db FACE_RIGHT
-
-TrySurfOW:: ; c9e7
-; Checking a tile in the overworld.
-; Return carry if fail is allowed.
-
-; Don't ask to surf if already fail.
- ld a, [PlayerState]
- cp PLAYER_SURF_PIKA
- jr z, .quit
- cp PLAYER_SURF
- jr z, .quit
-
-; Must be facing water.
- ld a, [EngineBuffer1]
- call GetTileCollision
- cp 1 ; surfable
- jr nz, .quit
-
-; Check tile permissions.
- call CheckDirection
- jr c, .quit
-
- ld de, ENGINE_FOGBADGE
- call CheckEngineFlag
- jr c, .quit
-
- ld d, SURF
- call CheckPartyMove
- jr c, .quit
-
- ld hl, BikeFlags
- bit 1, [hl] ; always on bike (can't surf)
- jr nz, .quit
-
- call GetSurfType
- ld [MovementType], a
- call GetPartyNick
-
- ld a, BANK(AskSurfScript)
- ld hl, AskSurfScript
- call CallScript
-
- scf
- ret
-
-.quit
- xor a
- ret
-
-AskSurfScript: ; ca2c
- opentext
- writetext AskSurfText
- yesorno
- iftrue UsedSurfScript
- closetext
- end
-
-AskSurfText: ; ca36
- text_jump _AskSurfText ; The water is calm.
- db "@" ; Want to SURF?
-
-FlyFunction: ; ca3b
- call ClearBuffer1
-.loop
- ld hl, .Jumptable
- call FieldMoveJumptable
- jr nc, .loop
- and $7f
- ld [wFieldMoveSucceeded], a
- ret
-
-.Jumptable
- dw .TryFly
- dw .DoFly
- dw .FailFly
-
-.TryFly: ; ca52
-; Fly
- ld de, ENGINE_STORMBADGE
- call CheckBadge
- jr c, .nostormbadge
- call GetMapPermission
- call CheckOutdoorMap
- jr z, .outdoors
- jr .indoors
-
-.outdoors
- xor a
- ld [hMapAnims], a
- call LoadStandardMenuDataHeader
- call ClearSprites
- callba _FlyMap
- ld a, e
- cp -1
- jr z, .illegal
- cp NUM_SPAWNS
- jr nc, .illegal
-
- ld [wd001], a
- call CloseWindow
- ld a, $1
- ret
-
-.nostormbadge
- ld a, $82
- ret
-
-.indoors
- ld a, $2
- ret
-
-.illegal
- call CloseWindow
- call WaitBGMap
- ld a, $80
- ret
-
-.DoFly: ; ca94
- ld hl, .FlyScript
- call QueueScript
- ld a, $81
- ret
-
-.FailFly: ; ca9d
- call FieldMoveFailed
- ld a, $82
- ret
-
-.FlyScript: ; 0xcaa3
- reloadmappart
- callasm HideSprites
- special UpdateTimePals
- callasm FlyFromAnim
- farscall Script_AbortBugContest
- special WarpToSpawnPoint
- callasm DelayLoadingNewSprites
- writecode VAR_MOVEMENT, PLAYER_NORMAL
- newloadmap MAPSETUP_FLY
- callasm FlyToAnim
- special WaitSFX
- callasm .ReturnFromFly
- end
-
-.ReturnFromFly: ; cacb
- callba Function561d
- call DelayFrame
- call ReplaceKrisSprite
- callba LoadOverworldFont
- ret
-
-WaterfallFunction: ; cade
- call .TryWaterfall
- and $7f
- ld [wFieldMoveSucceeded], a
- ret
-
-.TryWaterfall: ; cae7
-; Waterfall
- ld de, ENGINE_RISINGBADGE
- callba CheckBadge
- ld a, $80
- ret c
- call CheckMapCanWaterfall
- jr c, .failed
- ld hl, Script_WaterfallFromMenu
- call QueueScript
- ld a, $81
- ret
-
-.failed
- call FieldMoveFailed
- ld a, $80
- ret
-
-CheckMapCanWaterfall: ; cb07
- ld a, [PlayerDirection]
- and $c
- cp FACE_UP
- jr nz, .failed
- ld a, [TileUp]
- call CheckWaterfallTile
- jr nz, .failed
- xor a
- ret
-
-.failed
- scf
- ret
-
-Script_WaterfallFromMenu: ; 0xcb1c
- reloadmappart
- special UpdateTimePals
-
-Script_UsedWaterfall: ; 0xcb20
- callasm GetPartyNick
- writetext .Text_UsedWaterfall
- waitbutton
- closetext
- playsound SFX_BUBBLEBEAM
-.loop
- applymovement PLAYER, .WaterfallStep
- callasm .CheckContinueWaterfall
- iffalse .loop
- end
-
-.CheckContinueWaterfall: ; cb38
- xor a
- ld [ScriptVar], a
- ld a, [PlayerStandingTile]
- call CheckWaterfallTile
- ret z
- callba MobileFn_1060c1
- ld a, $1
- ld [ScriptVar], a
- ret
-
-.WaterfallStep: ; cb4f
- turn_waterfall_up
- step_end
-
-.Text_UsedWaterfall: ; 0xcb51
- ; used WATERFALL!
- text_jump UnknownText_0x1c068e
- db "@"
-
-TryWaterfallOW:: ; cb56
- ld d, WATERFALL
- call CheckPartyMove
- jr c, .failed
- ld de, ENGINE_RISINGBADGE
- call CheckEngineFlag
- jr c, .failed
- call CheckMapCanWaterfall
- jr c, .failed
- ld a, BANK(Script_AskWaterfall)
- ld hl, Script_AskWaterfall
- call CallScript
- scf
- ret
-
-.failed
- ld a, BANK(Script_CantDoWaterfall)
- ld hl, Script_CantDoWaterfall
- call CallScript
- scf
- ret
-
-Script_CantDoWaterfall: ; 0xcb7e
- jumptext .Text_CantDoWaterfall
-
-.Text_CantDoWaterfall: ; 0xcb81
- ; Wow, it's a huge waterfall.
- text_jump UnknownText_0x1c06a3
- db "@"
-
-Script_AskWaterfall: ; 0xcb86
- opentext
- writetext .AskUseWaterfall
- yesorno
- iftrue Script_UsedWaterfall
- closetext
- end
-
-.AskUseWaterfall: ; 0xcb90
- ; Do you want to use WATERFALL?
- text_jump UnknownText_0x1c06bf
- db "@"
-
-EscapeRopeFunction: ; cb95
- call ClearBuffer1
- ld a, $1
- jr dig_incave
-
-DigFunction: ; cb9c
- call ClearBuffer1
- ld a, $2
-
-dig_incave
- ld [Buffer2], a
-.loop
- ld hl, .DigTable
- call FieldMoveJumptable
- jr nc, .loop
- and $7f
- ld [wFieldMoveSucceeded], a
- ret
-
-.DigTable: ; cbb2
- dw .CheckCanDig
- dw .DoDig
- dw .FailDig
-
-.CheckCanDig: ; cbb8
- call GetMapPermission
- cp CAVE
- jr z, .incave
- cp DUNGEON
- jr z, .incave
-.fail
- ld a, $2
- ret
-
-.incave
- ld hl, wDigWarp
- ld a, [hli]
- and a
- jr z, .fail
- ld a, [hli]
- and a
- jr z, .fail
- ld a, [hl]
- and a
- jr z, .fail
- ld a, $1
- ret
-
-.DoDig: ; cbd8
- ld hl, wDigWarp
- ld de, wNextWarp
- ld bc, 3
- call CopyBytes
- call GetPartyNick
- ld a, [Buffer2]
- cp $2
- jr nz, .escaperope
- ld hl, .UsedDigScript
- call QueueScript
- ld a, $81
- ret
-
-.escaperope
- callba SpecialKabutoChamber
- ld hl, .UsedEscapeRopeScript
- call QueueScript
- ld a, $81
- ret
-
-.FailDig: ; cc06
- ld a, [Buffer2]
- cp $2
- jr nz, .failescaperope
- ld hl, .Text_CantUseHere
- call MenuTextBox
- call WaitPressAorB_BlinkCursor
- call CloseWindow
-
-.failescaperope
- ld a, $80
- ret
-
-.Text_UsedDig: ; 0xcc1c
- ; used DIG!
- text_jump UnknownText_0x1c06de
- db "@"
-
-.Text_UsedEscapeRope: ; 0xcc21
- ; used an ESCAPE ROPE.
- text_jump UnknownText_0x1c06ed
- db "@"
-
-.Text_CantUseHere: ; 0xcc26
- ; Can't use that here.
- text_jump UnknownText_0x1c0705
- db "@"
-
-.UsedEscapeRopeScript: ; 0xcc2b
- reloadmappart
- special UpdateTimePals
- writetext .Text_UsedEscapeRope
- jump .UsedDigOrEscapeRopeScript
-
-.UsedDigScript: ; 0xcc35
- reloadmappart
- special UpdateTimePals
- writetext .Text_UsedDig
-
-.UsedDigOrEscapeRopeScript: ; 0xcc3c
- waitbutton
- closetext
- playsound SFX_WARP_TO
- applymovement PLAYER, .DigOut
- farscall Script_AbortBugContest
- special WarpToSpawnPoint
- writecode VAR_MOVEMENT, PLAYER_NORMAL
- newloadmap MAPSETUP_DOOR
- playsound SFX_WARP_FROM
- applymovement PLAYER, .DigReturn
- end
-
-.DigOut: ; 0xcc59
- step_dig 32
- hide_person
- step_end
-
-.DigReturn: ; 0xcc5d
- show_person
- return_dig 32
- step_end
-
-TeleportFunction: ; cc61
- call ClearBuffer1
-.loop
- ld hl, .Jumptable
- call FieldMoveJumptable
- jr nc, .loop
- and $7f
- ld [wFieldMoveSucceeded], a
- ret
-
-.Jumptable: ; cc72
- dw .TryTeleport
- dw .DoTeleport
- dw .FailTeleport
-
-.TryTeleport: ; cc78
- call GetMapPermission
- call CheckOutdoorMap
- jr z, .CheckIfSpawnPoint
- jr .nope
-
-.CheckIfSpawnPoint
- ld a, [wLastSpawnMapGroup]
- ld d, a
- ld a, [wLastSpawnMapNumber]
- ld e, a
- callba IsSpawnPoint
- jr nc, .nope
- ld a, c
- ld [wd001], a
- ld a, $1
- ret
-
-.nope
- ld a, $2
- ret
-
-.DoTeleport: ; cc9c
- call GetPartyNick
- ld hl, .TeleportScript
- call QueueScript
- ld a, $81
- ret
-
-.FailTeleport: ; cca8
- ld hl, .Text_CantUseHere
- call MenuTextBoxBackup
- ld a, $80
- ret
-
-.Text_ReturnToLastMonCenter: ; 0xccb1
- ; Return to the last #MON CENTER.
- text_jump UnknownText_0x1c071a
- db "@"
-
-.Text_CantUseHere: ; 0xccb6
- ; Can't use that here.
- text_jump UnknownText_0x1c073b
- db "@"
-
-.TeleportScript: ; 0xccbb
- reloadmappart
- special UpdateTimePals
- writetext .Text_ReturnToLastMonCenter
- pause 60
- reloadmappart
- closetext
- playsound SFX_WARP_TO
- applymovement PLAYER, .TeleportFrom
- farscall Script_AbortBugContest
- special WarpToSpawnPoint
- writecode VAR_MOVEMENT, PLAYER_NORMAL
- newloadmap MAPSETUP_TELEPORT
- playsound SFX_WARP_FROM
- applymovement PLAYER, .TeleportTo
- end
-
-.TeleportFrom: ; cce1
- teleport_from
- step_end
-
-.TeleportTo: ; cce3
- teleport_to
- step_end
-
-StrengthFunction: ; cce5
- call .TryStrength
- and $7f
- ld [wFieldMoveSucceeded], a
- ret
-
-.TryStrength: ; ccee
-; Strength
- ld de, ENGINE_PLAINBADGE
- call CheckBadge
- jr c, .Failed
- jr .UseStrength
-
-.AlreadyUsing: ; unreferenced
- ld hl, .JumpText
- call MenuTextBoxBackup
- ld a, $80
- ret
-
-.JumpText: ; 0xcd01
- text_jump UnknownText_0x1c0751
- db "@"
-
-.Failed: ; cd06
- ld a, $80
- ret
-
-.UseStrength: ; cd09
- ld hl, Script_StrengthFromMenu
- call QueueScript
- ld a, $81
- ret
-
-SetStrengthFlag: ; cd12
- ld hl, BikeFlags
- set 0, [hl]
- ld a, [CurPartyMon]
- ld e, a
- ld d, 0
- ld hl, PartySpecies
- add hl, de
- ld a, [hl]
- ld [Buffer6], a
- call GetPartyNick
- ret
-
-Script_StrengthFromMenu: ; 0xcd29
- reloadmappart
- special UpdateTimePals
-
-Script_UsedStrength: ; 0xcd2d
- callasm SetStrengthFlag
- writetext .UsedStrength
- copybytetovar Buffer6
- cry 0
- pause 3
- writetext .StrengthAllowedItToMoveBoulders
- closetext
- end
-
-.UsedStrength: ; 0xcd41
- text_jump UnknownText_0x1c0774
- db "@"
-
-.StrengthAllowedItToMoveBoulders: ; 0xcd46
- text_jump UnknownText_0x1c0788
- db "@"
-
-AskStrengthScript:
- callasm TryStrengthOW
- iffalse .AskStrength
- if_equal $1, .DontMeetRequirements
- jump .AlreadyUsedStrength
-
-.DontMeetRequirements: ; 0xcd59
- jumptext UnknownText_0xcd73
-
-.AlreadyUsedStrength: ; 0xcd5c
- jumptext UnknownText_0xcd6e
-
-.AskStrength: ; 0xcd5f
- opentext
- writetext UnknownText_0xcd69
- yesorno
- iftrue Script_UsedStrength
- closetext
- end
-
-UnknownText_0xcd69: ; 0xcd69
- ; A #MON may be able to move this. Want to use STRENGTH?
- text_jump UnknownText_0x1c07a0
- db "@"
-
-UnknownText_0xcd6e: ; 0xcd6e
- ; Boulders may now be moved!
- text_jump UnknownText_0x1c07d8
- db "@"
-
-UnknownText_0xcd73: ; 0xcd73
- ; A #MON may be able to move this.
- text_jump UnknownText_0x1c07f4
- db "@"
-
-TryStrengthOW: ; cd78
- ld d, STRENGTH
- call CheckPartyMove
- jr c, .nope
-
- ld de, ENGINE_PLAINBADGE
- call CheckEngineFlag
- jr c, .nope
-
- ld hl, BikeFlags
- bit 0, [hl]
- jr z, .already_using
-
- ld a, 2
- jr .done
-
-.nope
- ld a, 1
- jr .done
-
-.already_using
- xor a
- jr .done
-
-.done
- ld [ScriptVar], a
- ret
-
-WhirlpoolFunction: ; cd9d
- call ClearBuffer1
-.loop
- ld hl, Jumptable_cdae
- call FieldMoveJumptable
- jr nc, .loop
- and $7f
- ld [wFieldMoveSucceeded], a
- ret
-
-Jumptable_cdae: ; cdae
- dw .TryWhirlpool
- dw .DoWhirlpool
- dw .FailWhirlpool
-
-.TryWhirlpool: ; cdb4
- ld de, ENGINE_GLACIERBADGE
- call CheckBadge
- jr c, .noglacierbadge
- call TryWhirlpoolMenu
- jr c, .failed
- ld a, $1
- ret
-
-.failed
- ld a, $2
- ret
-
-.noglacierbadge
- ld a, $80
- ret
-
-.DoWhirlpool: ; cdca
- ld hl, Script_WhirlpoolFromMenu
- call QueueScript
- ld a, $81
- ret
-
-.FailWhirlpool: ; cdd3
- call FieldMoveFailed
- ld a, $80
- ret
-
-Text_UsedWhirlpool: ; 0xcdd9
- ; used WHIRLPOOL!
- text_jump UnknownText_0x1c0816
- db "@"
-
-TryWhirlpoolMenu: ; cdde
- call GetFacingTileCoord
- ld c, a
- push de
- call CheckWhirlpoolTile
- pop de
- jr c, .failed
- call GetBlockLocation
- ld c, [hl]
- push hl
- ld hl, WhirlpoolBlockPointers
- call CheckOverworldTileArrays
- pop hl
- jr nc, .failed
- ld a, l
- ld [Buffer3], a
- ld a, h
- ld [Buffer4], a
- ld a, b
- ld [Buffer5], a
- ld a, c
- ld [Buffer6], a
- xor a
- ret
-
-.failed
- scf
- ret
-
-Script_WhirlpoolFromMenu: ; 0xce0b
- reloadmappart
- special UpdateTimePals
-
-Script_UsedWhirlpool: ; 0xce0f
- callasm GetPartyNick
- writetext Text_UsedWhirlpool
- reloadmappart
- callasm DisappearWhirlpool
- closetext
- end
-
-DisappearWhirlpool: ; ce1d
- ld hl, Buffer3
- ld a, [hli]
- ld h, [hl]
- ld l, a
- ld a, [Buffer5]
- ld [hl], a
- xor a
- ld [hBGMapMode], a
- call OverworldTextModeSwitch
- ld a, [Buffer6]
- ld e, a
- callba PlayWhirlpoolSound
- call BufferScreen
- call GetMovementPermissions
- ret
-
-TryWhirlpoolOW:: ; ce3e
- ld d, WHIRLPOOL
- call CheckPartyMove
- jr c, .failed
- ld de, ENGINE_GLACIERBADGE
- call CheckEngineFlag
- jr c, .failed
- call TryWhirlpoolMenu
- jr c, .failed
- ld a, BANK(Script_AskWhirlpoolOW)
- ld hl, Script_AskWhirlpoolOW
- call CallScript
- scf
- ret
-
-.failed
- ld a, BANK(Script_MightyWhirlpool)
- ld hl, Script_MightyWhirlpool
- call CallScript
- scf
- ret
-
-Script_MightyWhirlpool: ; 0xce66
- jumptext .MightyWhirlpoolText
-
-.MightyWhirlpoolText: ; 0xce69
- text_jump UnknownText_0x1c082b
- db "@"
-
-Script_AskWhirlpoolOW: ; 0xce6e
- opentext
- writetext UnknownText_0xce78
- yesorno
- iftrue Script_UsedWhirlpool
- closetext
- end
-
-UnknownText_0xce78: ; 0xce78
- text_jump UnknownText_0x1c0864
- db "@"
-
-HeadbuttFunction: ; ce7d
- call TryHeadbuttFromMenu
- and $7f
- ld [wFieldMoveSucceeded], a
- ret
-
-TryHeadbuttFromMenu: ; ce86
- call GetFacingTileCoord
- call CheckHeadbuttTreeTile
- jr nz, .no_tree
-
- ld hl, HeadbuttFromMenuScript
- call QueueScript
- ld a, $81
- ret
-
-.no_tree
- call FieldMoveFailed
- ld a, $80
- ret
-
-UnknownText_0xce9d: ; 0xce9d
- ; did a HEADBUTT!
- text_jump UnknownText_0x1c0897
- db "@"
-
-UnknownText_0xcea2: ; 0xcea2
- ; Nope. Nothing…
- text_jump UnknownText_0x1c08ac
- db "@"
-
-HeadbuttFromMenuScript: ; 0xcea7
- reloadmappart
- special UpdateTimePals
-
-HeadbuttScript: ; 0xceab
- callasm GetPartyNick
- writetext UnknownText_0xce9d
-
- reloadmappart
- callasm ShakeHeadbuttTree
-
- callasm TreeMonEncounter
- iffalse .no_battle
- closetext
- randomwildmon
- startbattle
- reloadmapafterbattle
- end
-
-.no_battle
- writetext UnknownText_0xcea2
- waitbutton
- closetext
- end
-
-TryHeadbuttOW:: ; cec9
- ld d, HEADBUTT
- call CheckPartyMove
- jr c, .no
-
- ld a, BANK(AskHeadbuttScript)
- ld hl, AskHeadbuttScript
- call CallScript
- scf
- ret
-
-.no
- xor a
- ret
-
-AskHeadbuttScript: ; 0xcedc
- opentext
- writetext UnknownText_0xcee6
- yesorno
- iftrue HeadbuttScript
- closetext
- end
-
-UnknownText_0xcee6: ; 0xcee6
- ; A #MON could be in this tree. Want to HEADBUTT it?
- text_jump UnknownText_0x1c08bc
- db "@"
-
-RockSmashFunction: ; ceeb
- call TryRockSmashFromMenu
- and $7f
- ld [wFieldMoveSucceeded], a
- ret
-
-TryRockSmashFromMenu: ; cef4
- call GetFacingObject
- jr c, .no_rock
- ld a, d
- cp $18
- jr nz, .no_rock
-
- ld hl, RockSmashFromMenuScript
- call QueueScript
- ld a, $81
- ret
-
-.no_rock
- call FieldMoveFailed
- ld a, $80
- ret
-
-GetFacingObject: ; cf0d
- callba CheckFacingObject
- jr nc, .fail
-
- ld a, [hObjectStructIndexBuffer]
- call GetObjectStruct
- ld hl, OBJECT_MAP_OBJECT_INDEX
- add hl, bc
- ld a, [hl]
- ld [hLastTalked], a
- call GetMapObject
- ld hl, MAPOBJECT_MOVEMENT
- add hl, bc
- ld a, [hl]
- ld d, a
- and a
- ret
-
-.fail
- scf
- ret
-
-RockSmashFromMenuScript: ; 0xcf2e
- reloadmappart
- special UpdateTimePals
-
-RockSmashScript: ; cf32
- callasm GetPartyNick
- writetext UnknownText_0xcf58
- closetext
- special WaitSFX
- playsound SFX_STRENGTH
- earthquake 84
- applymovement2 MovementData_0xcf55
- disappear -2
-
- callasm RockMonEncounter
- copybytetovar TempWildMonSpecies
- iffalse .done
- randomwildmon
- startbattle
- reloadmapafterbattle
-.done
- end
-
-MovementData_0xcf55: ; 0xcf55
- rock_smash 10
- step_end
-
-UnknownText_0xcf58: ; 0xcf58
- text_jump UnknownText_0x1c08f0
- db "@"
-
-AskRockSmashScript: ; 0xcf5d
- callasm HasRockSmash
- if_equal 1, .no
-
- opentext
- writetext UnknownText_0xcf77
- yesorno
- iftrue RockSmashScript
- closetext
- end
-.no
- jumptext UnknownText_0xcf72
-
-UnknownText_0xcf72: ; 0xcf72
- ; Maybe a #MON can break this.
- text_jump UnknownText_0x1c0906
- db "@"
-
-UnknownText_0xcf77: ; 0xcf77
- ; This rock looks breakable. Want to use ROCK SMASH?
- text_jump UnknownText_0x1c0924
- db "@"
-
-HasRockSmash: ; cf7c
- ld d, ROCK_SMASH
- call CheckPartyMove
- jr nc, .yes
-.no
- ld a, 1
- jr .done
-.yes
- xor a
- jr .done
-.done
- ld [ScriptVar], a
- ret
-
-FishFunction: ; cf8e
- ld a, e
- push af
- call ClearBuffer1
- pop af
- ld [Buffer2], a
-.loop
- ld hl, .FishTable
- call FieldMoveJumptable
- jr nc, .loop
- and $7f
- ld [wFieldMoveSucceeded], a
- ret
-
-.FishTable: ; cfa5
- dw .TryFish
- dw .FishNoBite
- dw .FishGotSomething
- dw .FailFish
- dw .FishNoFish
-
-.TryFish: ; cfaf
- ld a, [PlayerState]
- cp PLAYER_SURF
- jr z, .fail
- cp PLAYER_SURF_PIKA
- jr z, .fail
- call GetFacingTileCoord
- call GetTileCollision
- cp $1
- jr z, .facingwater
-.fail
- ld a, $3
- ret
-
-.facingwater
- call GetFishingGroup
- and a
- jr nz, .goodtofish
- ld a, $4
- ret
-
-.goodtofish
- ld d, a
- ld a, [Buffer2]
- ld e, a
- callba Fish
- ld a, d
- and a
- jr z, .nonibble
- ld [TempWildMonSpecies], a
- ld a, e
- ld [CurPartyLevel], a
- ld a, BATTLETYPE_FISH
- ld [BattleType], a
- ld a, $2
- ret
-
-.nonibble
- ld a, $1
- ret
-
-.FailFish: ; cff1
- ld a, $80
- ret
-
-.FishGotSomething: ; cff4
- ld a, $1
- ld [Buffer6], a
- ld hl, Script_GotABite
- call QueueScript
- ld a, $81
- ret
-
-.FishNoBite: ; d002
- ld a, $2
- ld [Buffer6], a
- ld hl, Script_NotEvenANibble
- call QueueScript
- ld a, $81
- ret
-
-.FishNoFish: ; d010
- ld a, $0
- ld [Buffer6], a
- ld hl, Script_NotEvenANibble2
- call QueueScript
- ld a, $81
- ret
-
-Script_NotEvenANibble: ; 0xd01e
- scall Script_FishCastRod
- writetext UnknownText_0xd0a9
- jump Script_NotEvenANibble_FallThrough
-
-Script_NotEvenANibble2: ; 0xd027
- scall Script_FishCastRod
- writetext UnknownText_0xd0a9
-
-Script_NotEvenANibble_FallThrough: ; 0xd02d
- loademote EMOTE_SHADOW
- callasm PutTheRodAway
- closetext
- end
-
-Script_GotABite: ; 0xd035
- scall Script_FishCastRod
- callasm Fishing_CheckFacingUp
- iffalse .NotFacingUp
- applymovement PLAYER, .Movement_FacingUp
- jump .FightTheHookedPokemon
-
-.NotFacingUp: ; 0xd046
- applymovement PLAYER, .Movement_NotFacingUp
-
-.FightTheHookedPokemon: ; 0xd04a
- pause 40
- applymovement PLAYER, .Movement_RestoreRod
- writetext UnknownText_0xd0a4
- callasm PutTheRodAway
- closetext
- randomwildmon
- startbattle
- reloadmapafterbattle
- end
-
-.Movement_NotFacingUp: ; d05c
- fish_got_bite
- fish_got_bite
- fish_got_bite
- fish_got_bite
- show_emote
- step_end
-
-.Movement_FacingUp: ; d062
- fish_got_bite
- fish_got_bite
- fish_got_bite
- fish_got_bite
- step_sleep_1
- show_emote
- step_end
-
-.Movement_RestoreRod: ; d069
- hide_emote
- fish_cast_rod
- step_end
-
-Fishing_CheckFacingUp: ; d06c
- ld a, [PlayerDirection]
- and $c
- cp OW_UP
- ld a, $1
- jr z, .up
- xor a
-
-.up
- ld [ScriptVar], a
- ret
-
-Script_FishCastRod: ; 0xd07c
- reloadmappart
- loadvar hBGMapMode, $0
- special UpdateTimePals
- loademote EMOTE_ROD
- callasm LoadFishingGFX
- loademote EMOTE_SHOCK
- applymovement PLAYER, MovementData_0xd093
- pause 40
- end
-
-MovementData_0xd093: ; d093
- fish_cast_rod
- step_end
-
-PutTheRodAway: ; d095
- xor a
- ld [hBGMapMode], a
- ld a, $1
- ld [PlayerAction], a
- call UpdateSprites
- call ReplaceKrisSprite
- ret
-
-UnknownText_0xd0a4: ; 0xd0a4
- ; Oh! A bite!
- text_jump UnknownText_0x1c0958
- db "@"
-
-UnknownText_0xd0a9: ; 0xd0a9
- ; Not even a nibble!
- text_jump UnknownText_0x1c0965
- db "@"
-
-UnknownText_0xd0ae: ; unused
- ; Looks like there's nothing here.
- text_jump UnknownText_0x1c0979
- db "@"
-
-BikeFunction: ; d0b3
- call .TryBike
- and $7f
- ld [wFieldMoveSucceeded], a
- ret
-
-.TryBike: ; d0bc
- call .CheckEnvironment
- jr c, .CannotUseBike
- ld a, [PlayerState]
- cp PLAYER_NORMAL
- jr z, .GetOnBike
- cp PLAYER_BIKE
- jr z, .GetOffBike
- jr .CannotUseBike
-
-.GetOnBike
- ld hl, Script_GetOnBike
- ld de, Script_GetOnBike_Register
- call .CheckIfRegistered
- call QueueScript
- xor a
- ld [MusicFade], a
- ld de, MUSIC_NONE
- call PlayMusic
- call DelayFrame
- call MaxVolume
- ld de, MUSIC_BICYCLE
- ld a, e
- ld [wMapMusic], a
- call PlayMusic
- ld a, $1
- ret
-
-.GetOffBike
- ld hl, BikeFlags
- bit 1, [hl]
- jr nz, .CantGetOffBike
- ld hl, Script_GetOffBike
- ld de, Script_GetOffBike_Register
- call .CheckIfRegistered
- ld a, $3
- jr .done
-
-.CantGetOffBike
- ld hl, Script_CantGetOffBike
- jr .done
-
-.CannotUseBike
- ld a, $0
- ret
-
-.done
- call QueueScript
- ld a, $1
- ret
-
-.CheckIfRegistered: ; d119
- ld a, [wUsingItemWithSelect]
- and a
- ret z
- ld h, d
- ld l, e
- ret
-
-.CheckEnvironment: ; d121
- call GetMapPermission
- call CheckOutdoorMap
- jr z, .ok
- cp CAVE
- jr z, .ok
- cp GATE
- jr z, .ok
- jr .nope
-
-.ok
- call GetPlayerStandingTile
- and $f ; can't use our bike in a wall or on water
- jr nz, .nope
- xor a
- ret
-
-.nope
- scf
- ret
-
-Script_GetOnBike: ; 0xd13e
- reloadmappart
- special UpdateTimePals
- writecode VAR_MOVEMENT, PLAYER_BIKE
- writetext GotOnTheBikeText
- waitbutton
- closetext
- special ReplaceKrisSprite
- end
-
-Script_GetOnBike_Register: ; 0xd14e
- writecode VAR_MOVEMENT, PLAYER_BIKE
- closetext
- special ReplaceKrisSprite
- end
-
-; XXX
- nop
- ret
-
-Script_GetOffBike: ; 0xd158
- reloadmappart
- special UpdateTimePals
- writecode VAR_MOVEMENT, PLAYER_NORMAL
- writetext GotOffTheBikeText
- waitbutton
-
-FinishGettingOffBike:
- closetext
- special ReplaceKrisSprite
- special PlayMapMusic
- end
-
-Script_GetOffBike_Register: ; 0xd16b
- writecode VAR_MOVEMENT, PLAYER_NORMAL
- jump FinishGettingOffBike
-
-Script_CantGetOffBike: ; 0xd171
- writetext .CantGetOffBikeText
- waitbutton
- closetext
- end
-
-.CantGetOffBikeText: ; 0xd177
- ; You can't get off here!
- text_jump UnknownText_0x1c099a
- db "@"
-
-GotOnTheBikeText: ; 0xd17c
- ; got on the @ .
- text_jump UnknownText_0x1c09b2
- db "@"
-
-GotOffTheBikeText: ; 0xd181
- ; got off the @ .
- text_jump UnknownText_0x1c09c7
- db "@"
-
-TryCutOW:: ; d186
- ld d, CUT
- call CheckPartyMove
- jr c, .cant_cut
-
- ld de, ENGINE_HIVEBADGE
- call CheckEngineFlag
- jr c, .cant_cut
-
- ld a, BANK(AskCutScript)
- ld hl, AskCutScript
- call CallScript
- scf
- ret
-
-.cant_cut
- ld a, BANK(CantCutScript)
- ld hl, CantCutScript
- call CallScript
- scf
- ret
-
-AskCutScript: ; 0xd1a9
- opentext
- writetext UnknownText_0xd1c8
- yesorno
- iffalse .script_d1b8
- callasm .CheckMap
- iftrue Script_Cut
-.script_d1b8
- closetext
- end
-
-.CheckMap: ; d1ba
- xor a
- ld [ScriptVar], a
- call CheckMapForSomethingToCut
- ret c
- ld a, TRUE
- ld [ScriptVar], a
- ret
-
-UnknownText_0xd1c8: ; 0xd1c8
- text_jump UnknownText_0x1c09dd
- db "@"
-
-CantCutScript: ; 0xd1cd
- jumptext UnknownText_0xd1d0
-
-UnknownText_0xd1d0: ; 0xd1d0
- text_jump UnknownText_0x1c0a05
- db "@"
-
-_ReceiveItem:: ; d1d5
- call DoesHLEqualNumItems
- jp nz, PutItemInPocket
- push hl
- call CheckItemPocket
- pop de
- ld a, [wItemAttributeParamBuffer]
- dec a
- ld hl, .Pockets
- rst JumpTable
- ret
-
-.Pockets: ; d1e9
- dw .Item
- dw .KeyItem
- dw .Ball
- dw .TMHM
-
-.Item: ; d1f1
- ld h, d
- ld l, e
- jp PutItemInPocket
-
-.KeyItem: ; d1f6
- ld h, d
- ld l, e
- jp ReceiveKeyItem
-
-.Ball: ; d1fb
- ld hl, NumBalls
- jp PutItemInPocket
-
-.TMHM: ; d201
- ld h, d
- ld l, e
- ld a, [CurItem]
- ld c, a
- call GetTMHMNumber
- jp ReceiveTMHM
-
-_TossItem:: ; d20d
- call DoesHLEqualNumItems
- jr nz, .remove
- push hl
- call CheckItemPocket
- pop de
- ld a, [wItemAttributeParamBuffer]
- dec a
- ld hl, .Pockets
- rst JumpTable
- ret
-
-.Pockets
- dw .Item
- dw .KeyItem
- dw .Ball
- dw .TMHM
-
-.Ball ; d228
- ld hl, NumBalls
- jp RemoveItemFromPocket
-
-.TMHM ; d22e
- ld h, d
- ld l, e
- ld a, [CurItem]
- ld c, a
- call GetTMHMNumber
- jp TossTMHM
-
-.KeyItem ; d23a
- ld h, d
- ld l, e
- jp TossKeyItem
-
-.Item ; d23f
- ld h, d
- ld l, e
-
-.remove
- jp RemoveItemFromPocket
-
-_CheckItem:: ; d244
- call DoesHLEqualNumItems
- jr nz, .nope
- push hl
- call CheckItemPocket
- pop de
- ld a, [wItemAttributeParamBuffer]
- dec a
- ld hl, .Pockets
- rst JumpTable
- ret
-
-.Pockets
- dw .Item
- dw .KeyItem
- dw .Ball
- dw .TMHM
-
-.Ball ; d25f
- ld hl, NumBalls
- jp CheckTheItem
-
-.TMHM ; d265
- ld h, d
- ld l, e
- ld a, [CurItem]
- ld c, a
- call GetTMHMNumber
- jp CheckTMHM
-
-.KeyItem ; d271
- ld h, d
- ld l, e
- jp CheckKeyItems
-
-.Item ; d276
- ld h, d
- ld l, e
-
-.nope
- jp CheckTheItem
-
-DoesHLEqualNumItems: ; d27b
- ld a, l
- cp NumItems % $100
- ret nz
- ld a, h
- cp NumItems / $100
- ret
-
-GetPocketCapacity: ; d283
- ld c, MAX_ITEMS
- ld a, e
- cp NumItems % $100
- jr nz, .not_bag
- ld a, d
- cp NumItems / $100
- ret z
-
-.not_bag
- ld c, MAX_PC_ITEMS
- ld a, e
- cp PCItems % $100
- jr nz, .not_pc
- ld a, d
- cp PCItems / $100
- ret z
-
-.not_pc
- ld c, MAX_BALLS
- ret
-
-PutItemInPocket: ; d29c
- ld d, h
- ld e, l
- inc hl
- ld a, [CurItem]
- ld c, a
- ld b, 0
-.loop
- ld a, [hli]
- cp -1
- jr z, .terminator
- cp c
- jr nz, .next
- ld a, 99
- sub [hl]
- add b
- ld b, a
- ld a, [wItemQuantityChangeBuffer]
- cp b
- jr z, .ok
- jr c, .ok
-
-.next
- inc hl
- jr .loop
-
-.terminator
- call GetPocketCapacity
- ld a, [de]
- cp c
- jr c, .ok
- and a
- ret
-
-.ok
- ld h, d
- ld l, e
- ld a, [CurItem]
- ld c, a
- ld a, [wItemQuantityChangeBuffer]
- ld [wItemQuantityBuffer], a
-.loop2
- inc hl
- ld a, [hli]
- cp -1
- jr z, .terminator2
- cp c
- jr nz, .loop2
- ld a, [wItemQuantityBuffer]
- add [hl]
- cp 100
- jr nc, .newstack
- ld [hl], a
- jr .done
-
-.newstack
- ld [hl], 99
- sub 99
- ld [wItemQuantityBuffer], a
- jr .loop2
-
-.terminator2
- dec hl
- ld a, [CurItem]
- ld [hli], a
- ld a, [wItemQuantityBuffer]
- ld [hli], a
- ld [hl], -1
- ld h, d
- ld l, e
- inc [hl]
-
-.done
- scf
- ret
-
-RemoveItemFromPocket: ; d2ff
- ld d, h
- ld e, l
- ld a, [hli]
- ld c, a
- ld a, [CurItemQuantity]
- cp c
- jr nc, .ok ; memory
- ld c, a
- ld b, $0
- add hl, bc
- add hl, bc
- ld a, [CurItem]
- cp [hl]
- inc hl
- jr z, .skip
- ld h, d
- ld l, e
- inc hl
-
-.ok
- ld a, [CurItem]
- ld b, a
-.loop
- ld a, [hli]
- cp b
- jr z, .skip
- cp -1
- jr z, .nope
- inc hl
- jr .loop
-
-.skip
- ld a, [wItemQuantityChangeBuffer]
- ld b, a
- ld a, [hl]
- sub b
- jr c, .nope
- ld [hl], a
- ld [wItemQuantityBuffer], a
- and a
- jr nz, .yup
- dec hl
- ld b, h
- ld c, l
- inc hl
- inc hl
-.loop2
- ld a, [hli]
- ld [bc], a
- inc bc
- cp -1
- jr nz, .loop2
- ld h, d
- ld l, e
- dec [hl]
-
-.yup
- scf
- ret
-
-.nope
- and a
- ret
-
-CheckTheItem: ; d349
- ld a, [CurItem]
- ld c, a
-.loop
- inc hl
- ld a, [hli]
- cp -1
- jr z, .done
- cp c
- jr nz, .loop
- scf
- ret
-
-.done
- and a
- ret
-
-ReceiveKeyItem: ; d35a
- ld hl, NumKeyItems
- ld a, [hli]
- cp MAX_KEY_ITEMS
- jr nc, .nope
- ld c, a
- ld b, 0
- add hl, bc
- ld a, [CurItem]
- ld [hli], a
- ld [hl], -1
- ld hl, NumKeyItems
- inc [hl]
- scf
- ret
-
-.nope
- and a
- ret
-
-TossKeyItem: ; d374
- ld a, [wd107]
- ld e, a
- ld d, 0
- ld hl, NumKeyItems
- ld a, [hl]
- cp e
- jr nc, .ok
- call .Toss
- ret nc
- jr .ok2
-
-.ok
- dec [hl]
- inc hl
- add hl, de
-
-.ok2
- ld d, h
- ld e, l
- inc hl
-.loop
- ld a, [hli]
- ld [de], a
- inc de
- cp -1
- jr nz, .loop
- scf
- ret
-
-.Toss: ; d396
- ld hl, NumKeyItems
- ld a, [CurItem]
- ld c, a
-.loop3
- inc hl
- ld a, [hl]
- cp c
- jr z, .ok3
- cp -1
- jr nz, .loop3
- xor a
- ret
-
-.ok3
- ld a, [NumKeyItems]
- dec a
- ld [NumKeyItems], a
- scf
- ret
-
-CheckKeyItems: ; d3b1
- ld a, [CurItem]
- ld c, a
- ld hl, KeyItems
-.loop
- ld a, [hli]
- cp c
- jr z, .done
- cp -1
- jr nz, .loop
- and a
- ret
-
-.done
- scf
- ret
-
-ReceiveTMHM: ; d3c4
- dec c
- ld b, 0
- ld hl, TMsHMs
- add hl, bc
- ld a, [wItemQuantityChangeBuffer]
- add [hl]
- cp 100
- jr nc, .toomany
- ld [hl], a
- scf
- ret
-
-.toomany
- and a
- ret
-
-TossTMHM: ; d3d8
- dec c
- ld b, 0
- ld hl, TMsHMs
- add hl, bc
- ld a, [wItemQuantityChangeBuffer]
- ld b, a
- ld a, [hl]
- sub b
- jr c, .nope
- ld [hl], a
- ld [wItemQuantityBuffer], a
- jr nz, .yup
- ld a, [wTMHMPocketScrollPosition]
- and a
- jr z, .yup
- dec a
- ld [wTMHMPocketScrollPosition], a
-
-.yup
- scf
- ret
-
-.nope
- and a
- ret
-
-CheckTMHM: ; d3fb
- dec c
- ld b, $0
- ld hl, TMsHMs
- add hl, bc
- ld a, [hl]
- and a
- ret z
- scf
- ret
-
-GetTMHMNumber:: ; d407
-; Return the number of a TM/HM by item id c.
-
- ld a, c
-
-; Skip any dummy items.
- cp ITEM_C3 ; TM04-05
- jr c, .done
- cp ITEM_DC ; TM28-29
- jr c, .skip
-
- dec a
-.skip
- dec a
-.done
- sub TM01
- inc a
- ld c, a
- ret
-
-GetNumberedTMHM: ; d417
-; Return the item id of a TM/HM by number c.
-
- ld a, c
-
-; Skip any gaps.
- cp ITEM_C3 - (TM01 - 1)
- jr c, .done
- cp ITEM_DC - (TM01 - 1) - 1
- jr c, .skip_one
-
-.skip_two
- inc a
-.skip_one
- inc a
-.done
- add TM01
- dec a
- ld c, a
- ret
-
-_CheckTossableItem:: ; d427
-; Return 1 in wItemAttributeParamBuffer and carry if CurItem can't be removed from the bag.
- ld a, ITEMATTR_PERMISSIONS
- call GetItemAttr
- bit 7, a
- jr nz, ItemAttr_ReturnCarry
- and a
- ret
-
-CheckSelectableItem: ; d432
-; Return 1 in wItemAttributeParamBuffer and carry if CurItem can't be selected.
- ld a, ITEMATTR_PERMISSIONS
- call GetItemAttr
- bit 6, a
- jr nz, ItemAttr_ReturnCarry
- and a
- ret
-
-CheckItemPocket:: ; d43d
-; Return the pocket for CurItem in wItemAttributeParamBuffer.
- ld a, ITEMATTR_POCKET
- call GetItemAttr
- and $f
- ld [wItemAttributeParamBuffer], a
- ret
-
-CheckItemContext: ; d448
-; Return the context for CurItem in wItemAttributeParamBuffer.
- ld a, ITEMATTR_HELP
- call GetItemAttr
- and $f
- ld [wItemAttributeParamBuffer], a
- ret
-
-CheckItemMenu: ; d453
-; Return the menu for CurItem in wItemAttributeParamBuffer.
- ld a, ITEMATTR_HELP
- call GetItemAttr
- swap a
- and $f
- ld [wItemAttributeParamBuffer], a
- ret
-
-GetItemAttr: ; d460
-; Get attribute a of CurItem.
-
- push hl
- push bc
-
- ld hl, ItemAttributes
- ld c, a
- ld b, 0
- add hl, bc
-
- xor a
- ld [wItemAttributeParamBuffer], a
-
- ld a, [CurItem]
- dec a
- ld c, a
- ld a, NUM_ITEMATTRS
- call AddNTimes
- ld a, BANK(ItemAttributes)
- call GetFarByte
-
- pop bc
- pop hl
- ret
-
-ItemAttr_ReturnCarry: ; d47f
- ld a, 1
- ld [wItemAttributeParamBuffer], a
- scf
- ret
-
-GetItemPrice: ; d486
-; Return the price of CurItem in de.
- push hl
- push bc
- ld a, ITEMATTR_PRICE
- call GetItemAttr
- ld e, a
- ld a, ITEMATTR_PRICE_HI
- call GetItemAttr
- ld d, a
- pop bc
- pop hl
- ret
-
+INCLUDE "engine/printnum.asm"
+INCLUDE "engine/health.asm"
+INCLUDE "event/overworld.asm"
+INCLUDE "engine/items.asm"
INCLUDE "engine/player_step.asm"
INCLUDE "engine/anim_hp_bar.asm"
INCLUDE "engine/move_mon.asm"
-
-_BillsPC: ; e3fd
- call .CheckCanUsePC
- ret c
- call .LogIn
- call .UseBillsPC
- jp .LogOut
-
-.CheckCanUsePC: ; e40a (3:640a)
- ld a, [PartyCount]
- and a
- ret nz
- ld hl, .Text_GottaHavePokemon
- call MenuTextBoxBackup
- scf
- ret
-
-.Text_GottaHavePokemon: ; 0xe417
- ; You gotta have #MON to call!
- text_jump UnknownText_0x1c1006
- db "@"
-
-.LogIn: ; e41c (3:641c)
- xor a
- ld [hBGMapMode], a
- call LoadStandardMenuDataHeader
- call ClearPCItemScreen
- ld hl, Options
- ld a, [hl]
- push af
- set NO_TEXT_SCROLL, [hl]
- ld hl, .Text_What
- call PrintText
- pop af
- ld [Options], a
- call LoadFontsBattleExtra
- ret
-
-.Text_What: ; 0xe43a
- ; What?
- text_jump UnknownText_0x1c1024
- db "@"
-
-.LogOut: ; e43f (3:643f)
- call CloseSubmenu
- ret
-
-.UseBillsPC: ; e443 (3:6443)
- ld hl, .MenuDataHeader
- call LoadMenuDataHeader
- ld a, $1
-.loop
- ld [wMenuCursorBuffer], a
- call SetPalettes
- xor a
- ld [wWhichIndexSet], a
- ld [hBGMapMode], a
- call DoNthMenu
- jr c, .cancel
- ld a, [wMenuCursorBuffer]
- push af
- ld a, [MenuSelection]
- ld hl, .Jumptable
- rst JumpTable
- pop bc
- ld a, b
- jr nc, .loop
-.cancel
- call CloseWindow
- ret
-
-.MenuDataHeader: ; 0xe46f
- db $40 ; flags
- db 00, 00 ; start coords
- db 17, 19 ; end coords
- dw .MenuData2
- db 1 ; default option
-
-.MenuData2: ; 0xe477
- db $80 ; flags
- db 0 ; items
- dw .items
- dw PlaceMenuStrings
- dw .strings
-
-.strings: ; e47f
- db "WITHDRAW <PK><MN>@"
- db "DEPOSIT <PK><MN>@"
- db "CHANGE BOX@"
- db "MOVE <PK><MN> W/O MAIL@"
- db "SEE YA!@"
-
-.Jumptable: ; e4ba (3:64ba)
- dw BillsPC_WithdrawMenu
- dw BillsPC_DepositMenu
- dw BillsPC_ChangeBoxMenu
- dw BillsPC_MovePKMNMenu
- dw BillsPC_SeeYa
-
-.items: ; e4c4
- db 5
- db 0 ; WITHDRAW
- db 1; DEPOSIT
- db 2 ; CHANGE BOX
- db 3 ; MOVE PKMN
- db 4 ; SEE YA!
- db -1
-
-BillsPC_SeeYa: ; e4cb
- scf
- ret
-
-BillsPC_MovePKMNMenu: ; e4cd
- call LoadStandardMenuDataHeader
- callba IsAnyMonHoldingMail
- jr nc, .no_mail
- ld hl, .Text_MonHoldingMail
- call PrintText
- jr .quit
-
-.no_mail
- callba StartMovePkmnWOMail_SaveGame
- jr c, .quit
- callba _MovePKMNWithoutMail
- call ReturnToMapFromSubmenu
- call ClearPCItemScreen
-
-.quit
- call CloseWindow
- and a
- ret
-
-.Text_MonHoldingMail: ; 0xe4f9
- ; There is a #MON holding MAIL. Please remove the MAIL.
- text_jump UnknownText_0x1c102b
- db "@"
-
-BillsPC_DepositMenu: ; e4fe (3:64fe)
- call LoadStandardMenuDataHeader
- callba _DepositPKMN
- call ReturnToMapFromSubmenu
- call ClearPCItemScreen
- call CloseWindow
- and a
- ret
-
-Functione512: ; unused
- ld a, [PartyCount]
- and a
- jr z, .no_pkmn
- cp 2
- jr c, .only_one_pkmn
- and a
- ret
-
-.no_pkmn
- ld hl, .Text_NoPKMN
- call MenuTextBoxBackup
- scf
- ret
-
-.only_one_pkmn
- ld hl, .Text_ItsYourLastPKMN
- call MenuTextBoxBackup
- scf
- ret
-
-.Text_NoPKMN: ; 0xe52e
- ; You don't have a single #MON!
- text_jump UnknownText_0x1c1062
- db "@"
-
-.Text_ItsYourLastPKMN: ; 0xe533
- ; You can't deposit your last #MON!
- text_jump UnknownText_0x1c1080
- db "@"
-
-CheckCurPartyMonFainted: ; e538
- ld hl, PartyMon1HP
- ld de, PARTYMON_STRUCT_LENGTH
- ld b, $0
-.loop
- ld a, [CurPartyMon]
- cp b
- jr z, .skip
- ld a, [hli]
- or [hl]
- jr nz, .notfainted
- dec hl
-
-.skip
- inc b
- ld a, [PartyCount]
- cp b
- jr z, .done
- add hl, de
- jr .loop
-
-.done
- scf
- ret
-
-.notfainted
- and a
- ret
-
-BillsPC_WithdrawMenu: ; e559 (3:6559)
- call LoadStandardMenuDataHeader
- callba _WithdrawPKMN
- call ReturnToMapFromSubmenu
- call ClearPCItemScreen
- call CloseWindow
- and a
- ret
-
-Functione56d: ; unused
- ld a, [PartyCount]
- cp PARTY_LENGTH
- jr nc, .asm_e576
- and a
- ret
-
-.asm_e576
- ld hl, UnknownText_0xe57e
- call MenuTextBoxBackup
- scf
- ret
-
-UnknownText_0xe57e: ; 0xe57e
- ; You can't take any more #MON.
- text_jump UnknownText_0x1c10a2
- db "@"
-
-BillsPC_ChangeBoxMenu: ; e583 (3:6583)
- callba _ChangeBox
- and a
- ret
-
-ClearPCItemScreen: ; e58b
- call DisableSpriteUpdates
- xor a
- ld [hBGMapMode], a
- call ClearBGPalettes
- call ClearSprites
- hlcoord 0, 0
- ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
- ld a, " "
- call ByteFill
- hlcoord 0,0
- lb bc, 10, 18
- call TextBox
- hlcoord 0,12
- lb bc, 4, 18
- call TextBox
- call WaitBGMap2
- call SetPalettes ; load regular palettes?
- ret
-
-CopyBoxmonToTempMon: ; e5bb
- ld a, [CurPartyMon]
- ld hl, sBoxMon1Species
- ld bc, BOXMON_STRUCT_LENGTH
- call AddNTimes
- ld de, TempMonSpecies
- ld bc, BOXMON_STRUCT_LENGTH
- ld a, BANK(sBoxMon1Species)
- call GetSRAMBank
- call CopyBytes
- call CloseSRAM
- ret
-
-Functione5d9: ; unreferenced
- ld a, [wCurBox]
- cp b
- jr z, .same_box
- ld a, b
- ld hl, .BoxAddrs
- ld bc, 3
- call AddNTimes
- ld a, [hli]
- push af
- ld a, [hli]
- ld h, [hl]
- ld l, a
- pop af
- jr .okay
-
-.same_box
- ld a, BANK(sBoxCount)
- ld hl, sBoxCount
-
-.okay
- call GetSRAMBank
- ld a, [hl]
- ld bc, 1 + MONS_PER_BOX + 1
- add hl, bc
- ld b, a
- ld c, $0
- ld de, wc608
- ld a, b
- and a
- jr z, .empty_box
-.loop
- push hl
- push bc
- ld a, c
- ld bc, 0
- add hl, bc
- ld bc, BOXMON_STRUCT_LENGTH
- call AddNTimes
- ld a, [hl]
- ld [de], a
- inc de
- ld [CurSpecies], a
- call GetBaseData
- pop bc
- pop hl
-
- push hl
- push bc
- ld a, c
- ld bc, MONS_PER_BOX * (BOXMON_STRUCT_LENGTH + NAME_LENGTH)
- add hl, bc
- call SkipNames
- call CopyBytes
- pop bc
- pop hl
-
- push hl
- push bc
- ld a, c
- ld bc, MON_LEVEL
- add hl, bc
- ld bc, BOXMON_STRUCT_LENGTH
- call AddNTimes
- ld a, [hl]
- ld [de], a
- inc de
- pop bc
- pop hl
-
- push hl
- push bc
- ld a, c
- ld bc, MON_DVS
- add hl, bc
- ld bc, BOXMON_STRUCT_LENGTH
- call AddNTimes
- ld a, [hli]
- and $f0
- ld b, a
- ld a, [hl]
- and $f0
- swap a
- or b
- ld b, a
- ld a, [BaseGender]
- cp b
- ld a, $1
- jr c, .okay2
- xor a
-.okay2
- ld [de], a
- inc de
- pop bc
- pop hl
-
- inc c
- dec b
- jr nz, .loop
-.empty_box
- call CloseSRAM
- ret
-
-.BoxAddrs: ; e66e
- dba sBox1
- dba sBox2
- dba sBox3
- dba sBox4
- dba sBox5
- dba sBox6
- dba sBox7
- dba sBox8
- dba sBox9
- dba sBox10
- dba sBox11
- dba sBox12
- dba sBox13
- dba sBox14
+INCLUDE "engine/billspctop.asm"
GetBreedMon1LevelGrowth: ; e698
ld hl, wBreedMon1Stats
@@ -5002,95 +353,6 @@ BugContest_SetCaughtContestMon: ; e6ce
INCLUDE "items/item_effects.asm"
-GetPokeBallWobble: ; f971 (3:7971)
-; Returns whether a Poke Ball will wobble in the catch animation.
-; Whether a Pokemon is caught is determined beforehand.
-
- push de
-
- ld a, [rSVBK]
- ld d, a
- push de
-
- ld a, 1 ; BANK(Buffer2)
- ld [rSVBK], a
-
- ld a, [Buffer2]
- inc a
- ld [Buffer2], a
-
-; Wobble up to 3 times.
- cp 3 + 1
- jr z, .finished
-
- ld a, [wWildMon]
- and a
- ld c, 0 ; next
- jr nz, .done
-
- ld hl, .WobbleProbabilities
- ld a, [Buffer1]
- ld b, a
-.loop
- ld a, [hli]
- cp b
- jr nc, .checkwobble
- inc hl
- jr .loop
-
-.checkwobble
- ld b, [hl]
- call Random
- cp b
- ld c, 0 ; next
- jr c, .done
- ld c, 2 ; escaped
- jr .done
-
-.finished
- ld a, [wWildMon]
- and a
- ld c, 1 ; caught
- jr nz, .done
- ld c, 2 ; escaped
-
-.done
- pop de
- ld e, a
- ld a, d
- ld [rSVBK], a
- ld a, e
- pop de
- ret
-
-.WobbleProbabilities: ; f9ba
-; catch rate, chance of wobbling / 255
-; nLeft/255 = (nRight/255) ** 4
- db 1, 63
- db 2, 75
- db 3, 84
- db 4, 90
- db 5, 95
- db 7, 103
- db 10, 113
- db 15, 126
- db 20, 134
- db 30, 149
- db 40, 160
- db 50, 169
- db 60, 177
- db 80, 191
- db 100, 201
- db 120, 211
- db 140, 220
- db 160, 227
- db 180, 234
- db 200, 240
- db 220, 246
- db 240, 251
- db 254, 253
- db 255, 255
-
KnowsMove: ; f9ea
ld a, MON_MOVES
call GetPartyParamLocation
@@ -6275,7 +1537,7 @@ ShowLinkBattleParticipants: ; 2ee18
call ClearSprites
ret
-FindFirstAliveMon: ; 2ee2f
+FindFirstAliveMonAndStartBattle: ; 2ee2f
xor a
ld [hMapAnims], a
call DelayFrame
@@ -10522,8 +5784,8 @@ Function8c7c9: ; unreferenced
INCLUDE "event/field_moves.asm"
INCLUDE "event/magnet_train.asm"
-Function8cf4f: ; 8cf4f
- call Function3238
+BattleStart_LoadEDTile: ; 8cf4f
+ call CGBOnly_LoadEDTile
ret
INCLUDE "engine/sprites.asm"
diff --git a/maps/BattleTower1F.asm b/maps/BattleTower1F.asm
index ca10518fb..10e8fa51a 100644
--- a/maps/BattleTower1F.asm
+++ b/maps/BattleTower1F.asm
@@ -62,7 +62,7 @@ ReceptionistScript_0x9e3e2:
opentext
writetext Text_BattleTowerWelcomesYou
buttonsound
- writebyte BATTLETOWERACTION_00 ; if new save file: bit 1, [sbe4f]
+ writebyte BATTLETOWERACTION_00 ; if new save file: bit 1, [s1_be4f]
special BattleTowerAction
if_not_equal $0, Script_Menu_ChallengeExplanationCancel
jump Script_BattleTowerIntroductionYesNo
@@ -87,7 +87,7 @@ Script_ChoseChallenge: ; 0x9e40f
special Special_TryQuickSave
iffalse Script_Menu_ChallengeExplanationCancel
dotrigger $1
- writebyte BATTLETOWERACTION_01 ; set 1, [sbe4f]
+ writebyte BATTLETOWERACTION_01 ; set 1, [s1_be4f]
special BattleTowerAction
special Function1700b0
if_equal $a, Script_Menu_ChallengeExplanationCancel
diff --git a/maps/BlackthornGym2F.asm b/maps/BlackthornGym2F.asm
index d77464877..02a4d2234 100644
--- a/maps/BlackthornGym2F.asm
+++ b/maps/BlackthornGym2F.asm
@@ -23,8 +23,8 @@ BlackthornGym2F_MapScriptHeader:
return
.BoulderCmdQueue
- dbw MAPCALLBACK_OBJECTS, .BoulderTable ; check if any stones are sitting on a warp
- db 0, 0 ; filler
+ dbw CMDQUEUE_STONETABLE, .BoulderTable ; check if any stones are sitting on a warp
+ dw 0 ; filler
.BoulderTable
stonetable 5, BLACKTHORNGYM2F_BOULDER1, .Disappear4
@@ -137,9 +137,9 @@ BlackthornGym2F_MapEventHeader:
db 5
warp_def $7, $1, 3, BLACKTHORN_GYM_1F
warp_def $9, $7, 4, BLACKTHORN_GYM_1F
- warp_def $5, $2, 5, BLACKTHORN_GYM_1F
- warp_def $7, $8, 6, BLACKTHORN_GYM_1F
- warp_def $3, $8, 7, BLACKTHORN_GYM_1F
+ warp_def $5, $2, 5, BLACKTHORN_GYM_1F ; hole
+ warp_def $7, $8, 6, BLACKTHORN_GYM_1F ; hole
+ warp_def $3, $8, 7, BLACKTHORN_GYM_1F ; hole
.XYTriggers:
db 0
diff --git a/maps/BurnedTowerB1F.asm b/maps/BurnedTowerB1F.asm
index 0991a2ecb..5de04e591 100644
--- a/maps/BurnedTowerB1F.asm
+++ b/maps/BurnedTowerB1F.asm
@@ -130,53 +130,53 @@ BurnedTowerB1FBoulder:
jumpstd strengthboulder
BurnedTowerRaikouMovement:
- db $39 ; movement
+ set_sliding
fast_jump_step_down
fast_jump_step_left
- db $38 ; movement
+ remove_sliding
step_end
BurnedTowerEnteiMovement:
- db $39 ; movement
+ set_sliding
fast_jump_step_right
fast_jump_step_down
fast_jump_step_right
- db $38 ; movement
+ remove_sliding
step_end
BurnedTowerSuicuneMovement1:
- db $39 ; movement
+ set_sliding
fast_jump_step_right
fast_jump_step_down
fast_jump_step_down
fast_jump_step_left
- db $38 ; movement
+ remove_sliding
step_end
BurnedTowerSuicuneMovement2:
- db $39 ; movement
+ set_sliding
fast_jump_step_left
fast_jump_step_up
big_step_up
fast_jump_step_right
- db $38 ; movement
+ remove_sliding
step_end
MovementData_0x18624f:
- db $39 ; movement
+ set_sliding
big_step_down
- db $38 ; movement
+ remove_sliding
step_end
BurnedTowerSuicuneMovement3:
- db $39 ; movement
+ set_sliding
big_step_up
fast_jump_step_right
fast_jump_step_down
fast_jump_step_down
fast_jump_step_down
fast_jump_step_down
- db $38 ; movement
+ remove_sliding
step_end
BurnedTowerB1FEusineMovement2:
diff --git a/maps/CianwoodGym.asm b/maps/CianwoodGym.asm
index 3d0a87751..afeb908de 100644
--- a/maps/CianwoodGym.asm
+++ b/maps/CianwoodGym.asm
@@ -21,31 +21,31 @@ ChuckScript_0x9d60f:
opentext
checkevent EVENT_BEAT_CHUCK
iftrue .FightDone
- writetext UnknownText_0x9d6f9
+ writetext ChuckIntroText1
waitbutton
closetext
spriteface CIANWOODGYM_CHUCK, RIGHT
opentext
- writetext UnknownText_0x9d76f
+ writetext ChuckIntroText2
waitbutton
closetext
- applymovement CIANWOODGYM_BOULDER1, MovementData_0x9d6f3
+ applymovement CIANWOODGYM_BOULDER1, CianwoodGymMovement_ChuckChucksBoulder
playsound SFX_STRENGTH
earthquake 80
disappear CIANWOODGYM_BOULDER1
pause 30
faceplayer
opentext
- writetext UnknownText_0x9d78a
+ writetext ChuckIntroText3
waitbutton
closetext
- winlosstext UnknownText_0x9d7f6, 0
+ winlosstext ChuckLossText, 0
loadtrainer CHUCK, 1
startbattle
reloadmapafterbattle
setevent EVENT_BEAT_CHUCK
opentext
- writetext UnknownText_0x9d835
+ writetext GetStormBadgeText
playsound SFX_GET_BADGE
waitsfx
setflag ENGINE_STORMBADGE
@@ -53,25 +53,25 @@ ChuckScript_0x9d60f:
scall CianwoodGymTriggerRockets
.FightDone
checkevent EVENT_GOT_TM01_DYNAMICPUNCH
- iftrue UnknownScript_0x9d67b
+ iftrue .AlreadyGotTM
setevent EVENT_BEAT_BLACKBELT_YOSHI
setevent EVENT_BEAT_BLACKBELT_LAO
setevent EVENT_BEAT_BLACKBELT_NOB
setevent EVENT_BEAT_BLACKBELT_LUNG
- writetext UnknownText_0x9d84d
+ writetext ChuckExplainBadgeText
buttonsound
verbosegiveitem TM_DYNAMICPUNCH
- iffalse UnknownScript_0x9d67f
+ iffalse .BagFull
setevent EVENT_GOT_TM01_DYNAMICPUNCH
- writetext UnknownText_0x9d8da
+ writetext ChuckExplainTMText
waitbutton
closetext
end
-UnknownScript_0x9d67b:
- writetext UnknownText_0x9d930
+.AlreadyGotTM:
+ writetext ChuckAfterText
waitbutton
-UnknownScript_0x9d67f:
+.BagFull:
closetext
end
@@ -87,45 +87,45 @@ CianwoodGymTriggerRockets:
jumpstd radiotowerrockets
TrainerBlackbeltYoshi:
- trainer EVENT_BEAT_BLACKBELT_YOSHI, BLACKBELT_T, YOSHI, BlackbeltYoshiSeenText, BlackbeltYoshiBeatenText, 0, BlackbeltYoshiScript
+ trainer EVENT_BEAT_BLACKBELT_YOSHI, BLACKBELT_T, YOSHI, BlackbeltYoshiSeenText, BlackbeltYoshiBeatenText, 0, .Script
-BlackbeltYoshiScript:
+.Script:
end_if_just_battled
opentext
- writetext UnknownText_0x9d9fa
+ writetext BlackbeltYoshiAfterText
waitbutton
closetext
end
TrainerBlackbeltLao:
- trainer EVENT_BEAT_BLACKBELT_LAO, BLACKBELT_T, LAO, BlackbeltLaoSeenText, BlackbeltLaoBeatenText, 0, BlackbeltLaoScript
+ trainer EVENT_BEAT_BLACKBELT_LAO, BLACKBELT_T, LAO, BlackbeltLaoSeenText, BlackbeltLaoBeatenText, 0, .Script
-BlackbeltLaoScript:
+.Script:
end_if_just_battled
opentext
- writetext UnknownText_0x9da61
+ writetext BlackbeltLaoAfterText
waitbutton
closetext
end
TrainerBlackbeltNob:
- trainer EVENT_BEAT_BLACKBELT_NOB, BLACKBELT_T, NOB, BlackbeltNobSeenText, BlackbeltNobBeatenText, 0, BlackbeltNobScript
+ trainer EVENT_BEAT_BLACKBELT_NOB, BLACKBELT_T, NOB, BlackbeltNobSeenText, BlackbeltNobBeatenText, 0, .Script
-BlackbeltNobScript:
+.Script:
end_if_just_battled
opentext
- writetext UnknownText_0x9dac0
+ writetext BlackbeltNobAfterText
waitbutton
closetext
end
TrainerBlackbeltLung:
- trainer EVENT_BEAT_BLACKBELT_LUNG, BLACKBELT_T, LUNG, BlackbeltLungSeenText, BlackbeltLungBeatenText, 0, BlackbeltLungScript
+ trainer EVENT_BEAT_BLACKBELT_LUNG, BLACKBELT_T, LUNG, BlackbeltLungSeenText, BlackbeltLungBeatenText, 0, .Script
-BlackbeltLungScript:
+.Script:
end_if_just_battled
opentext
- writetext UnknownText_0x9db14
+ writetext BlackbeltLungAfterText
waitbutton
closetext
end
@@ -141,15 +141,15 @@ CianwoodGymStatue:
trainertotext CHUCK, 1, $1
jumpstd gymstatue2
-MovementData_0x9d6f3:
- db $39 ; movement
+CianwoodGymMovement_ChuckChucksBoulder:
+ set_sliding
big_step_left
big_step_up
fast_jump_step_right
- db $38 ; movement
+ remove_sliding
step_end
-UnknownText_0x9d6f9:
+ChuckIntroText1:
text "WAHAHAH!"
para "So you've come"
@@ -165,14 +165,14 @@ UnknownText_0x9d6f9:
para "Watch this!"
done
-UnknownText_0x9d76f:
+ChuckIntroText2:
text "CHUCK: Urggh!"
line "…"
para "Oooarrgh!"
done
-UnknownText_0x9d78a:
+ChuckIntroText3:
text "There! Scared now,"
line "are you?"
@@ -186,7 +186,7 @@ UnknownText_0x9d78a:
line "do battle!"
done
-UnknownText_0x9d7f6:
+ChuckLossText:
text "Wha? Huh?"
line "I lost?"
@@ -195,12 +195,12 @@ UnknownText_0x9d7f6:
cont "STORMBADGE!"
done
-UnknownText_0x9d835:
+GetStormBadgeText:
text "<PLAYER> received"
line "STORMBADGE."
done
-UnknownText_0x9d84d:
+ChuckExplainBadgeText:
text "STORMBADGE makes"
line "all #MON up to"
@@ -217,7 +217,7 @@ UnknownText_0x9d84d:
line "too!"
done
-UnknownText_0x9d8da:
+ChuckExplainTMText:
text "That is DYNAMIC-"
line "PUNCH."
@@ -228,7 +228,7 @@ UnknownText_0x9d8da:
line "confusion!"
done
-UnknownText_0x9d930:
+ChuckAfterText:
text "WAHAHAH! I enjoyed"
line "battling you!"
@@ -253,7 +253,7 @@ BlackbeltYoshiBeatenText:
text "This isn't real!"
done
-UnknownText_0x9d9fa:
+BlackbeltYoshiAfterText:
text "You seem to have a"
line "strong bond with"
cont "your #MON too!"
@@ -268,7 +268,7 @@ BlackbeltLaoBeatenText:
text "That's shocking!"
done
-UnknownText_0x9da61:
+BlackbeltLaoAfterText:
text "Fighting #MON"
line "are afraid of psy-"
cont "chics…"
@@ -284,7 +284,7 @@ BlackbeltNobBeatenText:
text "…"
done
-UnknownText_0x9dac0:
+BlackbeltNobAfterText:
text "I lost! "
line "I'm speechless!"
done
@@ -299,7 +299,7 @@ BlackbeltLungBeatenText:
text "I got shattered!"
done
-UnknownText_0x9db14:
+BlackbeltLungAfterText:
text "My #MON lost…"
line "My… my pride is"
cont "shattered…"
diff --git a/maps/IcePathB1F.asm b/maps/IcePathB1F.asm
index 9e9390f67..afac65352 100644
--- a/maps/IcePathB1F.asm
+++ b/maps/IcePathB1F.asm
@@ -21,8 +21,8 @@ IcePathB1F_MapScriptHeader:
return
.CommandQueue:
- dbw MAPCALLBACK_OBJECTS, .StoneTable ; check if any stones are sitting on a warp
- db 0, 0 ; filler
+ dbw CMDQUEUE_STONETABLE, .StoneTable ; check if any stones are sitting on a warp
+ dw 0 ; filler
.StoneTable:
stonetable 3, ICEPATHB1F_BOULDER1, .Boulder1
@@ -90,10 +90,10 @@ IcePathB1F_MapEventHeader:
db 8
warp_def $f, $3, 3, ICE_PATH_1F
warp_def $3, $11, 1, ICE_PATH_B2F_MAHOGANY_SIDE
- warp_def $2, $b, 3, ICE_PATH_B2F_MAHOGANY_SIDE
- warp_def $7, $4, 4, ICE_PATH_B2F_MAHOGANY_SIDE
- warp_def $c, $5, 5, ICE_PATH_B2F_MAHOGANY_SIDE
- warp_def $d, $c, 6, ICE_PATH_B2F_MAHOGANY_SIDE
+ warp_def $2, $b, 3, ICE_PATH_B2F_MAHOGANY_SIDE ; hole
+ warp_def $7, $4, 4, ICE_PATH_B2F_MAHOGANY_SIDE ; hole
+ warp_def $c, $5, 5, ICE_PATH_B2F_MAHOGANY_SIDE ; hole
+ warp_def $d, $c, 6, ICE_PATH_B2F_MAHOGANY_SIDE ; hole
warp_def $19, $5, 4, ICE_PATH_1F
warp_def $1b, $b, 1, ICE_PATH_B2F_BLACKTHORN_SIDE
diff --git a/maps/LancesRoom.asm b/maps/LancesRoom.asm
index 6188ac56d..a3c9018e2 100644
--- a/maps/LancesRoom.asm
+++ b/maps/LancesRoom.asm
@@ -8,36 +8,36 @@ LancesRoom_MapScriptHeader:
db 2
; triggers
- dw UnknownScript_0x180e39, 0
- dw UnknownScript_0x180e3d, 0
+ dw .Trigger0, 0
+ dw .Trigger1, 0
.MapCallbacks:
db 1
; callbacks
- dbw MAPCALLBACK_TILES, UnknownScript_0x180e3e
+ dbw MAPCALLBACK_TILES, .CheckDoor
-UnknownScript_0x180e39:
- priorityjump UnknownScript_0x180e53
+.Trigger0:
+ priorityjump LancesRoom_PlayerWalksIn_DoorsCloseBehind
end
-UnknownScript_0x180e3d:
+.Trigger1:
end
-UnknownScript_0x180e3e:
+.CheckDoor:
checkevent EVENT_LANCES_ROOM_ENTRANCE_CLOSED
- iffalse UnknownScript_0x180e48
+ iffalse .LanceEntranceOpen
changeblock $4, $16, $34
-UnknownScript_0x180e48:
+.LanceEntranceOpen:
checkevent EVENT_LANCES_ROOM_EXIT_OPEN
- iffalse UnknownScript_0x180e52
+ iffalse .LanceExitClosed
changeblock $4, $0, $b
-UnknownScript_0x180e52:
+.LanceExitClosed:
return
-UnknownScript_0x180e53:
- applymovement PLAYER, MovementData_0x180f33
+LancesRoom_PlayerWalksIn_DoorsCloseBehind:
+ applymovement PLAYER, LancesRoom_PlayerWalksInMovementData
refreshscreen $86
playsound SFX_STRENGTH
earthquake 80
@@ -48,21 +48,21 @@ UnknownScript_0x180e53:
setevent EVENT_LANCES_ROOM_ENTRANCE_CLOSED
end
-UnknownScript_0x180e6a:
+Script_ApproachLanceFromLeft:
special Special_FadeOutMusic
- applymovement PLAYER, MovementData_0x180f38
+ applymovement PLAYER, MovementData_ApproachLanceFromLeft
jump LanceScript_0x180e7b
-UnknownScript_0x180e74:
+Script_ApproachLanceFromRight:
special Special_FadeOutMusic
- applymovement PLAYER, MovementData_0x180f3c
+ applymovement PLAYER, MovementData_ApproachLanceFromRight
LanceScript_0x180e7b:
spriteface LANCESROOM_LANCE, LEFT
opentext
- writetext UnknownText_0x180f67
+ writetext LanceBattleIntroText
waitbutton
closetext
- winlosstext UnknownText_0x1810a4, 0
+ winlosstext LanceBattleWinText, 0
setlasttalked LANCESROOM_LANCE
loadtrainer CHAMPION, LANCE
startbattle
@@ -70,7 +70,7 @@ LanceScript_0x180e7b:
reloadmapafterbattle
setevent EVENT_BEAT_CHAMPION_LANCE
opentext
- writetext UnknownText_0x181132
+ writetext LanceBattleAfterText
waitbutton
closetext
playsound SFX_ENTER_DOOR
@@ -85,15 +85,15 @@ LanceScript_0x180e7b:
pause 10
spriteface PLAYER, DOWN
appear LANCESROOM_MARY
- applymovement LANCESROOM_MARY, MovementData_0x180f41
+ applymovement LANCESROOM_MARY, LancesRoomMovementData_MaryRushesIn
opentext
writetext UnknownText_0x1811dd
waitbutton
closetext
appear LANCESROOM_OAK
- applymovement LANCESROOM_OAK, MovementData_0x180f46
+ applymovement LANCESROOM_OAK, LancesRoomMovementData_OakWalksIn
follow LANCESROOM_MARY, LANCESROOM_OAK
- applymovement LANCESROOM_MARY, MovementData_0x180f49
+ applymovement LANCESROOM_MARY, LancesRoomMovementData_MaryYieldsToOak
stopfollow
spriteface LANCESROOM_OAK, UP
spriteface LANCESROOM_LANCE, LEFT
@@ -101,13 +101,13 @@ LanceScript_0x180e7b:
writetext UnknownText_0x18121b
waitbutton
closetext
- applymovement LANCESROOM_MARY, MovementData_0x180f4c
+ applymovement LANCESROOM_MARY, LancesRoomMovementData_MaryInterviewChampion
spriteface PLAYER, LEFT
opentext
writetext UnknownText_0x18134b
waitbutton
closetext
- applymovement LANCESROOM_LANCE, MovementData_0x180f4f
+ applymovement LANCESROOM_LANCE, LancesRoomMovementData_LancePositionsSelfToGuidePlayerAway
spriteface PLAYER, UP
opentext
writetext UnknownText_0x18137b
@@ -116,88 +116,88 @@ LanceScript_0x180e7b:
follow LANCESROOM_LANCE, PLAYER
spriteface LANCESROOM_MARY, UP
spriteface LANCESROOM_OAK, UP
- applymovement LANCESROOM_LANCE, MovementData_0x180f53
+ applymovement LANCESROOM_LANCE, LancesRoomMovementData_LanceLeadsPlayerToHallOfFame
stopfollow
playsound SFX_EXIT_BUILDING
disappear LANCESROOM_LANCE
- applymovement PLAYER, MovementData_0x180f55
+ applymovement PLAYER, LancesRoomMovementData_PlayerExits
playsound SFX_EXIT_BUILDING
disappear PLAYER
- applymovement LANCESROOM_MARY, MovementData_0x180f57
+ applymovement LANCESROOM_MARY, LancesRoomMovementData_MaryTriesToFollow
showemote EMOTE_SHOCK, LANCESROOM_MARY, 15
opentext
writetext UnknownText_0x1813c5
pause 30
closetext
- applymovement LANCESROOM_MARY, MovementData_0x180f5b
+ applymovement LANCESROOM_MARY, LancesRoomMovementData_MaryRunsBackAndForth
special FadeOutPalettes
pause 15
warpfacing UP, HALL_OF_FAME, $4, $d
end
-MovementData_0x180f33:
+LancesRoom_PlayerWalksInMovementData:
step_up
step_up
step_up
step_up
step_end
-MovementData_0x180f38:
+MovementData_ApproachLanceFromLeft:
step_up
step_up
turn_head_right
step_end
-MovementData_0x180f3c:
+MovementData_ApproachLanceFromRight:
step_up
step_left
step_up
turn_head_right
step_end
-MovementData_0x180f41:
+LancesRoomMovementData_MaryRushesIn:
big_step_up
big_step_up
big_step_up
turn_head_down
step_end
-MovementData_0x180f46:
+LancesRoomMovementData_OakWalksIn:
step_up
step_up
step_end
-MovementData_0x180f49:
+LancesRoomMovementData_MaryYieldsToOak:
step_left
turn_head_right
step_end
-MovementData_0x180f4c:
+LancesRoomMovementData_MaryInterviewChampion:
big_step_up
turn_head_right
step_end
-MovementData_0x180f4f:
+LancesRoomMovementData_LancePositionsSelfToGuidePlayerAway:
step_up
step_left
turn_head_down
step_end
-MovementData_0x180f53:
+LancesRoomMovementData_LanceLeadsPlayerToHallOfFame:
step_up
step_end
-MovementData_0x180f55:
+LancesRoomMovementData_PlayerExits:
step_up
step_end
-MovementData_0x180f57:
+LancesRoomMovementData_MaryTriesToFollow:
step_up
step_right
turn_head_up
step_end
-MovementData_0x180f5b:
+LancesRoomMovementData_MaryRunsBackAndForth:
big_step_right
big_step_right
big_step_left
@@ -211,7 +211,7 @@ MovementData_0x180f5b:
turn_head_up
step_end
-UnknownText_0x180f67:
+LanceBattleIntroText:
text "LANCE: I've been"
line "waiting for you."
@@ -243,7 +243,7 @@ UnknownText_0x180f67:
cont "your challenge!"
done
-UnknownText_0x1810a4:
+LanceBattleWinText:
text "…It's over."
para "But it's an odd"
@@ -260,7 +260,7 @@ UnknownText_0x1810a4:
line "CHAMPION!"
done
-UnknownText_0x181132:
+LanceBattleAfterText:
text "…Whew."
para "You have become"
@@ -355,8 +355,8 @@ LancesRoom_MapEventHeader:
.XYTriggers:
db 2
- xy_trigger 1, $5, $4, $0, UnknownScript_0x180e6a, $0, $0
- xy_trigger 1, $5, $5, $0, UnknownScript_0x180e74, $0, $0
+ xy_trigger 1, $5, $4, $0, Script_ApproachLanceFromLeft, $0, $0
+ xy_trigger 1, $5, $5, $0, Script_ApproachLanceFromRight, $0, $0
.Signposts:
db 0
diff --git a/maps/Route36.asm b/maps/Route36.asm
index fb9289f47..8bd05b91d 100644
--- a/maps/Route36.asm
+++ b/maps/Route36.asm
@@ -14,23 +14,23 @@ Route36_MapScriptHeader:
db 2
; triggers
- dw UnknownScript_0x19400d, 0
- dw UnknownScript_0x19400e, 0
+ dw .Trigger0, 0
+ dw .Trigger1, 0
.MapCallbacks:
db 1
; callbacks
- dbw MAPCALLBACK_OBJECTS, ArthurCallback
+ dbw MAPCALLBACK_OBJECTS, .ArthurCallback
-UnknownScript_0x19400d:
+.Trigger0:
end
-UnknownScript_0x19400e:
+.Trigger1:
end
-ArthurCallback:
+.ArthurCallback:
checkcode VAR_WEEKDAY
if_equal THURSDAY, .ArthurAppears
disappear ROUTE36_ARTHUR
@@ -45,7 +45,7 @@ Route36SuicuneScript:
pause 15
playsound SFX_WARP_FROM
spriteface PLAYER, UP
- applymovement ROUTE36_SUICUNE, MovementData_0x194262
+ applymovement ROUTE36_SUICUNE, Route36SuicuneMovement
disappear ROUTE36_SUICUNE
spriteface PLAYER, DOWN
pause 10
@@ -86,7 +86,7 @@ WateredWeirdTreeScript:: ; export (for when you use Squirtbottle from pack)
loadwildmon SUDOWOODO, 20
startbattle
setevent EVENT_FOUGHT_SUDOWOODO
- if_equal $2, UnknownScript_0x19407b
+ if_equal $2, DidntCatchSudowoodo
disappear ROUTE36_WEIRD_TREE
variablesprite SPRITE_WEIRD_TREE, SPRITE_TWIN
reloadmapafterbattle
@@ -96,9 +96,9 @@ DidntUseSquirtbottleScript:
closetext
end
-UnknownScript_0x19407b:
+DidntCatchSudowoodo:
reloadmapafterbattle
- applymovement ROUTE36_WEIRD_TREE, MovementData_0x19424b
+ applymovement ROUTE36_WEIRD_TREE, WeirdTreeMovement_Flee
disappear ROUTE36_WEIRD_TREE
variablesprite SPRITE_WEIRD_TREE, SPRITE_TWIN
special RunCallback_04
@@ -132,28 +132,28 @@ Route36FloriaScript:
closetext
end
-FisherScript_0x1940b9:
+Route36RockSmashGuyScript:
faceplayer
opentext
checkevent EVENT_GOT_TM08_ROCK_SMASH
- iftrue UnknownScript_0x1940da
+ iftrue .AlreadyGotRockSmash
checkevent EVENT_FOUGHT_SUDOWOODO
- iftrue UnknownScript_0x1940cd
- writetext UnknownText_0x19446f
+ iftrue .ClearedSudowoodo
+ writetext RockSmashGuyText1
waitbutton
closetext
end
-UnknownScript_0x1940cd:
- writetext UnknownText_0x1944d0
+.ClearedSudowoodo:
+ writetext RockSmashGuyText2
buttonsound
verbosegiveitem TM_ROCK_SMASH
- iffalse UnknownScript_0x1940de
+ iffalse .NoRoomForTM
setevent EVENT_GOT_TM08_ROCK_SMASH
-UnknownScript_0x1940da:
- writetext UnknownText_0x19452c
+.AlreadyGotRockSmash:
+ writetext RockSmashGuyText3
waitbutton
-UnknownScript_0x1940de:
+.NoRoomForTM:
closetext
end
@@ -161,13 +161,13 @@ LassScript_0x1940e0:
faceplayer
opentext
checkevent EVENT_FOUGHT_SUDOWOODO
- iftrue UnknownScript_0x1940ee
+ iftrue .ClearedSudowoodo
writetext UnknownText_0x194626
waitbutton
closetext
end
-UnknownScript_0x1940ee:
+.ClearedSudowoodo:
writetext UnknownText_0x19469e
waitbutton
closetext
@@ -377,7 +377,7 @@ SudowoodoShakeMovement:
db $56 ; shake
step_end
-MovementData_0x19424b:
+WeirdTreeMovement_Flee:
fast_jump_step_up
fast_jump_step_up
step_end
@@ -406,15 +406,15 @@ FloriaMovement2:
step_left
step_end
-MovementData_0x194262:
- db $39 ; movement
+Route36SuicuneMovement:
+ set_sliding
fast_jump_step_down
fast_jump_step_down
fast_jump_step_down
fast_jump_step_right
fast_jump_step_right
fast_jump_step_right
- db $38 ; movement
+ remove_sliding
step_end
UseSquirtbottleText:
@@ -476,7 +476,7 @@ FloriaText2:
line "bottle…"
done
-UnknownText_0x19446f:
+RockSmashGuyText1:
text "Wa-hey!"
para "I was going to"
@@ -489,7 +489,7 @@ UnknownText_0x19446f:
line "I'm a failure!"
done
-UnknownText_0x1944d0:
+RockSmashGuyText2:
text "Did you clear that"
line "wretched tree?"
@@ -503,7 +503,7 @@ UnknownText_0x19451a:
line "TM08."
done
-UnknownText_0x19452c:
+RockSmashGuyText3:
text "That happens to be"
line "ROCK SMASH."
@@ -695,7 +695,7 @@ Route36_MapEventHeader:
person_event SPRITE_YOUNGSTER, 14, 31, SPRITEMOVEDATA_STANDING_LEFT, 0, 0, -1, -1, (1 << 3) | PAL_OW_BLUE, PERSONTYPE_TRAINER, 5, TrainerSchoolboyAlan1, -1
person_event SPRITE_WEIRD_TREE, 9, 35, SPRITEMOVEDATA_SUDOWOODO, 0, 0, -1, -1, 0, PERSONTYPE_SCRIPT, 0, SudowoodoScript, EVENT_ROUTE_36_SUDOWOODO
person_event SPRITE_LASS, 8, 51, SPRITEMOVEDATA_WALK_LEFT_RIGHT, 0, 2, -1, -1, 0, PERSONTYPE_SCRIPT, 0, LassScript_0x1940e0, -1
- person_event SPRITE_FISHER, 9, 44, SPRITEMOVEDATA_STANDING_LEFT, 0, 0, -1, -1, 0, PERSONTYPE_SCRIPT, 0, FisherScript_0x1940b9, -1
+ person_event SPRITE_FISHER, 9, 44, SPRITEMOVEDATA_STANDING_LEFT, 0, 0, -1, -1, 0, PERSONTYPE_SCRIPT, 0, Route36RockSmashGuyScript, -1
person_event SPRITE_FRUIT_TREE, 4, 21, SPRITEMOVEDATA_ITEM_TREE, 0, 0, -1, -1, 0, PERSONTYPE_SCRIPT, 0, FruitTreeScript_0x194247, -1
person_event SPRITE_YOUNGSTER, 6, 46, SPRITEMOVEDATA_WANDER, 1, 1, -1, -1, 0, PERSONTYPE_SCRIPT, 0, ArthurScript, EVENT_ROUTE_36_ARTHUR_OF_THURSDAY
person_event SPRITE_LASS, 12, 33, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, (1 << 3) | PAL_OW_BLUE, PERSONTYPE_SCRIPT, 0, Route36FloriaScript, EVENT_FLORIA_AT_SUDOWOODO
diff --git a/maps/TinTower1F.asm b/maps/TinTower1F.asm
index 81fb366e6..5ebd80be6 100644
--- a/maps/TinTower1F.asm
+++ b/maps/TinTower1F.asm
@@ -243,37 +243,37 @@ TinTowerPlayerMovement1:
step_end
TinTowerRaikouMovement1:
- db $39 ; movement
+ set_sliding
fast_jump_step_down
- db $38 ; movement
+ remove_sliding
step_end
TinTowerRaikouMovement2:
- db $39 ; movement
+ set_sliding
fast_jump_step_down
fast_jump_step_right
fast_jump_step_down
- db $38 ; movement
+ remove_sliding
step_end
TinTowerEnteiMovement1:
- db $39 ; movement
+ set_sliding
fast_jump_step_down
- db $38 ; movement
+ remove_sliding
step_end
TinTowerEnteiMovement2:
- db $39 ; movement
+ set_sliding
fast_jump_step_down
fast_jump_step_left
fast_jump_step_down
- db $38 ; movement
+ remove_sliding
step_end
TinTowerSuicuneMovement:
- db $39 ; movement
+ set_sliding
fast_jump_step_down
- db $38 ; movement
+ remove_sliding
step_end
TinTowerPlayerMovement2:
diff --git a/misc/battle_tower_5c.asm b/misc/battle_tower_5c.asm
index c975f4901..127590b3a 100755
--- a/misc/battle_tower_5c.asm
+++ b/misc/battle_tower_5c.asm
@@ -1085,9 +1085,9 @@ Function17075f: ; 17075f (5c:475f) BattleTowerAction $00
and a
ret z
- ld a, BANK(sbe4f)
+ ld a, BANK(s1_be4f)
call GetSRAMBank
- ld a, [sbe4f]
+ ld a, [s1_be4f]
and $2
ld [ScriptVar], a
call CloseSRAM
@@ -1103,11 +1103,11 @@ Function170778: ; 170778 (5c:4778) BattleTowerAction $02
ret
Function170788: ; 170788 (5c:4788) BattleTowerAction $01
- ld a, BANK(sbe4f)
+ ld a, BANK(s1_be4f)
call GetSRAMBank
- ld a, [sbe4f]
+ ld a, [s1_be4f]
or $2
- ld [sbe4f], a
+ ld [s1_be4f], a
call CloseSRAM
ret
@@ -1591,20 +1591,20 @@ Function170abe: ; 170abe (5c:4abe) BattleTowerAction $14
and a
ret z
- ld a, BANK(sbe4f)
+ ld a, BANK(s1_be4f)
call GetSRAMBank
- ld a, [sbe4f]
+ ld a, [s1_be4f]
and $1
ld [ScriptVar], a
call CloseSRAM
ret
Function170ad7: ; 170ad7 (5c:4ad7) BattleTowerAction $15
- ld a, BANK(sbe4f)
+ ld a, BANK(s1_be4f)
call GetSRAMBank
- ld a, [sbe4f]
+ ld a, [s1_be4f]
or $1
- ld [sbe4f], a
+ ld [s1_be4f], a
call CloseSRAM
ret
diff --git a/misc/mobile_12_2.asm b/misc/mobile_12_2.asm
index 86583aa40..928eeec98 100755
--- a/misc/mobile_12_2.asm
+++ b/misc/mobile_12_2.asm
@@ -443,7 +443,7 @@ Function4aad3: ; 4aad3
push bc
push hl
ld e, 0
- callba Function8e83f
+ callba LoadMenuMonIcon
ld a, [hObjectStructIndexBuffer]
inc a
ld [hObjectStructIndexBuffer], a
diff --git a/misc/mobile_22.asm b/misc/mobile_22.asm
index b849b8405..c9a844b42 100644
--- a/misc/mobile_22.asm
+++ b/misc/mobile_22.asm
@@ -2216,7 +2216,7 @@ Function89d85: ; 89d85 (22:5d85)
push hl
call Function8923c
call _hl_
- call Function3238
+ call CGBOnly_LoadEDTile
pop hl
asm_89d90: ; 89d90 (22:5d90)
@@ -2661,7 +2661,7 @@ rept 3
endr
ld a, $6
call Function8a5a3
- call Function3238
+ call CGBOnly_LoadEDTile
pop bc
ld a, c
cp $b
@@ -2676,7 +2676,7 @@ endr
ld a, $6
hlcoord 15, 4, AttrMap
call Function8a5a3
- call Function3238
+ call CGBOnly_LoadEDTile
jp Function89e36
Function8a0a1: ; 8a0a1 (22:60a1)
diff --git a/misc/mobile_22_2.asm b/misc/mobile_22_2.asm
index 70fc96095..4b2cb07ee 100644
--- a/misc/mobile_22_2.asm
+++ b/misc/mobile_22_2.asm
@@ -401,7 +401,7 @@ Function8b539: ; 8b539 (22:7539)
call Function8b4fd
ld e, $0
call Function89c44
- call Function3238
+ call CGBOnly_LoadEDTile
ret
Function8b555: ; 8b555 (22:7555)
diff --git a/misc/mobile_40.asm b/misc/mobile_40.asm
index 8594f0044..430400c8d 100644
--- a/misc/mobile_40.asm
+++ b/misc/mobile_40.asm
@@ -3079,7 +3079,7 @@ Function1013d6: ; 1013d6
; 1013dd
Function1013dd: ; 1013dd
- call Function3238
+ call CGBOnly_LoadEDTile
ret
; 1013e1
diff --git a/misc/mobile_46.asm b/misc/mobile_46.asm
index a5f9bbddb..c30713f43 100755
--- a/misc/mobile_46.asm
+++ b/misc/mobile_46.asm
@@ -5846,12 +5846,12 @@ Function11ad1b: ; 11ad1b
ld [hObjectStructIndexBuffer], a
ld a, $10
ld [wCurIconTile], a
- ld hl, Function8e83f
- ld a, BANK(Function8e83f)
+ ld hl, LoadMenuMonIcon
+ ld a, BANK(LoadMenuMonIcon)
ld e, $4
rst FarCall
- ld hl, Function8e83f
- ld a, BANK(Function8e83f)
+ ld hl, LoadMenuMonIcon
+ ld a, BANK(LoadMenuMonIcon)
ld e, $5
rst FarCall
ld hl, $c6d0
diff --git a/sram.asm b/sram.asm
index f28ed939e..676453e93 100644
--- a/sram.asm
+++ b/sram.asm
@@ -69,7 +69,7 @@ sMysteryGiftTimerStartDay:: ds 1
sMysteryGiftTrainerHouseFlag:: ds 1
sMysteryGiftPartnerName:: ds NAME_LENGTH
s0_ac09:: ds 1
-sMysteryGiftTrainer:: ds (1 + 1 + NUM_MOVES) * PARTY_LENGTH + 2
+sMysteryGiftTrainer:: ds (1 + 1 + NUM_MOVES) * PARTY_LENGTH + 2 ; ac0a
sBackupMysteryGiftItemEnd::
ds $30
@@ -81,7 +81,7 @@ sLuckyIDNumber:: ds 2
SECTION "Backup Save", SRAM [$b200], BANK [0]
sBackupOptions:: ds OptionsEnd - Options
-s0_b208:: ds 1
+s0_b208:: ds 1 ; loaded with 99, used to check save corruption
sBackupGameData::
sBackupPlayerData:: ds wPlayerDataEnd - wPlayerData
@@ -94,11 +94,11 @@ sBackupGameDataEnd::
; bf0d
sBackupChecksum:: ds 2
-s0_bf0f:: ds 1
+s0_bf0f:: ds 1 ; loaded with 0x7f, used to check save corruption
sStackTop:: ds 2
-SECTION "SRAM Bank 1", SRAM, BANK [1]
+SECTION "Save", SRAM, BANK [1]
sOptions:: ds OptionsEnd - Options
@@ -117,11 +117,13 @@ sGameDataEnd::
sChecksum:: ds 2
s1_ad0f:: ds 1 ; loaded with 0x7f, used to check save corruption
+SECTION "Active Box", SRAM, BANK [1]
; ad10
box sBox
; b160
ds $f4
+SECTION "Link Battle Data", SRAM, BANK [1]
sLinkBattleResults:: ds $c
sLinkBattleStats:: ; b260
@@ -143,6 +145,7 @@ sLinkBattleRecord4:: link_battle_record sLinkBattleRecord4
sLinkBattleRecord5:: link_battle_record sLinkBattleRecord5
sLinkBattleStatsEnd::
+SECTION "SRAM Hall of Fame", SRAM, BANK [1]
sHallOfFame:: ; b2c0
; temporary until I can find a way to macrofy it
hall_of_fame sHallOfFame01
@@ -190,6 +193,7 @@ sHallOfFame:: ; b2c0
; endr
sHallOfFameEnd::
+SECTION "SRAM Crystal Data", SRAM, BANK [1]
sMobileEventIndex:: ds 1 ; be3c
sCrystalData::
@@ -208,7 +212,7 @@ sBTChoiceOfLevelGroup:: ds 1
; The 7 trainers of the BattleTower are saved here, so nobody appears more than once
sBTTrainers:: ; sbe48
ds 7
-sbe4f:: ds 1
+s1_be4f:: ds 1
sBattleTowerReward:: ds 1
; Pkmn of previous trainer
sBTPkmnOfTrainers:: ; 0xbe51
diff --git a/wram.asm b/wram.asm
index 01394f364..2786879ee 100644
--- a/wram.asm
+++ b/wram.asm
@@ -118,7 +118,7 @@ Channel1JumpCondition:: ds 1
Channel2JumpCondition:: ds 1
Channel3JumpCondition:: ds 1
Channel4JumpCondition:: ds 1
-wStereoPanningMask:: ds 1
+wStereoPanningMask:: ds 1 ; c2bc
CryTracks:: ; c2bd
; plays only in left or right track depending on what side the monster is on
; both tracks active outside of battle
@@ -127,7 +127,7 @@ wSFXDuration:: ds 1
CurSFX:: ; c2bf
; id of sfx currently playing
ds 1
-
+ChannelsEnd::
wMapMusic:: ; c2c0
ds 1
@@ -1328,9 +1328,9 @@ wWindowStackPointer:: dw ; cf71
wMenuJoypad:: ds 1 ; cf73
MenuSelection:: ds 1 ; cf74
MenuSelectionQuantity:: ds 1 ; cf75
-wWhichIndexSet:: ds 1
-wScrollingMenuCursorPosition:: ds 1
-wWindowStackSize:: ds 9
+wWhichIndexSet:: ds 1 ; cf76
+wScrollingMenuCursorPosition:: ds 1 ; cf77
+wWindowStackSize:: ds 9 ; cf78
; menu data header
wMenuDataHeader:: ; cf81
@@ -1727,18 +1727,21 @@ CurMoveNum:: ; d0d5
ds 1
wLastPocket:: ds 1
-wd0d7:: ds 1
-wd0d8::
+
+wPCItemsCursor:: ds 1
wPartyMenuCursor:: ds 1
wItemsPocketCursor:: ds 1
wKeyItemsPocketCursor:: ds 1
wBallsPocketCursor:: ds 1
wTMHMPocketCursor:: ds 1
-wd0dd:: ds 2
+
+wPCItemsScrollPosition:: ds 1
+wPartyMenuScrollPosition:: ds 1 ; unused
wItemsPocketScrollPosition:: ds 1
wKeyItemsPocketScrollPosition:: ds 1
wBallsPocketScrollPosition:: ds 1
wTMHMPocketScrollPosition:: ds 1
+
wMoveSwapBuffer::
wSwitchMon::
wSwitchItem::
@@ -1764,9 +1767,9 @@ VramState:: ; d0ed
; flickers when climbing waterfall
ds 1
-wBattleResult:: ds 1
-wUsingItemWithSelect:: ds 1
-CurMart:: ds 16
+wBattleResult:: ds 1 ; d0ee
+wUsingItemWithSelect:: ds 1 ; d0ef
+CurMart:: ds 16 ; d0f0
CurMartEnd::
ds CurMart - @
CurElevator:: ds 1
@@ -1776,7 +1779,7 @@ wCurMessageIndex:: ds 1
wd0f2::
wMailboxCount:: ds 1
wMailboxItems:: ds MAILBOX_CAPACITY
-wMailboxEnd:: ds 1 ; d1fe
+wMailboxEnd:: ds 1 ; d0fe
ds 2
wd100:: ds 1
@@ -1786,9 +1789,7 @@ wd103:: ds 1
wd104:: ds 1
wd105:: ds 1
-CurItem:: ; d106
- ds 1
-
+CurItem:: ds 1 ; d106
CurItemQuantity:: ; d107
wMartItemID::
wd107:: ds 1
@@ -1805,6 +1806,7 @@ CurPartyMon:: ; d109
wWhichHPBar::
; 0: Enemy
; 1: Player
+; 2: Party Menu
ds 1
wPokemonWithdrawDepositParameter::
; 0: Take from PC
@@ -2027,7 +2029,9 @@ wd1ee:: ds 1
Buffer6::
wd1ef:: ds 1
wd1f0:: ds 1
+wCurHPBarPixels::
wd1f1:: ds 1
+wNewHPBarPixels::
wd1f2:: ds 1
wd1f3:: ds 1
wd1f4:: ds 1
@@ -2148,7 +2152,7 @@ wWaterEncounterRate:: ds 1 ; d25d
wListMoves_MoveIndicesBuffer:: ds NUM_MOVES
wPutativeTMHMMove:: ds 1
wd263:: ds 1
-wd264:: ds 1
+wAISwitch:: ds 1
wFoundMatchingIDInParty::
wNamedObjectIndexBuffer::
wCurTMHM::
@@ -2801,16 +2805,16 @@ wMapData::
VisitedSpawns:: ; dca5
flag_array NUM_SPAWNS
-wDigWarp:: ds 1
-wDigMapGroup:: ds 1
-wDigMapNumber:: ds 1
+wDigWarp:: ds 1 ; dcaa
+wDigMapGroup:: ds 1 ; dcab
+wDigMapNumber:: ds 1 ; dcac
; used on maps like second floor pokécenter, which are reused, so we know which
; map to return to
-BackupWarpNumber:: ; dcac
+BackupWarpNumber:: ; dcad
ds 1
-BackupMapGroup:: ; dcad
+BackupMapGroup:: ; dcae
ds 1
-BackupMapNumber:: ; dcae
+BackupMapNumber:: ; dcaf
ds 1
ds 3