mirror of
https://github.com/thornAvery/kep-hack.git
synced 2026-02-06 15:45:24 +13:00
split code out of main.asm
This commit is contained in:
parent
10289bf7dd
commit
bf67f7174d
22 changed files with 2671 additions and 2675 deletions
20
engine/overworld/clear_variables.asm
Normal file
20
engine/overworld/clear_variables.asm
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
ClearVariablesOnEnterMap:
|
||||
ld a, SCREEN_HEIGHT_PIXELS
|
||||
ld [hWY], a
|
||||
ld [rWY], a
|
||||
xor a
|
||||
ld [H_AUTOBGTRANSFERENABLED], a
|
||||
ld [wStepCounter], a
|
||||
ld [wLoneAttackNo], a
|
||||
ld [hJoyPressed], a
|
||||
ld [hJoyReleased], a
|
||||
ld [hJoyHeld], a
|
||||
ld [wActionResultOrTookBattleTurn], a
|
||||
ld [wUnusedD5A3], a
|
||||
ld hl, wCardKeyDoorY
|
||||
ld [hli], a
|
||||
ld [hl], a
|
||||
ld hl, wWhichTrade
|
||||
ld bc, wStandingOnWarpPadOrHole - wWhichTrade
|
||||
call FillMemory
|
||||
ret
|
||||
18
engine/overworld/daycare_exp.asm
Normal file
18
engine/overworld/daycare_exp.asm
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
IncrementDayCareMonExp:
|
||||
ld a, [wDayCareInUse]
|
||||
and a
|
||||
ret z
|
||||
ld hl, wDayCareMonExp + 2
|
||||
inc [hl]
|
||||
ret nz
|
||||
dec hl
|
||||
inc [hl]
|
||||
ret nz
|
||||
dec hl
|
||||
inc [hl]
|
||||
ld a, [hl]
|
||||
cp $50
|
||||
ret c
|
||||
ld a, $50
|
||||
ld [hl], a
|
||||
ret
|
||||
57
engine/overworld/field_move_messages.asm
Normal file
57
engine/overworld/field_move_messages.asm
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
PrintStrengthTxt:
|
||||
ld hl, wd728
|
||||
set 0, [hl]
|
||||
ld hl, UsedStrengthText
|
||||
call PrintText
|
||||
ld hl, CanMoveBouldersText
|
||||
jp PrintText
|
||||
|
||||
UsedStrengthText:
|
||||
TX_FAR _UsedStrengthText
|
||||
TX_ASM
|
||||
ld a, [wcf91]
|
||||
call PlayCry
|
||||
call Delay3
|
||||
jp TextScriptEnd
|
||||
|
||||
CanMoveBouldersText:
|
||||
TX_FAR _CanMoveBouldersText
|
||||
db "@"
|
||||
|
||||
IsSurfingAllowed:
|
||||
; Returns whether surfing is allowed in bit 1 of wd728.
|
||||
; Surfing isn't allowed on the Cycling Road or in the lowest level of the
|
||||
; Seafoam Islands before the current has been slowed with boulders.
|
||||
ld hl, wd728
|
||||
set 1, [hl]
|
||||
ld a, [wd732]
|
||||
bit 5, a
|
||||
jr nz, .forcedToRideBike
|
||||
ld a, [wCurMap]
|
||||
cp SEAFOAM_ISLANDS_5
|
||||
ret nz
|
||||
CheckBothEventsSet EVENT_SEAFOAM4_BOULDER1_DOWN_HOLE, EVENT_SEAFOAM4_BOULDER2_DOWN_HOLE
|
||||
ret z
|
||||
ld hl, CoordsData_cdf7
|
||||
call ArePlayerCoordsInArray
|
||||
ret nc
|
||||
ld hl, wd728
|
||||
res 1, [hl]
|
||||
ld hl, CurrentTooFastText
|
||||
jp PrintText
|
||||
.forcedToRideBike
|
||||
ld hl, wd728
|
||||
res 1, [hl]
|
||||
ld hl, CyclingIsFunText
|
||||
jp PrintText
|
||||
|
||||
CoordsData_cdf7:
|
||||
db $0B,$07,$FF
|
||||
|
||||
CurrentTooFastText:
|
||||
TX_FAR _CurrentTooFastText
|
||||
db "@"
|
||||
|
||||
CyclingIsFunText:
|
||||
TX_FAR _CyclingIsFunText
|
||||
db "@"
|
||||
215
engine/overworld/missable_objects.asm
Normal file
215
engine/overworld/missable_objects.asm
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
MarkTownVisitedAndLoadMissableObjects:
|
||||
ld a, [wCurMap]
|
||||
cp ROUTE_1
|
||||
jr nc, .notInTown
|
||||
ld c, a
|
||||
ld b, FLAG_SET
|
||||
ld hl, wTownVisitedFlag ; mark town as visited (for flying)
|
||||
predef FlagActionPredef
|
||||
.notInTown
|
||||
ld hl, MapHSPointers
|
||||
ld a, [wCurMap]
|
||||
ld b, $0
|
||||
ld c, a
|
||||
add hl, bc
|
||||
add hl, bc
|
||||
ld a, [hli] ; load missable objects pointer in hl
|
||||
ld h, [hl]
|
||||
; fall through
|
||||
|
||||
LoadMissableObjects:
|
||||
ld l, a
|
||||
push hl
|
||||
ld de, MapHS00 ; calculate difference between out pointer and the base pointer
|
||||
ld a, l
|
||||
sub e
|
||||
jr nc, .asm_f13c
|
||||
dec h
|
||||
.asm_f13c
|
||||
ld l, a
|
||||
ld a, h
|
||||
sub d
|
||||
ld h, a
|
||||
ld a, h
|
||||
ld [H_DIVIDEND], a
|
||||
ld a, l
|
||||
ld [H_DIVIDEND+1], a
|
||||
xor a
|
||||
ld [H_DIVIDEND+2], a
|
||||
ld [H_DIVIDEND+3], a
|
||||
ld a, $3
|
||||
ld [H_DIVISOR], a
|
||||
ld b, $2
|
||||
call Divide ; divide difference by 3, resulting in the global offset (number of missable items before ours)
|
||||
ld a, [wCurMap]
|
||||
ld b, a
|
||||
ld a, [H_DIVIDEND+3]
|
||||
ld c, a ; store global offset in c
|
||||
ld de, wMissableObjectList
|
||||
pop hl
|
||||
.writeMissableObjectsListLoop
|
||||
ld a, [hli]
|
||||
cp $ff
|
||||
jr z, .done ; end of list
|
||||
cp b
|
||||
jr nz, .done ; not for current map anymore
|
||||
ld a, [hli]
|
||||
inc hl
|
||||
ld [de], a ; write (map-local) sprite ID
|
||||
inc de
|
||||
ld a, c
|
||||
inc c
|
||||
ld [de], a ; write (global) missable object index
|
||||
inc de
|
||||
jr .writeMissableObjectsListLoop
|
||||
.done
|
||||
ld a, $ff
|
||||
ld [de], a ; write sentinel
|
||||
ret
|
||||
|
||||
InitializeMissableObjectsFlags:
|
||||
ld hl, wMissableObjectFlags
|
||||
ld bc, wMissableObjectFlagsEnd - wMissableObjectFlags
|
||||
xor a
|
||||
call FillMemory ; clear missable objects flags
|
||||
ld hl, MapHS00
|
||||
xor a
|
||||
ld [wMissableObjectCounter], a
|
||||
.missableObjectsLoop
|
||||
ld a, [hli]
|
||||
cp $ff ; end of list
|
||||
ret z
|
||||
push hl
|
||||
inc hl
|
||||
ld a, [hl]
|
||||
cp Hide
|
||||
jr nz, .skip
|
||||
ld hl, wMissableObjectFlags
|
||||
ld a, [wMissableObjectCounter]
|
||||
ld c, a
|
||||
ld b, FLAG_SET
|
||||
call MissableObjectFlagAction ; set flag if Item is hidden
|
||||
.skip
|
||||
ld hl, wMissableObjectCounter
|
||||
inc [hl]
|
||||
pop hl
|
||||
inc hl
|
||||
inc hl
|
||||
jr .missableObjectsLoop
|
||||
|
||||
; tests if current sprite is a missable object that is hidden/has been removed
|
||||
IsObjectHidden:
|
||||
ld a, [H_CURRENTSPRITEOFFSET]
|
||||
swap a
|
||||
ld b, a
|
||||
ld hl, wMissableObjectList
|
||||
.loop
|
||||
ld a, [hli]
|
||||
cp $ff
|
||||
jr z, .notHidden ; not missable -> not hidden
|
||||
cp b
|
||||
ld a, [hli]
|
||||
jr nz, .loop
|
||||
ld c, a
|
||||
ld b, FLAG_TEST
|
||||
ld hl, wMissableObjectFlags
|
||||
call MissableObjectFlagAction
|
||||
ld a, c
|
||||
and a
|
||||
jr nz, .hidden
|
||||
.notHidden
|
||||
xor a
|
||||
.hidden
|
||||
ld [$ffe5], a
|
||||
ret
|
||||
|
||||
; adds missable object (items, leg. pokemon, etc.) to the map
|
||||
; [wMissableObjectIndex]: index of the missable object to be added (global index)
|
||||
ShowObject:
|
||||
ShowObject2:
|
||||
ld hl, wMissableObjectFlags
|
||||
ld a, [wMissableObjectIndex]
|
||||
ld c, a
|
||||
ld b, FLAG_RESET
|
||||
call MissableObjectFlagAction ; reset "removed" flag
|
||||
jp UpdateSprites
|
||||
|
||||
; removes missable object (items, leg. pokemon, etc.) from the map
|
||||
; [wMissableObjectIndex]: index of the missable object to be removed (global index)
|
||||
HideObject:
|
||||
ld hl, wMissableObjectFlags
|
||||
ld a, [wMissableObjectIndex]
|
||||
ld c, a
|
||||
ld b, FLAG_SET
|
||||
call MissableObjectFlagAction ; set "removed" flag
|
||||
jp UpdateSprites
|
||||
|
||||
MissableObjectFlagAction:
|
||||
; identical to FlagAction
|
||||
|
||||
push hl
|
||||
push de
|
||||
push bc
|
||||
|
||||
; bit
|
||||
ld a, c
|
||||
ld d, a
|
||||
and 7
|
||||
ld e, a
|
||||
|
||||
; byte
|
||||
ld a, d
|
||||
srl a
|
||||
srl a
|
||||
srl a
|
||||
add l
|
||||
ld l, a
|
||||
jr nc, .ok
|
||||
inc h
|
||||
.ok
|
||||
|
||||
; d = 1 << e (bitmask)
|
||||
inc e
|
||||
ld d, 1
|
||||
.shift
|
||||
dec e
|
||||
jr z, .shifted
|
||||
sla d
|
||||
jr .shift
|
||||
.shifted
|
||||
|
||||
ld a, b
|
||||
and a
|
||||
jr z, .reset
|
||||
cp 2
|
||||
jr z, .read
|
||||
|
||||
.set
|
||||
ld a, [hl]
|
||||
ld b, a
|
||||
ld a, d
|
||||
or b
|
||||
ld [hl], a
|
||||
jr .done
|
||||
|
||||
.reset
|
||||
ld a, [hl]
|
||||
ld b, a
|
||||
ld a, d
|
||||
xor $ff
|
||||
and b
|
||||
ld [hl], a
|
||||
jr .done
|
||||
|
||||
.read
|
||||
ld a, [hl]
|
||||
ld b, a
|
||||
ld a, d
|
||||
and b
|
||||
|
||||
.done
|
||||
pop bc
|
||||
pop de
|
||||
pop hl
|
||||
ld c, a
|
||||
ret
|
||||
463
engine/overworld/player_state.asm
Normal file
463
engine/overworld/player_state.asm
Normal file
|
|
@ -0,0 +1,463 @@
|
|||
; only used for setting bit 2 of wd736 upon entering a new map
|
||||
IsPlayerStandingOnWarp:
|
||||
ld a, [wNumberOfWarps]
|
||||
and a
|
||||
ret z
|
||||
ld c, a
|
||||
ld hl, wWarpEntries
|
||||
.loop
|
||||
ld a, [wYCoord]
|
||||
cp [hl]
|
||||
jr nz, .nextWarp1
|
||||
inc hl
|
||||
ld a, [wXCoord]
|
||||
cp [hl]
|
||||
jr nz, .nextWarp2
|
||||
inc hl
|
||||
ld a, [hli] ; target warp
|
||||
ld [wDestinationWarpID], a
|
||||
ld a, [hl] ; target map
|
||||
ld [hWarpDestinationMap], a
|
||||
ld hl, wd736
|
||||
set 2, [hl] ; standing on warp flag
|
||||
ret
|
||||
.nextWarp1
|
||||
inc hl
|
||||
.nextWarp2
|
||||
inc hl
|
||||
inc hl
|
||||
inc hl
|
||||
dec c
|
||||
jr nz, .loop
|
||||
ret
|
||||
|
||||
CheckForceBikeOrSurf:
|
||||
ld hl, wd732
|
||||
bit 5, [hl]
|
||||
ret nz
|
||||
ld hl, ForcedBikeOrSurfMaps
|
||||
ld a, [wYCoord]
|
||||
ld b, a
|
||||
ld a, [wXCoord]
|
||||
ld c, a
|
||||
ld a, [wCurMap]
|
||||
ld d, a
|
||||
.loop
|
||||
ld a, [hli]
|
||||
cp $ff
|
||||
ret z ;if we reach FF then it's not part of the list
|
||||
cp d ;compare to current map
|
||||
jr nz, .incorrectMap
|
||||
ld a, [hli]
|
||||
cp b ;compare y-coord
|
||||
jr nz, .incorrectY
|
||||
ld a, [hli]
|
||||
cp c ;compare x-coord
|
||||
jr nz, .loop ; incorrect x-coord, check next item
|
||||
ld a, [wCurMap]
|
||||
cp SEAFOAM_ISLANDS_4
|
||||
ld a, $2
|
||||
ld [wSeafoamIslands4CurScript], a
|
||||
jr z, .forceSurfing
|
||||
ld a, [wCurMap]
|
||||
cp SEAFOAM_ISLANDS_5
|
||||
ld a, $2
|
||||
ld [wSeafoamIslands5CurScript], a
|
||||
jr z, .forceSurfing
|
||||
;force bike riding
|
||||
ld hl, wd732
|
||||
set 5, [hl]
|
||||
ld a, $1
|
||||
ld [wWalkBikeSurfState], a
|
||||
ld [wWalkBikeSurfStateCopy], a
|
||||
jp ForceBikeOrSurf
|
||||
.incorrectMap
|
||||
inc hl
|
||||
.incorrectY
|
||||
inc hl
|
||||
jr .loop
|
||||
.forceSurfing
|
||||
ld a, $2
|
||||
ld [wWalkBikeSurfState], a
|
||||
ld [wWalkBikeSurfStateCopy], a
|
||||
jp ForceBikeOrSurf
|
||||
|
||||
INCLUDE "data/force_bike_surf.asm"
|
||||
|
||||
IsPlayerFacingEdgeOfMap:
|
||||
push hl
|
||||
push de
|
||||
push bc
|
||||
ld a, [wSpriteStateData1 + 9] ; player sprite's facing direction
|
||||
srl a
|
||||
ld c, a
|
||||
ld b, $0
|
||||
ld hl, .functionPointerTable
|
||||
add hl, bc
|
||||
ld a, [hli]
|
||||
ld h, [hl]
|
||||
ld l, a
|
||||
ld a, [wYCoord]
|
||||
ld b, a
|
||||
ld a, [wXCoord]
|
||||
ld c, a
|
||||
ld de, .asm_c41e
|
||||
push de
|
||||
jp [hl]
|
||||
.asm_c41e
|
||||
pop bc
|
||||
pop de
|
||||
pop hl
|
||||
ret
|
||||
|
||||
.functionPointerTable
|
||||
dw .facingDown
|
||||
dw .facingUp
|
||||
dw .facingLeft
|
||||
dw .facingRight
|
||||
|
||||
.facingDown
|
||||
ld a, [wCurMapHeight]
|
||||
add a
|
||||
dec a
|
||||
cp b
|
||||
jr z, .setCarry
|
||||
jr .resetCarry
|
||||
|
||||
.facingUp
|
||||
ld a, b
|
||||
and a
|
||||
jr z, .setCarry
|
||||
jr .resetCarry
|
||||
|
||||
.facingLeft
|
||||
ld a, c
|
||||
and a
|
||||
jr z, .setCarry
|
||||
jr .resetCarry
|
||||
|
||||
.facingRight
|
||||
ld a, [wCurMapWidth]
|
||||
add a
|
||||
dec a
|
||||
cp c
|
||||
jr z, .setCarry
|
||||
jr .resetCarry
|
||||
.resetCarry
|
||||
and a
|
||||
ret
|
||||
.setCarry
|
||||
scf
|
||||
ret
|
||||
|
||||
IsWarpTileInFrontOfPlayer:
|
||||
push hl
|
||||
push de
|
||||
push bc
|
||||
call _GetTileAndCoordsInFrontOfPlayer
|
||||
ld a, [wCurMap]
|
||||
cp SS_ANNE_5
|
||||
jr z, .ssAnne5
|
||||
ld a, [wSpriteStateData1 + 9] ; player sprite's facing direction
|
||||
srl a
|
||||
ld c, a
|
||||
ld b, 0
|
||||
ld hl, .warpTileListPointers
|
||||
add hl, bc
|
||||
ld a, [hli]
|
||||
ld h, [hl]
|
||||
ld l, a
|
||||
ld a, [wTileInFrontOfPlayer]
|
||||
ld de, $1
|
||||
call IsInArray
|
||||
.done
|
||||
pop bc
|
||||
pop de
|
||||
pop hl
|
||||
ret
|
||||
|
||||
.warpTileListPointers:
|
||||
dw .facingDownWarpTiles
|
||||
dw .facingUpWarpTiles
|
||||
dw .facingLeftWarpTiles
|
||||
dw .facingRightWarpTiles
|
||||
|
||||
.facingDownWarpTiles
|
||||
db $01,$12,$17,$3D,$04,$18,$33,$FF
|
||||
|
||||
.facingUpWarpTiles
|
||||
db $01,$5C,$FF
|
||||
|
||||
.facingLeftWarpTiles
|
||||
db $1A,$4B,$FF
|
||||
|
||||
.facingRightWarpTiles
|
||||
db $0F,$4E,$FF
|
||||
|
||||
.ssAnne5
|
||||
ld a, [wTileInFrontOfPlayer]
|
||||
cp $15
|
||||
jr nz, .notSSAnne5Warp
|
||||
scf
|
||||
jr .done
|
||||
.notSSAnne5Warp
|
||||
and a
|
||||
jr .done
|
||||
|
||||
IsPlayerStandingOnDoorTileOrWarpTile:
|
||||
push hl
|
||||
push de
|
||||
push bc
|
||||
callba IsPlayerStandingOnDoorTile
|
||||
jr c, .done
|
||||
ld a, [wCurMapTileset]
|
||||
add a
|
||||
ld c, a
|
||||
ld b, $0
|
||||
ld hl, WarpTileIDPointers
|
||||
add hl, bc
|
||||
ld a, [hli]
|
||||
ld h, [hl]
|
||||
ld l, a
|
||||
ld de, $1
|
||||
aCoord 8, 9
|
||||
call IsInArray
|
||||
jr nc, .done
|
||||
ld hl, wd736
|
||||
res 2, [hl]
|
||||
.done
|
||||
pop bc
|
||||
pop de
|
||||
pop hl
|
||||
ret
|
||||
|
||||
INCLUDE "data/warp_tile_ids.asm"
|
||||
|
||||
PrintSafariZoneSteps:
|
||||
ld a, [wCurMap]
|
||||
cp SAFARI_ZONE_EAST
|
||||
ret c
|
||||
cp UNKNOWN_DUNGEON_2
|
||||
ret nc
|
||||
coord hl, 0, 0
|
||||
ld b, 3
|
||||
ld c, 7
|
||||
call TextBoxBorder
|
||||
coord hl, 1, 1
|
||||
ld de, wSafariSteps
|
||||
lb bc, 2, 3
|
||||
call PrintNumber
|
||||
coord hl, 4, 1
|
||||
ld de, SafariSteps
|
||||
call PlaceString
|
||||
coord hl, 1, 3
|
||||
ld de, SafariBallText
|
||||
call PlaceString
|
||||
ld a, [wNumSafariBalls]
|
||||
cp 10
|
||||
jr nc, .asm_c56d
|
||||
coord hl, 5, 3
|
||||
ld a, " "
|
||||
ld [hl], a
|
||||
.asm_c56d
|
||||
coord hl, 6, 3
|
||||
ld de, wNumSafariBalls
|
||||
lb bc, 1, 2
|
||||
jp PrintNumber
|
||||
|
||||
SafariSteps:
|
||||
db "/500@"
|
||||
|
||||
SafariBallText:
|
||||
db "BALL×× @"
|
||||
|
||||
GetTileAndCoordsInFrontOfPlayer:
|
||||
call GetPredefRegisters
|
||||
|
||||
_GetTileAndCoordsInFrontOfPlayer:
|
||||
ld a, [wYCoord]
|
||||
ld d, a
|
||||
ld a, [wXCoord]
|
||||
ld e, a
|
||||
ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
|
||||
and a ; cp SPRITE_FACING_DOWN
|
||||
jr nz, .notFacingDown
|
||||
; facing down
|
||||
aCoord 8, 11
|
||||
inc d
|
||||
jr .storeTile
|
||||
.notFacingDown
|
||||
cp SPRITE_FACING_UP
|
||||
jr nz, .notFacingUp
|
||||
; facing up
|
||||
aCoord 8, 7
|
||||
dec d
|
||||
jr .storeTile
|
||||
.notFacingUp
|
||||
cp SPRITE_FACING_LEFT
|
||||
jr nz, .notFacingLeft
|
||||
; facing left
|
||||
aCoord 6, 9
|
||||
dec e
|
||||
jr .storeTile
|
||||
.notFacingLeft
|
||||
cp SPRITE_FACING_RIGHT
|
||||
jr nz, .storeTile
|
||||
; facing right
|
||||
aCoord 10, 9
|
||||
inc e
|
||||
.storeTile
|
||||
ld c, a
|
||||
ld [wTileInFrontOfPlayer], a
|
||||
ret
|
||||
|
||||
GetTileTwoStepsInFrontOfPlayer:
|
||||
xor a
|
||||
ld [$ffdb], a
|
||||
ld hl, wYCoord
|
||||
ld a, [hli]
|
||||
ld d, a
|
||||
ld e, [hl]
|
||||
ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
|
||||
and a ; cp SPRITE_FACING_DOWN
|
||||
jr nz, .notFacingDown
|
||||
; facing down
|
||||
ld hl, $ffdb
|
||||
set 0, [hl]
|
||||
aCoord 8, 13
|
||||
inc d
|
||||
jr .storeTile
|
||||
.notFacingDown
|
||||
cp SPRITE_FACING_UP
|
||||
jr nz, .notFacingUp
|
||||
; facing up
|
||||
ld hl, $ffdb
|
||||
set 1, [hl]
|
||||
aCoord 8, 5
|
||||
dec d
|
||||
jr .storeTile
|
||||
.notFacingUp
|
||||
cp SPRITE_FACING_LEFT
|
||||
jr nz, .notFacingLeft
|
||||
; facing left
|
||||
ld hl, $ffdb
|
||||
set 2, [hl]
|
||||
aCoord 4, 9
|
||||
dec e
|
||||
jr .storeTile
|
||||
.notFacingLeft
|
||||
cp SPRITE_FACING_RIGHT
|
||||
jr nz, .storeTile
|
||||
; facing right
|
||||
ld hl, $ffdb
|
||||
set 3, [hl]
|
||||
aCoord 12, 9
|
||||
inc e
|
||||
.storeTile
|
||||
ld c, a
|
||||
ld [wTileInFrontOfBoulderAndBoulderCollisionResult], a
|
||||
ld [wTileInFrontOfPlayer], a
|
||||
ret
|
||||
|
||||
CheckForCollisionWhenPushingBoulder:
|
||||
call GetTileTwoStepsInFrontOfPlayer
|
||||
ld hl, wTilesetCollisionPtr
|
||||
ld a, [hli]
|
||||
ld h, [hl]
|
||||
ld l, a
|
||||
.loop
|
||||
ld a, [hli]
|
||||
cp $ff
|
||||
jr z, .done ; if the tile two steps ahead is not passable
|
||||
cp c
|
||||
jr nz, .loop
|
||||
ld hl, TilePairCollisionsLand
|
||||
call CheckForTilePairCollisions2
|
||||
ld a, $ff
|
||||
jr c, .done ; if there is an elevation difference between the current tile and the one two steps ahead
|
||||
ld a, [wTileInFrontOfBoulderAndBoulderCollisionResult]
|
||||
cp $15 ; stairs tile
|
||||
ld a, $ff
|
||||
jr z, .done ; if the tile two steps ahead is stairs
|
||||
call CheckForBoulderCollisionWithSprites
|
||||
.done
|
||||
ld [wTileInFrontOfBoulderAndBoulderCollisionResult], a
|
||||
ret
|
||||
|
||||
; sets a to $ff if there is a collision and $00 if there is no collision
|
||||
CheckForBoulderCollisionWithSprites:
|
||||
ld a, [wBoulderSpriteIndex]
|
||||
dec a
|
||||
swap a
|
||||
ld d, 0
|
||||
ld e, a
|
||||
ld hl, wSpriteStateData2 + $14
|
||||
add hl, de
|
||||
ld a, [hli] ; map Y position
|
||||
ld [$ffdc], a
|
||||
ld a, [hl] ; map X position
|
||||
ld [$ffdd], a
|
||||
ld a, [wNumSprites]
|
||||
ld c, a
|
||||
ld de, $f
|
||||
ld hl, wSpriteStateData2 + $14
|
||||
ld a, [$ffdb]
|
||||
and $3 ; facing up or down?
|
||||
jr z, .pushingHorizontallyLoop
|
||||
.pushingVerticallyLoop
|
||||
inc hl
|
||||
ld a, [$ffdd]
|
||||
cp [hl]
|
||||
jr nz, .nextSprite1 ; if X coordinates don't match
|
||||
dec hl
|
||||
ld a, [hli]
|
||||
ld b, a
|
||||
ld a, [$ffdb]
|
||||
rrca
|
||||
jr c, .pushingDown
|
||||
; pushing up
|
||||
ld a, [$ffdc]
|
||||
dec a
|
||||
jr .compareYCoords
|
||||
.pushingDown
|
||||
ld a, [$ffdc]
|
||||
inc a
|
||||
.compareYCoords
|
||||
cp b
|
||||
jr z, .failure
|
||||
.nextSprite1
|
||||
dec c
|
||||
jr z, .success
|
||||
add hl, de
|
||||
jr .pushingVerticallyLoop
|
||||
.pushingHorizontallyLoop
|
||||
ld a, [hli]
|
||||
ld b, a
|
||||
ld a, [$ffdc]
|
||||
cp b
|
||||
jr nz, .nextSprite2
|
||||
ld b, [hl]
|
||||
ld a, [$ffdb]
|
||||
bit 2, a
|
||||
jr nz, .pushingLeft
|
||||
; pushing right
|
||||
ld a, [$ffdd]
|
||||
inc a
|
||||
jr .compareXCoords
|
||||
.pushingLeft
|
||||
ld a, [$ffdd]
|
||||
dec a
|
||||
.compareXCoords
|
||||
cp b
|
||||
jr z, .failure
|
||||
.nextSprite2
|
||||
dec c
|
||||
jr z, .success
|
||||
add hl, de
|
||||
jr .pushingHorizontallyLoop
|
||||
.failure
|
||||
ld a, $ff
|
||||
ret
|
||||
.success
|
||||
xor a
|
||||
ret
|
||||
112
engine/overworld/poison.asm
Normal file
112
engine/overworld/poison.asm
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
ApplyOutOfBattlePoisonDamage:
|
||||
ld a, [wd730]
|
||||
add a
|
||||
jp c, .noBlackOut ; no black out if joypad states are being simulated
|
||||
ld a, [wPartyCount]
|
||||
and a
|
||||
jp z, .noBlackOut
|
||||
call IncrementDayCareMonExp
|
||||
ld a, [wStepCounter]
|
||||
and $3 ; is the counter a multiple of 4?
|
||||
jp nz, .noBlackOut ; only apply poison damage every fourth step
|
||||
ld [wWhichPokemon], a
|
||||
ld hl, wPartyMon1Status
|
||||
ld de, wPartySpecies
|
||||
.applyDamageLoop
|
||||
ld a, [hl]
|
||||
and (1 << PSN)
|
||||
jr z, .nextMon2 ; not poisoned
|
||||
dec hl
|
||||
dec hl
|
||||
ld a, [hld]
|
||||
ld b, a
|
||||
ld a, [hli]
|
||||
or b
|
||||
jr z, .nextMon ; already fainted
|
||||
; subtract 1 from HP
|
||||
ld a, [hl]
|
||||
dec a
|
||||
ld [hld], a
|
||||
inc a
|
||||
jr nz, .noBorrow
|
||||
; borrow 1 from upper byte of HP
|
||||
dec [hl]
|
||||
inc hl
|
||||
jr .nextMon
|
||||
.noBorrow
|
||||
ld a, [hli]
|
||||
or [hl]
|
||||
jr nz, .nextMon ; didn't faint from damage
|
||||
; the mon fainted from the damage
|
||||
push hl
|
||||
inc hl
|
||||
inc hl
|
||||
ld [hl], a
|
||||
ld a, [de]
|
||||
ld [wd11e], a
|
||||
push de
|
||||
ld a, [wWhichPokemon]
|
||||
ld hl, wPartyMonNicks
|
||||
call GetPartyMonName
|
||||
xor a
|
||||
ld [wJoyIgnore], a
|
||||
call EnableAutoTextBoxDrawing
|
||||
ld a, $d0
|
||||
ld [hSpriteIndexOrTextID], a
|
||||
call DisplayTextID
|
||||
pop de
|
||||
pop hl
|
||||
.nextMon
|
||||
inc hl
|
||||
inc hl
|
||||
.nextMon2
|
||||
inc de
|
||||
ld a, [de]
|
||||
inc a
|
||||
jr z, .applyDamageLoopDone
|
||||
ld bc, wPartyMon2 - wPartyMon1
|
||||
add hl, bc
|
||||
push hl
|
||||
ld hl, wWhichPokemon
|
||||
inc [hl]
|
||||
pop hl
|
||||
jr .applyDamageLoop
|
||||
.applyDamageLoopDone
|
||||
ld hl, wPartyMon1Status
|
||||
ld a, [wPartyCount]
|
||||
ld d, a
|
||||
ld e, 0
|
||||
.countPoisonedLoop
|
||||
ld a, [hl]
|
||||
and (1 << PSN)
|
||||
or e
|
||||
ld e, a
|
||||
ld bc, wPartyMon2 - wPartyMon1
|
||||
add hl, bc
|
||||
dec d
|
||||
jr nz, .countPoisonedLoop
|
||||
ld a, e
|
||||
and a ; are any party members poisoned?
|
||||
jr z, .skipPoisonEffectAndSound
|
||||
ld b, $2
|
||||
predef ChangeBGPalColor0_4Frames ; change BG white to dark grey for 4 frames
|
||||
ld a, SFX_POISONED
|
||||
call PlaySound
|
||||
.skipPoisonEffectAndSound
|
||||
predef AnyPartyAlive
|
||||
ld a, d
|
||||
and a
|
||||
jr nz, .noBlackOut
|
||||
call EnableAutoTextBoxDrawing
|
||||
ld a, $d1
|
||||
ld [hSpriteIndexOrTextID], a
|
||||
call DisplayTextID
|
||||
ld hl, wd72e
|
||||
set 5, [hl]
|
||||
ld a, $ff
|
||||
jr .done
|
||||
.noBlackOut
|
||||
xor a
|
||||
.done
|
||||
ld [wOutOfBattleBlackout], a
|
||||
ret
|
||||
105
engine/overworld/push_boulder.asm
Normal file
105
engine/overworld/push_boulder.asm
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
TryPushingBoulder:
|
||||
ld a, [wd728]
|
||||
bit 0, a ; using Strength?
|
||||
ret z
|
||||
ld a, [wFlags_0xcd60]
|
||||
bit 1, a ; has boulder dust animation from previous push played yet?
|
||||
ret nz
|
||||
xor a
|
||||
ld [hSpriteIndexOrTextID], a
|
||||
call IsSpriteInFrontOfPlayer
|
||||
ld a, [hSpriteIndexOrTextID]
|
||||
ld [wBoulderSpriteIndex], a
|
||||
and a
|
||||
jp z, ResetBoulderPushFlags
|
||||
ld hl, wSpriteStateData1 + 1
|
||||
ld d, $0
|
||||
ld a, [hSpriteIndexOrTextID]
|
||||
swap a
|
||||
ld e, a
|
||||
add hl, de
|
||||
res 7, [hl]
|
||||
call GetSpriteMovementByte2Pointer
|
||||
ld a, [hl]
|
||||
cp BOULDER_MOVEMENT_BYTE_2
|
||||
jp nz, ResetBoulderPushFlags
|
||||
ld hl, wFlags_0xcd60
|
||||
bit 6, [hl]
|
||||
set 6, [hl] ; indicate that the player has tried pushing
|
||||
ret z ; the player must try pushing twice before the boulder will move
|
||||
ld a, [hJoyHeld]
|
||||
and D_RIGHT | D_LEFT | D_UP | D_DOWN
|
||||
ret z
|
||||
predef CheckForCollisionWhenPushingBoulder
|
||||
ld a, [wTileInFrontOfBoulderAndBoulderCollisionResult]
|
||||
and a ; was there a collision?
|
||||
jp nz, ResetBoulderPushFlags
|
||||
ld a, [hJoyHeld]
|
||||
ld b, a
|
||||
ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
|
||||
cp SPRITE_FACING_UP
|
||||
jr z, .pushBoulderUp
|
||||
cp SPRITE_FACING_LEFT
|
||||
jr z, .pushBoulderLeft
|
||||
cp SPRITE_FACING_RIGHT
|
||||
jr z, .pushBoulderRight
|
||||
.pushBoulderDown
|
||||
bit 7, b
|
||||
ret z
|
||||
ld de, PushBoulderDownMovementData
|
||||
jr .done
|
||||
.pushBoulderUp
|
||||
bit 6, b
|
||||
ret z
|
||||
ld de, PushBoulderUpMovementData
|
||||
jr .done
|
||||
.pushBoulderLeft
|
||||
bit 5, b
|
||||
ret z
|
||||
ld de, PushBoulderLeftMovementData
|
||||
jr .done
|
||||
.pushBoulderRight
|
||||
bit 4, b
|
||||
ret z
|
||||
ld de, PushBoulderRightMovementData
|
||||
.done
|
||||
call MoveSprite
|
||||
ld a, SFX_PUSH_BOULDER
|
||||
call PlaySound
|
||||
ld hl, wFlags_0xcd60
|
||||
set 1, [hl]
|
||||
ret
|
||||
|
||||
PushBoulderUpMovementData:
|
||||
db NPC_MOVEMENT_UP,$FF
|
||||
|
||||
PushBoulderDownMovementData:
|
||||
db NPC_MOVEMENT_DOWN,$FF
|
||||
|
||||
PushBoulderLeftMovementData:
|
||||
db NPC_MOVEMENT_LEFT,$FF
|
||||
|
||||
PushBoulderRightMovementData:
|
||||
db NPC_MOVEMENT_RIGHT,$FF
|
||||
|
||||
DoBoulderDustAnimation:
|
||||
ld a, [wd730]
|
||||
bit 0, a
|
||||
ret nz
|
||||
callab AnimateBoulderDust
|
||||
call DiscardButtonPresses
|
||||
ld [wJoyIgnore], a
|
||||
call ResetBoulderPushFlags
|
||||
set 7, [hl]
|
||||
ld a, [wBoulderSpriteIndex]
|
||||
ld [H_SPRITEINDEX], a
|
||||
call GetSpriteMovementByte2Pointer
|
||||
ld [hl], $10
|
||||
ld a, SFX_CUT
|
||||
jp PlaySound
|
||||
|
||||
ResetBoulderPushFlags:
|
||||
ld hl, wFlags_0xcd60
|
||||
res 1, [hl]
|
||||
res 6, [hl]
|
||||
ret
|
||||
60
engine/overworld/tileset_header.asm
Normal file
60
engine/overworld/tileset_header.asm
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
LoadTilesetHeader:
|
||||
call GetPredefRegisters
|
||||
push hl
|
||||
ld d, 0
|
||||
ld a, [wCurMapTileset]
|
||||
add a
|
||||
add a
|
||||
ld b, a
|
||||
add a
|
||||
add b ; a = tileset * 12
|
||||
jr nc, .noCarry
|
||||
inc d
|
||||
.noCarry
|
||||
ld e, a
|
||||
ld hl, Tilesets
|
||||
add hl, de
|
||||
ld de, wTilesetBank
|
||||
ld c, $b
|
||||
.copyTilesetHeaderLoop
|
||||
ld a, [hli]
|
||||
ld [de], a
|
||||
inc de
|
||||
dec c
|
||||
jr nz, .copyTilesetHeaderLoop
|
||||
ld a, [hl]
|
||||
ld [hTilesetType], a
|
||||
xor a
|
||||
ld [$ffd8], a
|
||||
pop hl
|
||||
ld a, [wCurMapTileset]
|
||||
push hl
|
||||
push de
|
||||
ld hl, DungeonTilesets
|
||||
ld de, $1
|
||||
call IsInArray
|
||||
pop de
|
||||
pop hl
|
||||
jr c, .asm_c797
|
||||
ld a, [wCurMapTileset]
|
||||
ld b, a
|
||||
ld a, [hPreviousTileset]
|
||||
cp b
|
||||
jr z, .done
|
||||
.asm_c797
|
||||
ld a, [wDestinationWarpID]
|
||||
cp $ff
|
||||
jr z, .done
|
||||
call LoadDestinationWarpPosition
|
||||
ld a, [wYCoord]
|
||||
and $1
|
||||
ld [wYBlockCoord], a
|
||||
ld a, [wXCoord]
|
||||
and $1
|
||||
ld [wXBlockCoord], a
|
||||
.done
|
||||
ret
|
||||
|
||||
INCLUDE "data/dungeon_tilesets.asm"
|
||||
|
||||
INCLUDE "data/tileset_headers.asm"
|
||||
126
engine/overworld/update_map.asm
Normal file
126
engine/overworld/update_map.asm
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
; replaces a tile block with the one specified in [wNewTileBlockID]
|
||||
; and redraws the map view if necessary
|
||||
; b = Y
|
||||
; c = X
|
||||
ReplaceTileBlock:
|
||||
call GetPredefRegisters
|
||||
ld hl, wOverworldMap
|
||||
ld a, [wCurMapWidth]
|
||||
add $6
|
||||
ld e, a
|
||||
ld d, $0
|
||||
add hl, de
|
||||
add hl, de
|
||||
add hl, de
|
||||
ld e, $3
|
||||
add hl, de
|
||||
ld e, a
|
||||
ld a, b
|
||||
and a
|
||||
jr z, .addX
|
||||
; add width * Y
|
||||
.addWidthYTimesLoop
|
||||
add hl, de
|
||||
dec b
|
||||
jr nz, .addWidthYTimesLoop
|
||||
.addX
|
||||
add hl, bc ; add X
|
||||
ld a, [wNewTileBlockID]
|
||||
ld [hl], a
|
||||
ld a, [wCurrentTileBlockMapViewPointer]
|
||||
ld c, a
|
||||
ld a, [wCurrentTileBlockMapViewPointer + 1]
|
||||
ld b, a
|
||||
call CompareHLWithBC
|
||||
ret c ; return if the replaced tile block is below the map view in memory
|
||||
push hl
|
||||
ld l, e
|
||||
ld h, $0
|
||||
ld e, $6
|
||||
ld d, h
|
||||
add hl, hl
|
||||
add hl, hl
|
||||
add hl, de
|
||||
add hl, bc
|
||||
pop bc
|
||||
call CompareHLWithBC
|
||||
ret c ; return if the replaced tile block is above the map view in memory
|
||||
|
||||
RedrawMapView:
|
||||
ld a, [wIsInBattle]
|
||||
inc a
|
||||
ret z
|
||||
ld a, [H_AUTOBGTRANSFERENABLED]
|
||||
push af
|
||||
ld a, [hTilesetType]
|
||||
push af
|
||||
xor a
|
||||
ld [H_AUTOBGTRANSFERENABLED], a
|
||||
ld [hTilesetType], a ; no flower/water BG tile animations
|
||||
call LoadCurrentMapView
|
||||
call RunDefaultPaletteCommand
|
||||
ld hl, wMapViewVRAMPointer
|
||||
ld a, [hli]
|
||||
ld h, [hl]
|
||||
ld l, a
|
||||
ld de, -2 * 32
|
||||
add hl, de
|
||||
ld a, h
|
||||
and $3
|
||||
or $98
|
||||
ld a, l
|
||||
ld [wBuffer], a
|
||||
ld a, h
|
||||
ld [wBuffer + 1], a ; this copy of the address is not used
|
||||
ld a, 2
|
||||
ld [$ffbe], a
|
||||
ld c, 9 ; number of rows of 2x2 tiles (this covers the whole screen)
|
||||
.redrawRowLoop
|
||||
push bc
|
||||
push hl
|
||||
push hl
|
||||
ld hl, wTileMap - 2 * SCREEN_WIDTH
|
||||
ld de, SCREEN_WIDTH
|
||||
ld a, [$ffbe]
|
||||
.calcWRAMAddrLoop
|
||||
add hl, de
|
||||
dec a
|
||||
jr nz, .calcWRAMAddrLoop
|
||||
call CopyToRedrawRowOrColumnSrcTiles
|
||||
pop hl
|
||||
ld de, $20
|
||||
ld a, [$ffbe]
|
||||
ld c, a
|
||||
.calcVRAMAddrLoop
|
||||
add hl, de
|
||||
ld a, h
|
||||
and $3
|
||||
or $98
|
||||
dec c
|
||||
jr nz, .calcVRAMAddrLoop
|
||||
ld [hRedrawRowOrColumnDest + 1], a
|
||||
ld a, l
|
||||
ld [hRedrawRowOrColumnDest], a
|
||||
ld a, REDRAW_ROW
|
||||
ld [hRedrawRowOrColumnMode], a
|
||||
call DelayFrame
|
||||
ld hl, $ffbe
|
||||
inc [hl]
|
||||
inc [hl]
|
||||
pop hl
|
||||
pop bc
|
||||
dec c
|
||||
jr nz, .redrawRowLoop
|
||||
pop af
|
||||
ld [hTilesetType], a
|
||||
pop af
|
||||
ld [H_AUTOBGTRANSFERENABLED], a
|
||||
ret
|
||||
|
||||
CompareHLWithBC:
|
||||
ld a, h
|
||||
sub b
|
||||
ret nz
|
||||
ld a, l
|
||||
sub c
|
||||
ret
|
||||
33
engine/overworld/wild_mons.asm
Normal file
33
engine/overworld/wild_mons.asm
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
LoadWildData:
|
||||
ld hl,WildDataPointers
|
||||
ld a,[wCurMap]
|
||||
|
||||
; get wild data for current map
|
||||
ld c,a
|
||||
ld b,0
|
||||
add hl,bc
|
||||
add hl,bc
|
||||
ld a,[hli]
|
||||
ld h,[hl]
|
||||
ld l,a ; hl now points to wild data for current map
|
||||
ld a,[hli]
|
||||
ld [wGrassRate],a
|
||||
and a
|
||||
jr z,.NoGrassData ; if no grass data, skip to surfing data
|
||||
push hl
|
||||
ld de,wGrassMons ; otherwise, load grass data
|
||||
ld bc,$0014
|
||||
call CopyData
|
||||
pop hl
|
||||
ld bc,$0014
|
||||
add hl,bc
|
||||
.NoGrassData
|
||||
ld a,[hli]
|
||||
ld [wWaterRate],a
|
||||
and a
|
||||
ret z ; if no water data, we're done
|
||||
ld de,wWaterMons ; otherwise, load surfing data
|
||||
ld bc,$0014
|
||||
jp CopyData
|
||||
|
||||
INCLUDE "data/wild_mons.asm"
|
||||
Loading…
Add table
Add a link
Reference in a new issue