summaryrefslogtreecommitdiff
path: root/engine/overworld/cut.asm
diff options
context:
space:
mode:
Diffstat (limited to 'engine/overworld/cut.asm')
-rwxr-xr-xengine/overworld/cut.asm201
1 files changed, 103 insertions, 98 deletions
diff --git a/engine/overworld/cut.asm b/engine/overworld/cut.asm
index 7b92bca3..f6ae6468 100755
--- a/engine/overworld/cut.asm
+++ b/engine/overworld/cut.asm
@@ -1,43 +1,43 @@
-UsedCut: ; ef54 (3:6f54)
+UsedCut:
xor a
- ld [wcd6a], a
- ld a, [W_CURMAPTILESET] ; W_CURMAPTILESET
+ ld [wActionResultOrTookBattleTurn], a ; initialise to failure value
+ ld a, [wCurMapTileset]
and a ; OVERWORLD
- jr z, .asm_ef6b
+ jr z, .overworld
cp GYM
- jr nz, .asm_ef77
+ jr nz, .nothingToCut
ld a, [wTileInFrontOfPlayer]
cp $50 ; gym cut tree
- jr nz, .asm_ef77
- jr asm_ef82
-.asm_ef6b
+ jr nz, .nothingToCut
+ jr .canCut
+.overworld
dec a
ld a, [wTileInFrontOfPlayer]
cp $3d ; cut tree
- jr z, asm_ef82
+ jr z, .canCut
cp $52 ; grass
- jr z, asm_ef82
-.asm_ef77
- ld hl, NothingToCutText
+ jr z, .canCut
+.nothingToCut
+ ld hl, .NothingToCutText
jp PrintText
-NothingToCutText: ; ef7d (3:6f7d)
+.NothingToCutText
TX_FAR _NothingToCutText
db "@"
-asm_ef82: ; ef82 (3:6f82)
- ld [wcd4d], a
- ld a, $1
- ld [wcd6a], a
- ld a, [wWhichPokemon] ; wWhichPokemon
- ld hl, wPartyMonNicks ; wPartyMonNicks
+.canCut
+ ld [wCutTile], a
+ ld a, 1
+ ld [wActionResultOrTookBattleTurn], a ; used cut
+ ld a, [wWhichPokemon]
+ ld hl, wPartyMonNicks
call GetPartyMonName
ld hl, wd730
set 6, [hl]
call GBPalWhiteOutWithDelay3
call ClearSprites
call RestoreScreenTilesAndReloadTilePatterns
- ld a, $90
+ ld a, SCREEN_HEIGHT_PIXELS
ld [hWY], a
call Delay3
call LoadGBPal
@@ -53,79 +53,80 @@ asm_ef82: ; ef82 (3:6f82)
res 6, [hl]
ld a, $ff
ld [wUpdateSpritesEnabled], a
- call AnimateCutTree
- ld de, CutTreeBlockSwaps ; $7100
- call Func_f09f
+ call InitCutAnimOAM
+ ld de, CutTreeBlockSwaps
+ call ReplaceTreeTileBlock
call RedrawMapView
- callba Func_79e96
+ callba AnimCut
ld a, $1
ld [wUpdateSpritesEnabled], a
- ld a, (SFX_02_56 - SFX_Headers_02) / 3
+ ld a, SFX_CUT
call PlaySound
ld a, $90
ld [hWY], a
call UpdateSprites
jp RedrawMapView
-UsedCutText: ; eff2 (3:6ff2)
+UsedCutText:
TX_FAR _UsedCutText
db "@"
-AnimateCutTree: ; eff7 (3:6ff7)
+InitCutAnimOAM:
xor a
- ld [wcd50], a
- ld a, $e4
- ld [rOBP1], a ; $ff49
- ld a, [wcd4d]
+ ld [wWhichAnimationOffsets], a
+ ld a, %11100100
+ ld [rOBP1], a
+ ld a, [wCutTile]
cp $52
- jr z, .asm_f020
- ld de, Overworld_GFX + $2d0 ; $42d0 ; cuttable tree sprite top row
+ jr z, .grass
+; tree
+ ld de, Overworld_GFX + $2d0 ; cuttable tree sprite top row
ld hl, vChars1 + $7c0
- ld bc, (BANK(Overworld_GFX) << 8) + $02
+ lb bc, BANK(Overworld_GFX), $02
call CopyVideoData
- ld de, Overworld_GFX + $3d0 ; $43d0 ; cuttable tree sprite bottom row
+ ld de, Overworld_GFX + $3d0 ; cuttable tree sprite bottom row
ld hl, vChars1 + $7e0
- ld bc, (BANK(Overworld_GFX) << 8) + $02
+ lb bc, BANK(Overworld_GFX), $02
call CopyVideoData
- jr WriteCutTreeBoulderDustAnimationOAMBlock
-.asm_f020
+ jr WriteCutOrBoulderDustAnimationOAMBlock
+.grass
ld hl, vChars1 + $7c0
- call LoadCutTreeAnimationTilePattern
+ call LoadCutGrassAnimationTilePattern
ld hl, vChars1 + $7d0
- call LoadCutTreeAnimationTilePattern
+ call LoadCutGrassAnimationTilePattern
ld hl, vChars1 + $7e0
- call LoadCutTreeAnimationTilePattern
+ call LoadCutGrassAnimationTilePattern
ld hl, vChars1 + $7f0
- call LoadCutTreeAnimationTilePattern
- call WriteCutTreeBoulderDustAnimationOAMBlock
+ call LoadCutGrassAnimationTilePattern
+ call WriteCutOrBoulderDustAnimationOAMBlock
ld hl, wOAMBuffer + $93
- ld de, $4
+ ld de, 4
ld a, $30
ld c, e
-.asm_f044
+.loop
ld [hl], a
add hl, de
xor $60
dec c
- jr nz, .asm_f044
+ jr nz, .loop
ret
-LoadCutTreeAnimationTilePattern: ; f04c (3:704c)
- ld de, AnimationTileset2 + $60 ; $474e ; tile depicting a leaf
- ld bc, (BANK(AnimationTileset2) << 8) + $01
+LoadCutGrassAnimationTilePattern:
+ ld de, AnimationTileset2 + $60 ; tile depicting a leaf
+ lb bc, BANK(AnimationTileset2), $01
jp CopyVideoData
-WriteCutTreeBoulderDustAnimationOAMBlock: ; f055 (3:7055)
- call GetCutTreeBoulderDustAnimationOffsets
+WriteCutOrBoulderDustAnimationOAMBlock:
+ call GetCutOrBoulderDustAnimationOffsets
ld a, $9
- ld de, CutTreeBoulderDustAnimationTilesAndAttributes
+ ld de, CutOrBoulderDustAnimationTilesAndAttributes
jp WriteOAMBlock
-CutTreeBoulderDustAnimationTilesAndAttributes: ; f060 (3:7060)
+CutOrBoulderDustAnimationTilesAndAttributes:
db $FC,$10,$FD,$10
db $FE,$10,$FF,$10
-GetCutTreeBoulderDustAnimationOffsets: ; f068 (3:7068)
+GetCutOrBoulderDustAnimationOffsets:
ld hl, wSpriteStateData1 + 4
ld a, [hli] ; player's sprite screen Y position
ld b, a
@@ -138,12 +139,12 @@ GetCutTreeBoulderDustAnimationOffsets: ; f068 (3:7068)
srl a
ld e, a
ld d, $0 ; de holds direction (00: down, 02: up, 04: left, 06: right)
- ld a, [wcd50]
+ ld a, [wWhichAnimationOffsets]
and a
- ld hl, CutTreeAnimationOffsets
- jr z, .asm_f084
+ ld hl, CutAnimationOffsets
+ jr z, .next
ld hl, BoulderDustAnimationOffsets
-.asm_f084
+.next
add hl, de
ld e, [hl]
inc hl
@@ -156,14 +157,14 @@ GetCutTreeBoulderDustAnimationOffsets: ; f068 (3:7068)
ld c, a
ret
-CutTreeAnimationOffsets: ; f08f (3:708f)
+CutAnimationOffsets:
; Each pair represents the x and y pixels offsets from the player of where the cut tree animation should be drawn
db 8, 36 ; player is facing down
db 8, 4 ; player is facing up
db -8, 20 ; player is facing left
db 24, 20 ; player is facing right
-BoulderDustAnimationOffsets: ; f097 (3:7097)
+BoulderDustAnimationOffsets:
; Each pair represents the x and y pixels offsets from the player of where the cut tree animation should be drawn
; These offsets represent 2 blocks away from the player
db 8, 52 ; player is facing down
@@ -171,79 +172,83 @@ BoulderDustAnimationOffsets: ; f097 (3:7097)
db -24, 20 ; player is facing left
db 40, 20 ; player is facing right
-Func_f09f: ; f09f (3:709f)
+ReplaceTreeTileBlock:
+; Determine the address of the tile block that contains the tile in front of the
+; player (i.e. where the tree is) and replace it with the corresponding tile
+; block that doesn't have the tree.
push de
- ld a, [W_CURMAPWIDTH] ; wd369
- add $6
+ ld a, [wCurMapWidth]
+ add 6
ld c, a
- ld b, $0
- ld d, $0
+ ld b, 0
+ ld d, 0
ld hl, wCurrentTileBlockMapViewPointer
ld a, [hli]
ld h, [hl]
ld l, a
add hl, bc
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wSpriteStateData1 + 9] ; player sprite's facing direction
and a
- jr z, .asm_f0c7
- cp $4
- jr z, .asm_f0cf
- cp $8
- jr z, .asm_f0d7
- ld a, [W_XBLOCKCOORD] ; wd364
+ jr z, .down
+ cp SPRITE_FACING_UP
+ jr z, .up
+ cp SPRITE_FACING_LEFT
+ jr z, .left
+; right
+ ld a, [wXBlockCoord]
and a
- jr z, .asm_f0e0
- jr .asm_f0ec
-.asm_f0c7
- ld a, [W_YBLOCKCOORD] ; wd363
+ jr z, .centerTileBlock
+ jr .rightOfCenter
+.down
+ ld a, [wYBlockCoord]
and a
- jr z, .asm_f0e0
- jr .asm_f0df
-.asm_f0cf
- ld a, [W_YBLOCKCOORD] ; wd363
+ jr z, .centerTileBlock
+ jr .belowCenter
+.up
+ ld a, [wYBlockCoord]
and a
- jr z, .asm_f0e1
- jr .asm_f0e0
-.asm_f0d7
- ld a, [W_XBLOCKCOORD] ; wd364
+ jr z, .aboveCenter
+ jr .centerTileBlock
+.left
+ ld a, [wXBlockCoord]
and a
- jr z, .asm_f0e6
- jr .asm_f0e0
-.asm_f0df
+ jr z, .leftOfCenter
+ jr .centerTileBlock
+.belowCenter
add hl, bc
-.asm_f0e0
+.centerTileBlock
add hl, bc
-.asm_f0e1
+.aboveCenter
ld e, $2
add hl, de
- jr .asm_f0f0
-.asm_f0e6
+ jr .next
+.leftOfCenter
ld e, $1
add hl, bc
add hl, de
- jr .asm_f0f0
-.asm_f0ec
+ jr .next
+.rightOfCenter
ld e, $3
add hl, bc
add hl, de
-.asm_f0f0
+.next
pop de
ld a, [hl]
ld c, a
-.asm_f0f3
+.loop ; find the matching tile block in the array
ld a, [de]
inc de
inc de
cp $ff
ret z
cp c
- jr nz, .asm_f0f3
+ jr nz, .loop
dec de
- ld a, [de]
+ ld a, [de] ; replacement tile block from matching array entry
ld [hl], a
ret
-CutTreeBlockSwaps: ; f100 (3:7100)
+CutTreeBlockSwaps:
; first byte = tileset block containing the cut tree
; second byte = corresponding tileset block after the cut animation happens
db $32, $6D