Organize the engine/ directory

This is an informed attempt at reorganizing the engine/ directory by
creating categorized subdirectories, in order to make it easier to
navigate and find things.

The directories created are as follows:
* engine/game: Contains all "minigames", things like the unown puzzle
and slot machine.
* engine/gfx: Contains all handling of graphics. From loading palettes
to playing animations.
* engine/link: Contains all multiplayer functionality.
* engine/menu: Contains all generic/misc. menus and menu code.
Other, more specialized menus are in their own subdirectories (pokedex,
pokegear, party menu, etc).
* engine/overworld: Contains all handling of the overworld. From loading
and connecting maps to wild encounters and the scripting engine.
* engine/pokegear: In the same vein as engine/pokedex, except it could
use some more splitting up.
* engine/pokemon: Contains everything related to manipulating pokemon
data. From the pokemon storage system to evolution and mail.
* engine/printer: Contains everything related to printing things as well
as the printer communication.
* engine/title: Contains intro sequences, title screens and credits.
This commit is contained in:
mid-kid
2018-03-13 13:07:16 +01:00
parent 12070ca500
commit baa0dc5a96
106 changed files with 104 additions and 104 deletions

1303
engine/overworld/decorations.asm Executable file

File diff suppressed because it is too large Load Diff

1111
engine/overworld/events.asm Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,650 @@
; More overworld event handling.
WarpToSpawnPoint:: ; 97c28
ld hl, wStatusFlags2
res STATUSFLAGS2_SAFARI_GAME_F, [hl]
res STATUSFLAGS2_BUG_CONTEST_TIMER_F, [hl]
ret
; 97c30
RunMemScript:: ; 97c30
; If there is no script here, we don't need to be here.
ld a, [wMapReentryScriptQueueFlag]
and a
ret z
; Execute the script at (wMapReentryScriptBank):(wMapReentryScriptAddress).
ld hl, wMapReentryScriptAddress
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wMapReentryScriptBank]
call CallScript
scf
; Clear the buffer for the next script.
push af
xor a
ld hl, wMapReentryScriptQueueFlag
ld bc, 8
call ByteFill
pop af
ret
; 97c4f
LoadScriptBDE:: ; 97c4f
; If there's already a script here, don't overwrite.
ld hl, wMapReentryScriptQueueFlag
ld a, [hl]
and a
ret nz
; Set the flag
ld [hl], 1
inc hl
; Load the script pointer b:de into (wMapReentryScriptBank):(wMapReentryScriptAddress)
ld [hl], b
inc hl
ld [hl], e
inc hl
ld [hl], d
scf
ret
; 97c5f
TryTileCollisionEvent:: ; 97c5f
call GetFacingTileCoord
ld [wEngineBuffer1], a
ld c, a
farcall CheckFacingTileForStdScript
jr c, .done
call CheckCutTreeTile
jr nz, .whirlpool
farcall TryCutOW
jr .done
.whirlpool
ld a, [wEngineBuffer1]
call CheckWhirlpoolTile
jr nz, .waterfall
farcall TryWhirlpoolOW
jr .done
.waterfall
ld a, [wEngineBuffer1]
call CheckWaterfallTile
jr nz, .headbutt
farcall TryWaterfallOW
jr .done
.headbutt
ld a, [wEngineBuffer1]
call CheckHeadbuttTreeTile
jr nz, .surf
farcall TryHeadbuttOW
jr c, .done
jr .noevent
.surf
farcall TrySurfOW
jr nc, .noevent
jr .done
.noevent
xor a
ret
.done
call PlayClickSFX
ld a, $ff
scf
ret
; 97cc0
RandomEncounter:: ; 97cc0
; Random encounter
call CheckWildEncounterCooldown
jr c, .nope
call CanUseSweetScent
jr nc, .nope
ld hl, wStatusFlags2
bit STATUSFLAGS2_BUG_CONTEST_TIMER_F, [hl]
jr nz, .bug_contest
farcall TryWildEncounter
jr nz, .nope
jr .ok
.bug_contest
call _TryWildEncounter_BugContest
jr nc, .nope
jr .ok_bug_contest
.nope
ld a, 1
and a
ret
.ok
ld a, BANK(WildBattleScript)
ld hl, WildBattleScript
jr .done
.ok_bug_contest
ld a, BANK(BugCatchingContestBattleScript)
ld hl, BugCatchingContestBattleScript
jr .done
.done
call CallScript
scf
ret
; 97cf9
WildBattleScript: ; 97cf9
randomwildmon
startbattle
reloadmapafterbattle
end
; 97cfd
CanUseSweetScent:: ; 97cfd
ld hl, wStatusFlags
bit STATUSFLAGS_NO_WILD_ENCOUNTERS_F, [hl]
jr nz, .no
ld a, [wEnvironment]
cp CAVE
jr z, .ice_check
cp DUNGEON
jr z, .ice_check
farcall CheckGrassCollision
jr nc, .no
.ice_check
ld a, [wPlayerStandingTile]
call CheckIceTile
jr z, .no
scf
ret
.no
and a
ret
; 97d23
_TryWildEncounter_BugContest: ; 97d23
call TryWildEncounter_BugContest
ret nc
call ChooseWildEncounter_BugContest
farcall CheckRepelEffect
ret
; 97d31
ChooseWildEncounter_BugContest:: ; 97d31
; Pick a random mon out of ContestMons.
.loop
call Random
cp 100 << 1
jr nc, .loop
srl a
ld hl, ContestMons
ld de, 4
.CheckMon:
sub [hl]
jr c, .GotMon
add hl, de
jr .CheckMon
.GotMon:
inc hl
; Species
ld a, [hli]
ld [wTempWildMonSpecies], a
; Min level
ld a, [hli]
ld d, a
; Max level
ld a, [hl]
sub d
jr nz, .RandomLevel
; If min and max are the same.
ld a, d
jr .GotLevel
.RandomLevel:
; Get a random level between the min and max.
ld c, a
inc c
call Random
ld a, [hRandomAdd]
call SimpleDivide
add d
.GotLevel:
ld [wCurPartyLevel], a
xor a
ret
; 97d64
TryWildEncounter_BugContest: ; 97d64
ld a, [wPlayerStandingTile]
call CheckSuperTallGrassTile
ld b, 40 percent
jr z, .ok
ld b, 20 percent
.ok
farcall ApplyMusicEffectOnEncounterRate
farcall ApplyCleanseTagEffectOnEncounterRate
call Random
ld a, [hRandomAdd]
cp b
ret c
ld a, 1
and a
ret
; 97d87
INCLUDE "data/wild/bug_contest_mons.asm"
DoBikeStep:: ; 97db3
nop
nop
; If the bike shop owner doesn't have our number, or
; if we've already gotten the call, we don't have to
; be here.
ld hl, wStatusFlags2
bit STATUSFLAGS2_BIKE_SHOP_CALL_F, [hl]
jr z, .NoCall
; If we're not on the bike, we don't have to be here.
ld a, [wPlayerState]
cp PLAYER_BIKE
jr nz, .NoCall
; If we're not in an area of phone service, we don't
; have to be here.
call GetMapPhoneService
and a
jr nz, .NoCall
; Check the bike step count and check whether we've
; taken 65536 of them yet.
ld hl, wBikeStep
ld a, [hli]
ld d, a
ld e, [hl]
cp 255
jr nz, .increment
ld a, e
cp 255
jr z, .dont_increment
.increment
inc de
ld [hl], e
dec hl
ld [hl], d
.dont_increment
; If we've taken at least 1024 steps, have the bike
; shop owner try to call us.
ld a, d
cp HIGH(1024)
jr c, .NoCall
; If a call has already been queued, don't overwrite
; that call.
ld a, [wSpecialPhoneCallID]
and a
jr nz, .NoCall
; Queue the call.
ld a, SPECIALCALL_BIKESHOP
ld [wSpecialPhoneCallID], a
xor a
ld [wSpecialPhoneCallID + 1], a
ld hl, wStatusFlags2
res STATUSFLAGS2_BIKE_SHOP_CALL_F, [hl]
scf
ret
.NoCall:
xor a
ret
; 97df9
ClearCmdQueue:: ; 97df9
ld hl, wCmdQueue
ld de, 6
ld c, 4
xor a
.loop
ld [hl], a
add hl, de
dec c
jr nz, .loop
ret
; 97e08
HandleCmdQueue:: ; 97e08
ld hl, wCmdQueue
xor a
.loop
ld [hMapObjectIndexBuffer], a
ld a, [hl]
and a
jr z, .skip
push hl
ld b, h
ld c, l
call HandleQueuedCommand
pop hl
.skip
ld de, CMDQUEUE_ENTRY_SIZE
add hl, de
ld a, [hMapObjectIndexBuffer]
inc a
cp CMDQUEUE_CAPACITY
jr nz, .loop
ret
; 97e25
Unreferenced_GetNthCmdQueueEntry: ; 97e25
ld hl, wCmdQueue
ld bc, CMDQUEUE_ENTRY_SIZE
call AddNTimes
ld b, h
ld c, l
ret
; 97e31
WriteCmdQueue:: ; 97e31
push bc
push de
call .GetNextEmptyEntry
ld d, h
ld e, l
pop hl
pop bc
ret c
ld a, b
ld bc, CMDQUEUE_ENTRY_SIZE - 1
call FarCopyBytes
xor a
ld [hl], a
ret
; 97e45
.GetNextEmptyEntry: ; 97e45
ld hl, wCmdQueue
ld de, CMDQUEUE_ENTRY_SIZE
ld c, CMDQUEUE_CAPACITY
.loop
ld a, [hl]
and a
jr z, .done
add hl, de
dec c
jr nz, .loop
scf
ret
.done
ld a, CMDQUEUE_CAPACITY
sub c
and a
ret
; 97e5c
DelCmdQueue:: ; 97e5c
ld hl, wCmdQueue
ld de, CMDQUEUE_ENTRY_SIZE
ld c, CMDQUEUE_CAPACITY
.loop
ld a, [hl]
cp b
jr z, .done
add hl, de
dec c
jr nz, .loop
and a
ret
.done
xor a
ld [hl], a
scf
ret
; 97e72
_DelCmdQueue: ; 97e72
ld hl, CMDQUEUE_TYPE
add hl, bc
ld [hl], 0
ret
; 97e79
HandleQueuedCommand: ; 97e79
ld hl, CMDQUEUE_TYPE
add hl, bc
ld a, [hl]
cp 5
jr c, .okay
xor a
.okay
ld e, a
ld d, 0
ld hl, .Jumptable
add hl, de
add hl, de
add hl, de
ld a, [hli]
push af
ld a, [hli]
ld h, [hl]
ld l, a
pop af
rst FarCall
ret
; 97e94
.Jumptable: ; 97e94
dba CmdQueue_Null
dba CmdQueue_Null2
dba CmdQueue_StoneTable
dba CmdQueue_Type3
dba CmdQueue_Type4
; 97ea3
CmdQueueAnonymousJumptable: ; 97ea3
ld hl, CMDQUEUE_05
add hl, bc
ld a, [hl]
pop hl
rst JumpTable
ret
; 97eab
CmdQueueAnonJT_Increment: ; 97eab
ld hl, CMDQUEUE_05
add hl, bc
inc [hl]
ret
; 97eb1
CmdQueueAnonJT_Decrement: ; 97eb1
ld hl, CMDQUEUE_05
add hl, bc
dec [hl]
ret
; 97eb7
CmdQueue_Null: ; 97eb7
ret
; 97eb8
CmdQueue_Null2: ; 97eb8
call ret_2f3e
ret
; 97ebc
CmdQueue_Type4: ; 97ebc
call CmdQueueAnonymousJumptable
; anonymous dw
dw .zero
dw .one
; 97ec3
.zero ; 97ec3
ld a, [hSCY]
ld hl, 4
add hl, bc
ld [hl], a
call CmdQueueAnonJT_Increment
.one ; 97ecd
ld hl, 1
add hl, bc
ld a, [hl]
dec a
ld [hl], a
jr z, .finish
and $1
jr z, .add
ld hl, 2
add hl, bc
ld a, [hSCY]
sub [hl]
ld [hSCY], a
ret
.add
ld hl, 2
add hl, bc
ld a, [hSCY]
add [hl]
ld [hSCY], a
ret
.finish
ld hl, 4
add hl, bc
ld a, [hl]
ld [hSCY], a
call _DelCmdQueue
ret
; 97ef9
CmdQueue_Type3: ; 97ef9
call CmdQueueAnonymousJumptable
; anonymous dw
dw .zero
dw .one
dw .two
; 97f02
.zero ; 97f02
call .IsPlayerFacingDown
jr z, .PlayerNotFacingDown
call CmdQueueAnonJT_Increment
.one ; 97f0a
call .IsPlayerFacingDown
jr z, .PlayerNotFacingDown
call CmdQueueAnonJT_Increment
ld hl, 2
add hl, bc
ld a, [hl]
ld [wd173], a
ret
; 97f1b
.two ; 97f1b
call .IsPlayerFacingDown
jr z, .PlayerNotFacingDown
call CmdQueueAnonJT_Decrement
ld hl, 3
add hl, bc
ld a, [hl]
ld [wd173], a
ret
; 97f2c
.PlayerNotFacingDown: ; 97f2c
ld a, $7f
ld [wd173], a
ld hl, 5
add hl, bc
ld [hl], 0
ret
; 97f38
.IsPlayerFacingDown: ; 97f38
push bc
ld bc, wPlayerStruct
call GetSpriteDirection
and a
pop bc
ret
; 97f42
CmdQueue_StoneTable: ; 97f42
ld de, wPlayerStruct
ld a, NUM_OBJECT_STRUCTS
.loop
push af
ld hl, OBJECT_SPRITE
add hl, de
ld a, [hl]
and a
jr z, .next
ld hl, OBJECT_MOVEMENTTYPE
add hl, de
ld a, [hl]
cp SPRITEMOVEDATA_STRENGTH_BOULDER
jr nz, .next
ld hl, OBJECT_NEXT_TILE
add hl, de
ld a, [hl]
call CheckPitTile
jr nz, .next
ld hl, OBJECT_DIRECTION_WALKING
add hl, de
ld a, [hl]
cp STANDING
jr nz, .next
call HandleStoneQueue
jr c, .fall_down_hole
.next
ld hl, OBJECT_STRUCT_LENGTH
add hl, de
ld d, h
ld e, l
pop af
dec a
jr nz, .loop
ret
.fall_down_hole
pop af
ret
; 97f7e

View File

@@ -0,0 +1,103 @@
ReanchorBGMap_NoOAMUpdate:: ; 6454
call DelayFrame
ld a, [hOAMUpdate]
push af
ld a, $1
ld [hOAMUpdate], a
ld a, [hBGMapMode]
push af
xor a
ld [hBGMapMode], a
call .ReanchorBGMap
pop af
ld [hBGMapMode], a
pop af
ld [hOAMUpdate], a
ld hl, wVramState
set 6, [hl]
ret
.ReanchorBGMap:
xor a
ld [hLCDCPointer], a
ld [hBGMapMode], a
ld a, $90
ld [hWY], a
call OverworldTextModeSwitch
ld a, HIGH(vBGMap1)
call .LoadBGMapAddrIntoHRAM
call _OpenAndCloseMenu_HDMATransferTileMapAndAttrMap
farcall LoadOW_BGPal7
farcall ApplyPals
ld a, $1
ld [hCGBPalUpdate], a
xor a
ld [hBGMapMode], a
ld [hWY], a
farcall HDMATransfer_FillBGMap0WithBlack ; no need to farcall
ld a, HIGH(vBGMap0)
call .LoadBGMapAddrIntoHRAM
xor a ; LOW(vBGMap0)
ld [wBGMapAnchor], a
ld a, HIGH(vBGMap0)
ld [wBGMapAnchor + 1], a
xor a
ld [hSCX], a
ld [hSCY], a
call ApplyBGMapAnchorToObjects
ret
.LoadBGMapAddrIntoHRAM: ; 64b9
ld [hBGMapAddress + 1], a
xor a
ld [hBGMapAddress], a
ret
LoadFonts_NoOAMUpdate:: ; 64bf
ld a, [hOAMUpdate]
push af
ld a, $1
ld [hOAMUpdate], a
call .LoadGFX
pop af
ld [hOAMUpdate], a
ret
.LoadGFX:
call LoadFontsExtra
ld a, $90
ld [hWY], a
call SafeUpdateSprites
call LoadStandardFont
ret
HDMATransfer_FillBGMap0WithBlack: ; 64db
ld a, [rSVBK]
push af
ld a, BANK(wDecompressScratch)
ld [rSVBK], a
ld a, "■"
ld hl, wDecompressScratch
ld bc, wScratchAttrMap - wDecompressScratch
call ByteFill
ld a, HIGH(wDecompressScratch)
ld [rHDMA1], a
ld a, LOW(wDecompressScratch)
ld [rHDMA2], a
ld a, HIGH(vBGMap0 % $8000)
ld [rHDMA3], a
ld a, LOW(vBGMap0 % $8000)
ld [rHDMA4], a
ld a, $3f
ld [hDMATransfer], a
call DelayFrame
pop af
ld [rSVBK], a
ret

View File

@@ -0,0 +1,87 @@
GetLandmarkCoords: ; 0x1ca896
; Return coordinates (d, e) of landmark e.
push hl
ld l, e
ld h, 0
add hl, hl
add hl, hl
ld de, Landmarks
add hl, de
ld a, [hli]
ld e, a
ld d, [hl]
pop hl
ret
; 0x1ca8a5
GetLandmarkName:: ; 0x1ca8a5
; Copy the name of landmark e to wStringBuffer1.
push hl
push de
push bc
ld l, e
ld h, 0
add hl, hl
add hl, hl
ld de, Landmarks + 2
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
ld de, wStringBuffer1
ld c, 18
.copy
ld a, [hli]
ld [de], a
inc de
dec c
jr nz, .copy
pop bc
pop de
pop hl
ret
; 0x1ca8c3
INCLUDE "data/maps/landmarks.asm"
RegionCheck: ; 0x1caea1
; Checks if the player is in Kanto or Johto.
; If in Johto, returns 0 in e.
; If in Kanto, returns 1 in e.
ld a, [wMapGroup]
ld b, a
ld a, [wMapNumber]
ld c, a
call GetWorldMapLocation
cp FAST_SHIP ; S.S. Aqua
jr z, .johto
cp SPECIAL_MAP
jr nz, .checkagain
; In a special map, get the backup map group / map id
ld a, [wBackupMapGroup]
ld b, a
ld a, [wBackupMapNumber]
ld c, a
call GetWorldMapLocation
.checkagain
cp KANTO_LANDMARK
jr c, .johto
; Victory Road area is considered to be Johto.
cp VICTORY_ROAD
jr c, .kanto
.johto
ld e, JOHTO_REGION
ret
.kanto
ld e, KANTO_REGION
ret

View File

@@ -0,0 +1,313 @@
ObjectActionPairPointers: ; 445f
; entries correspond to OBJECT_ACTION_* constants
dw SetFacingStanding, SetFacingStanding
dw SetFacingStandAction, SetFacingCurrent
dw SetFacingStepAction, SetFacingCurrent
dw SetFacingBumpAction, SetFacingCurrent
dw SetFacingCounterclockwiseSpin, SetFacingCurrent
dw SetFacingCounterclockwiseSpin2, SetFacingStanding
dw SetFacingFish, SetFacingFish
dw SetFacingShadow, SetFacingStanding
dw SetFacingEmote, SetFacingEmote
dw SetFacingBigDollSym, SetFacingBigDollSym
dw SetFacingBounce, SetFacingFreezeBounce
dw SetFacingWeirdTree, SetFacingCurrent
dw SetFacingBigDollAsym, SetFacingBigDollAsym
dw SetFacingBigDoll, SetFacingBigDoll
dw SetFacingBoulderDust, SetFacingStanding
dw SetFacingGrassShake, SetFacingStanding
dw SetFacingSkyfall, SetFacingCurrent
; 44a3
SetFacingStanding: ; 44a3
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], STANDING
ret
; 44aa
SetFacingCurrent: ; 44aa
call GetSpriteDirection
or FACING_STEP_DOWN_0 ; useless
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], a
ret
; 44b5
SetFacingStandAction: ; 44b5
ld hl, OBJECT_FACING_STEP
add hl, bc
ld a, [hl]
and 1
jr nz, SetFacingStepAction
jp SetFacingCurrent
; 44c1
SetFacingStepAction: ; 44c1
ld hl, OBJECT_FLAGS1
add hl, bc
bit SLIDING, [hl]
jp nz, SetFacingCurrent
ld hl, OBJECT_STEP_FRAME
add hl, bc
ld a, [hl]
inc a
and %00001111
ld [hl], a
rrca
rrca
and %00000011
ld d, a
call GetSpriteDirection
or FACING_STEP_DOWN_0 ; useless
or d
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], a
ret
; 44e4
SetFacingSkyfall: ; 44e4
ld hl, OBJECT_FLAGS1
add hl, bc
bit SLIDING, [hl]
jp nz, SetFacingCurrent
ld hl, OBJECT_STEP_FRAME
add hl, bc
ld a, [hl]
add 2
and %00001111
ld [hl], a
rrca
rrca
and %00000011
ld d, a
call GetSpriteDirection
or FACING_STEP_DOWN_0 ; useless
or d
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], a
ret
; 4508
SetFacingBumpAction: ; 4508
ld hl, OBJECT_FLAGS1
add hl, bc
bit SLIDING, [hl]
jp nz, SetFacingCurrent
ld hl, OBJECT_STEP_FRAME
add hl, bc
inc [hl]
ld a, [hl]
rrca
rrca
rrca
and %00000011
ld d, a
call GetSpriteDirection
or FACING_STEP_DOWN_0 ; useless
or d
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], a
ret
; 4529
SetFacingCounterclockwiseSpin: ; 4529
call CounterclockwiseSpinAction
ld hl, OBJECT_FACING
add hl, bc
ld a, [hl]
or FACING_STEP_DOWN_0 ; useless
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], a
ret
; 4539
SetFacingCounterclockwiseSpin2: ; 4539
call CounterclockwiseSpinAction
jp SetFacingStanding
; 453f
CounterclockwiseSpinAction: ; 453f
; Here, OBJECT_STEP_FRAME consists of two 2-bit components,
; using only bits 0,1 and 4,5.
; bits 0,1 is a timer (4 overworld frames)
; bits 4,5 determines the facing - the direction is counterclockwise.
ld hl, OBJECT_STEP_FRAME
add hl, bc
ld a, [hl]
and %11110000
ld e, a
ld a, [hl]
inc a
and %00001111
ld d, a
cp 4
jr c, .ok
ld d, 0
ld a, e
add $10
and %00110000
ld e, a
.ok
ld a, d
or e
ld [hl], a
swap e
ld d, 0
ld hl, .Directions
add hl, de
ld a, [hl]
ld hl, OBJECT_FACING
add hl, bc
ld [hl], a
ret
; 456a
.Directions: ; 456a
db OW_DOWN, OW_RIGHT, OW_UP, OW_LEFT
; 456e
SetFacingFish: ; 456e
call GetSpriteDirection
rrca
rrca
add FACING_FISH_DOWN
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], a
ret
; 457b
SetFacingShadow: ; 457b
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], FACING_SHADOW
ret
; 4582
SetFacingEmote: ; 4582 emote
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], FACING_EMOTE
ret
; 4589
SetFacingBigDollSym: ; 4589
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], FACING_BIG_DOLL_SYM
ret
; 4590
SetFacingBounce: ; 4590
ld hl, OBJECT_STEP_FRAME
add hl, bc
ld a, [hl]
inc a
and %00001111
ld [hl], a
and %00001000
jr z, SetFacingFreezeBounce
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], FACING_STEP_UP_0
ret
; 45a4
SetFacingFreezeBounce: ; 45a4
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], FACING_STEP_DOWN_0
ret
; 45ab
SetFacingWeirdTree: ; 45ab
ld hl, OBJECT_STEP_FRAME
add hl, bc
ld a, [hl]
inc a
ld [hl], a
and %00001100
rrca
rrca
add FACING_WEIRD_TREE_0
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], a
ret
; 45be
SetFacingBigDollAsym: ; 45be
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], FACING_BIG_DOLL_ASYM
ret
; 45c5
SetFacingBigDoll: ; 45c5
ld a, [wVariableSprites + SPRITE_BIG_DOLL - SPRITE_VARS]
ld d, FACING_BIG_DOLL_SYM ; symmetric
cp SPRITE_BIG_SNORLAX
jr z, .ok
cp SPRITE_BIG_LAPRAS
jr z, .ok
ld d, FACING_BIG_DOLL_ASYM ; asymmetric
.ok
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], d
ret
; 45da
SetFacingBoulderDust: ; 45da
ld hl, OBJECT_STEP_FRAME
add hl, bc
inc [hl]
ld a, [hl]
ld hl, OBJECT_FACING_STEP
add hl, bc
and 2
ld a, FACING_BOULDER_DUST_1
jr z, .ok
inc a ; FACING_BOULDER_DUST_2
.ok
ld [hl], a
ret
; 45ed
SetFacingGrassShake: ; 45ed
ld hl, OBJECT_STEP_FRAME
add hl, bc
inc [hl]
ld a, [hl]
ld hl, OBJECT_FACING_STEP
add hl, bc
and 4
ld a, FACING_GRASS_1
jr z, .ok
inc a ; FACING_GRASS_2
.ok
ld [hl], a
ret
; 4600

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,70 @@
LoadObjectMasks: ; 2454f
ld hl, wObjectMasks
xor a
ld bc, NUM_OBJECTS
call ByteFill
nop
ld bc, wMapObjects
ld de, wObjectMasks
xor a
.loop
push af
push bc
push de
call GetObjectTimeMask
jr c, .next
call CheckObjectFlag
.next
pop de
ld [de], a
inc de
pop bc
ld hl, OBJECT_LENGTH
add hl, bc
ld b, h
ld c, l
pop af
inc a
cp NUM_OBJECTS
jr nz, .loop
ret
CheckObjectFlag: ; 2457d (9:457d)
ld hl, MAPOBJECT_SPRITE
add hl, bc
ld a, [hl]
and a
jr z, .masked
ld hl, MAPOBJECT_EVENT_FLAG
add hl, bc
ld a, [hli]
ld e, a
ld a, [hl]
ld d, a
cp -1
jr nz, .check
ld a, e
cp -1
jr z, .unmasked
jr .masked
.check
ld b, CHECK_FLAG
call EventFlagAction
ld a, c
and a
jr nz, .masked
.unmasked
xor a
ret
.masked
ld a, -1
scf
ret
GetObjectTimeMask: ; 245a7 (9:45a7)
call CheckObjectTime
ld a, -1
ret c
xor a
ret

View File

@@ -0,0 +1,260 @@
RunMapSetupScript:: ; 15363
ld a, [hMapEntryMethod]
and $f
dec a
ld c, a
ld b, 0
ld hl, MapSetupScripts
add hl, bc
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
call ReadMapSetupScript
ret
; 15377
INCLUDE "data/maps/setup_scripts.asm"
ReadMapSetupScript: ; 1541d
.loop
ld a, [hli]
cp -1
ret z
push hl
ld c, a
ld b, 0
ld hl, MapSetupCommands
add hl, bc
add hl, bc
add hl, bc
; bank
ld b, [hl]
inc hl
; address
ld a, [hli]
ld h, [hl]
ld l, a
; Bit 7 of the bank indicates a parameter.
; This is left unused.
bit 7, b
jr z, .go
pop de
ld a, [de]
ld c, a
inc de
push de
.go
ld a, b
and $7f
rst FarCall
pop hl
jr .loop
; 15440
MapSetupCommands: ; 15440
; entries correspond to command indexes in constants/map_setup_constants.asm
dba EnableLCD ; 00
dba DisableLCD ; 01
dba MapSetup_Sound_Off ; 02
dba PlayMapMusic ; 03
dba RestartMapMusic ; 04
dba FadeToMapMusic ; 05
dba RotatePalettesRightMapAndMusic ; 06
dba EnterMapMusic ; 07
dba ForceMapMusic ; 08
dba FadeInMusic ; 09
dba LoadBlockData ; 0a (callback 1)
dba LoadNeighboringBlockData ; 0b
dba SaveScreen ; 0c
dba BufferScreen ; 0d
dba LoadGraphics ; 0e
dba LoadTileset ; 0f
dba LoadMapTimeOfDay ; 10
dba LoadMapPalettes ; 11
dba LoadWildMonData ; 12
dba RefreshMapSprites ; 13
dba HandleNewMap ; 14
dba InitCommandQueue ; 15
dba LoadObjectsRunCallback_02 ; 16
dba LoadSpawnPoint ; 17
dba EnterMapConnection ; 18
dba LoadWarpData ; 19
dba LoadMapAttributes ; 1a
dba LoadMapAttributes_SkipPeople ; 1b
dba ClearBGPalettes ; 1c
dba FadeOutPalettes ; 1d
dba FadeInPalettes ; 1e
dba GetCoordOfUpperLeftCorner ; 1f
dba RestoreFacingAfterWarp ; 20
dba SpawnInFacingDown ; 21
dba SpawnPlayer ; 22
dba RefreshPlayerCoords ; 23
dba DelayClearingOldSprites ; 24
dba DelayLoadingNewSprites ; 25
dba UpdateRoamMons ; 26
dba JumpRoamMons ; 27
dba FadeOldMapMusic ; 28
dba ActivateMapAnims ; 29
dba SuspendMapAnims ; 2a
dba RetainOldPalettes ; 2b
dba DontScrollText ; 2c
dba ReturnFromMapSetupScript ; 2d
; 154ca
DontScrollText: ; 154ca
xor a
ld [wDisableTextAcceleration], a
ret
; 154cf
ActivateMapAnims: ; 154cf
ld a, $1
ld [hMapAnims], a
ret
; 154d3
SuspendMapAnims: ; 154d3
xor a
ld [hMapAnims], a
ret
; 154d7
LoadObjectsRunCallback_02: ; 154d7
ld a, MAPCALLBACK_OBJECTS
call RunMapCallback
farcall LoadObjectMasks
farcall InitializeVisibleSprites
ret
; 154ea (5:54ea)
; unused
ret
; 154eb
DelayClearingOldSprites: ; 154eb
ld hl, wPlayerSpriteSetupFlags
set PLAYERSPRITESETUP_RESET_ACTION_F, [hl]
ret
; 154f1
DelayLoadingNewSprites: ; 154f1
ld hl, wPlayerSpriteSetupFlags
set PLAYERSPRITESETUP_SKIP_RELOAD_GFX_F, [hl]
ret
CheckReplaceKrisSprite: ; 154f7
nop
call .CheckBiking
jr c, .ok
call .CheckSurfing
jr c, .ok
call .CheckSurfing2
jr c, .ok
ret
.ok
call ReplaceKrisSprite
ret
.CheckBiking: ; 1550c (5:550c)
and a
ld hl, wBikeFlags
bit BIKEFLAGS_ALWAYS_ON_BIKE_F, [hl]
ret z
ld a, PLAYER_BIKE
ld [wPlayerState], a
scf
ret
.CheckSurfing2: ; 1551a (5:551a)
ld a, [wPlayerState]
cp PLAYER_NORMAL
jr z, .nope
cp PLAYER_SKATE
jr z, .nope
cp PLAYER_SURF
jr z, .surfing
cp PLAYER_SURF_PIKA
jr z, .surfing
call GetMapEnvironment
cp INDOOR
jr z, .checkbiking
cp ENVIRONMENT_5
jr z, .checkbiking
cp DUNGEON
jr z, .checkbiking
jr .nope
.checkbiking
ld a, [wPlayerState]
cp PLAYER_BIKE
jr nz, .nope
.surfing
ld a, PLAYER_NORMAL
ld [wPlayerState], a
scf
ret
.nope
and a
ret
.CheckSurfing: ; 1554e (5:554e)
call CheckOnWater
jr nz, .ret_nc
ld a, [wPlayerState]
cp PLAYER_SURF
jr z, ._surfing
cp PLAYER_SURF_PIKA
jr z, ._surfing
ld a, PLAYER_SURF
ld [wPlayerState], a
._surfing
scf
ret
.ret_nc
and a
ret
; 15567
FadeOldMapMusic: ; 15567
ld a, 6
call SkipMusic
ret
; 1556d
RetainOldPalettes: ; 1556d
farcall _UpdateTimePals
ret
RotatePalettesRightMapAndMusic: ; 15574
ld e, 0
ld a, [wMusicFadeID]
ld d, 0
ld a, [wMusicFadeID + 1]
ld a, $4
ld [wMusicFade], a
call RotateThreePalettesRight
ret
; 15587
ForceMapMusic: ; 15587
ld a, [wPlayerState]
cp PLAYER_BIKE
jr nz, .notbiking
call VolumeOff
ld a, $88
ld [wMusicFade], a
.notbiking
call TryRestartMapMusic
ret
; 1559a

View File

@@ -0,0 +1,864 @@
MovementPointers: ; 5075
; entries correspond to macros/scripts/movement.asm enumeration
dw Movement_turn_head_down ; 00
dw Movement_turn_head_up ; 01
dw Movement_turn_head_left ; 02
dw Movement_turn_head_right ; 03
dw Movement_turn_step_down ; 04
dw Movement_turn_step_up ; 05
dw Movement_turn_step_left ; 06
dw Movement_turn_step_right ; 07
dw Movement_slow_step_down ; 08
dw Movement_slow_step_up ; 09
dw Movement_slow_step_left ; 0a
dw Movement_slow_step_right ; 0b
dw Movement_step_down ; 0c
dw Movement_step_up ; 0d
dw Movement_step_left ; 0e
dw Movement_step_right ; 0f
dw Movement_big_step_down ; 10
dw Movement_big_step_up ; 11
dw Movement_big_step_left ; 12
dw Movement_big_step_right ; 13
dw Movement_slow_slide_step_down ; 14
dw Movement_slow_slide_step_up ; 15
dw Movement_slow_slide_step_left ; 16
dw Movement_slow_slide_step_right ; 17
dw Movement_slide_step_down ; 18
dw Movement_slide_step_up ; 19
dw Movement_slide_step_left ; 1a
dw Movement_slide_step_right ; 1b
dw Movement_fast_slide_step_down ; 1c
dw Movement_fast_slide_step_up ; 1d
dw Movement_fast_slide_step_left ; 1e
dw Movement_fast_slide_step_right ; 1f
dw Movement_turn_away_down ; 20
dw Movement_turn_away_up ; 21
dw Movement_turn_away_left ; 22
dw Movement_turn_away_right ; 23
dw Movement_turn_in_down ; 24
dw Movement_turn_in_up ; 25
dw Movement_turn_in_left ; 26
dw Movement_turn_in_right ; 27
dw Movement_turn_waterfall_down ; 28
dw Movement_turn_waterfall_up ; 29
dw Movement_turn_waterfall_left ; 2a
dw Movement_turn_waterfall_right ; 2b
dw Movement_slow_jump_step_down ; 2c
dw Movement_slow_jump_step_up ; 2d
dw Movement_slow_jump_step_left ; 2e
dw Movement_slow_jump_step_right ; 2f
dw Movement_jump_step_down ; 30
dw Movement_jump_step_up ; 31
dw Movement_jump_step_left ; 32
dw Movement_jump_step_right ; 33
dw Movement_fast_jump_step_down ; 34
dw Movement_fast_jump_step_up ; 35
dw Movement_fast_jump_step_left ; 36
dw Movement_fast_jump_step_right ; 37
dw Movement_remove_sliding ; 38
dw Movement_set_sliding ; 39
dw Movement_remove_fixed_facing ; 3a
dw Movement_fix_facing ; 3b
dw Movement_show_object ; 3c
dw Movement_hide_object ; 3d
dw Movement_step_sleep_1 ; 3e
dw Movement_step_sleep_2 ; 3f
dw Movement_step_sleep_3 ; 40
dw Movement_step_sleep_4 ; 41
dw Movement_step_sleep_5 ; 42
dw Movement_step_sleep_6 ; 43
dw Movement_step_sleep_7 ; 44
dw Movement_step_sleep_8 ; 45
dw Movement_step_sleep ; 46
dw Movement_step_end ; 47
dw Movement_48 ; 48
dw Movement_remove_object ; 49
dw Movement_step_loop ; 4a
dw Movement_4b ; 4b
dw Movement_teleport_from ; 4c
dw Movement_teleport_to ; 4d
dw Movement_skyfall ; 4e
dw Movement_step_dig ; 4f
dw Movement_step_bump ; 50
dw Movement_fish_got_bite ; 51
dw Movement_fish_cast_rod ; 52
dw Movement_hide_emote ; 53
dw Movement_show_emote ; 54
dw Movement_step_shake ; 55
dw Movement_tree_shake ; 56
dw Movement_rock_smash ; 57
dw Movement_return_dig ; 58
dw Movement_skyfall_top ; 59
; 5129
Movement_teleport_from: ; 5129
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_TELEPORT_FROM
ret
; 5130
Movement_teleport_to: ; 5130
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_TELEPORT_TO
ret
; 5137
Movement_skyfall: ; 5137
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_SKYFALL
ret
; 513e
Movement_skyfall_top: ; 513e
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_SKYFALL_TOP
ret
; 5145
Movement_step_dig: ; 5145
call GetSpriteDirection
rlca
rlca
ld hl, OBJECT_STEP_FRAME
add hl, bc
ld [hl], a
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_SPIN
call JumpMovementPointer
ld hl, OBJECT_STEP_DURATION
add hl, bc
ld [hl], a
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_03
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld [hl], STANDING
ret
; 516a
Movement_return_dig: ; 516a
call GetSpriteDirection
rlca
rlca
ld hl, OBJECT_STEP_FRAME
add hl, bc
ld [hl], a
call JumpMovementPointer
ld hl, OBJECT_STEP_DURATION
add hl, bc
ld [hl], a
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld [hl], STANDING
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_RETURN_DIG
ret
; 5189
Movement_fish_got_bite: ; 5189
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_FISHING
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_GOT_BITE
ret
; 5196
Movement_rock_smash: ; 5196
call JumpMovementPointer
ld hl, OBJECT_STEP_DURATION
add hl, bc
ld [hl], a
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_STAND
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_ROCK_SMASH
ret
; 51ab
Movement_fish_cast_rod: ; 51ab
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_FISHING
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_SLEEP
ret
; 51b8
Movement_step_loop: ; 51b8
ld hl, OBJECT_MOVEMENT_BYTE_INDEX
add hl, bc
ld [hl], $0
jp ContinueReadingMovement
; 51c1
Movement_step_end: ; 51c1
call RestoreDefaultMovement
ld hl, OBJECT_MOVEMENTTYPE
add hl, bc
ld [hl], a
ld hl, OBJECT_MOVEMENT_BYTE_INDEX
add hl, bc
ld [hl], $0
ld hl, wVramState
res 7, [hl]
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_SLEEP
ret
; 51db
Movement_48: ; 51db
call RestoreDefaultMovement
ld hl, OBJECT_MOVEMENTTYPE
add hl, bc
ld [hl], a
ld hl, OBJECT_MOVEMENT_BYTE_INDEX
add hl, bc
ld [hl], $0
call JumpMovementPointer
ld hl, OBJECT_STEP_DURATION
add hl, bc
ld [hl], a
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_03
ld hl, wVramState
res 7, [hl]
ret
; 51fd
Movement_remove_object: ; 51fd
call DeleteMapObject
ld hl, wObjectFollow_Leader
ld a, [hMapObjectIndexBuffer]
cp [hl]
jr nz, .not_leading
ld [hl], -1
.not_leading
ld hl, wVramState
res 7, [hl]
ret
; 5210
Movement_4b: ; 5210
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_STAND
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_04
ld hl, wVramState
res 7, [hl]
ret
; 5222
Movement_step_sleep_1: ; 5222
ld a, 1
jr Movement_step_sleep_common
Movement_step_sleep_2: ; 5226
ld a, 2
jr Movement_step_sleep_common
Movement_step_sleep_3: ; 522a
ld a, 3
jr Movement_step_sleep_common
Movement_step_sleep_4: ; 522e
ld a, 4
jr Movement_step_sleep_common
Movement_step_sleep_5: ; 5232
ld a, 5
jr Movement_step_sleep_common
Movement_step_sleep_6: ; 5236
ld a, 6
jr Movement_step_sleep_common
Movement_step_sleep_7: ; 523a
ld a, 7
jr Movement_step_sleep_common
Movement_step_sleep_8: ; 523e
ld a, 8
jr Movement_step_sleep_common
Movement_step_sleep: ; 5242
; parameters:
; duration (DecimalParam)
call JumpMovementPointer
jr Movement_step_sleep_common
Movement_step_sleep_common: ; 5247
ld hl, OBJECT_STEP_DURATION
add hl, bc
ld [hl], a
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_03
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_STAND
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld [hl], STANDING
ret
; 525f
Movement_step_bump: ; 525f
ld a, 1
ld hl, OBJECT_STEP_DURATION
add hl, bc
ld [hl], a
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_BUMP
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_BUMP
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld [hl], STANDING
ret
; 5279
Movement_tree_shake: ; 5279
ld a, 24
ld hl, OBJECT_STEP_DURATION
add hl, bc
ld [hl], a
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_03
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_WEIRD_TREE
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld [hl], STANDING
ret
; 5293
Movement_remove_sliding: ; 5293
ld hl, OBJECT_FLAGS1
add hl, bc
res SLIDING, [hl]
jp ContinueReadingMovement
; 529c
Movement_set_sliding: ; 529c
ld hl, OBJECT_FLAGS1
add hl, bc
set SLIDING, [hl]
jp ContinueReadingMovement
; 52a5
Movement_remove_fixed_facing: ; 52a5
ld hl, OBJECT_FLAGS1
add hl, bc
res FIXED_FACING, [hl]
jp ContinueReadingMovement
; 52ae
Movement_fix_facing: ; 52ae
ld hl, OBJECT_FLAGS1
add hl, bc
set FIXED_FACING, [hl]
jp ContinueReadingMovement
; 52b7
Movement_show_object: ; 52b7
ld hl, OBJECT_FLAGS1
add hl, bc
res INVISIBLE, [hl]
jp ContinueReadingMovement
; 52c0
Movement_hide_object: ; 52c0
ld hl, OBJECT_FLAGS1
add hl, bc
set INVISIBLE, [hl]
jp ContinueReadingMovement
; 52c9
Movement_hide_emote: ; 52c9
call DespawnEmote
jp ContinueReadingMovement
; 52cf
Movement_show_emote: ; 52cf
call SpawnEmote
jp ContinueReadingMovement
; 52d5
Movement_step_shake: ; 52d5
; parameters:
; displacement (DecimalParam)
call JumpMovementPointer
call ShakeScreen
jp ContinueReadingMovement
; 52de
Movement_turn_head_down: ; 52de
ld a, OW_DOWN
jr TurnHead
Movement_turn_head_up: ; 52e2
ld a, OW_UP
jr TurnHead
Movement_turn_head_left: ; 52e6
ld a, OW_LEFT
jr TurnHead
Movement_turn_head_right: ; 52ea
ld a, OW_RIGHT
jr TurnHead
TurnHead: ; 52ee
ld hl, OBJECT_FACING
add hl, bc
ld [hl], a
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_STAND
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld [hl], STANDING
ret
; 5300
Movement_slow_step_down: ; 5300
ld a, STEP_SLOW << 2 | DOWN
jp NormalStep
; 5305
Movement_slow_step_up: ; 5305
ld a, STEP_SLOW << 2 | UP
jp NormalStep
; 530a
Movement_slow_step_left: ; 530a
ld a, STEP_SLOW << 2 | LEFT
jp NormalStep
; 530f
Movement_slow_step_right: ; 530f
ld a, STEP_SLOW << 2 | RIGHT
jp NormalStep
; 5314
Movement_step_down: ; 5314
ld a, STEP_WALK << 2 | DOWN
jp NormalStep
; 5319
Movement_step_up: ; 5319
ld a, STEP_WALK << 2 | UP
jp NormalStep
; 531e
Movement_step_left: ; 531e
ld a, STEP_WALK << 2 | LEFT
jp NormalStep
; 5323
Movement_step_right: ; 5323
ld a, STEP_WALK << 2 | RIGHT
jp NormalStep
; 5328
Movement_big_step_down: ; 5328
ld a, STEP_BIKE << 2 | DOWN
jp NormalStep
; 532d
Movement_big_step_up: ; 532d
ld a, STEP_BIKE << 2 | UP
jp NormalStep
; 5332
Movement_big_step_left: ; 5332
ld a, STEP_BIKE << 2 | LEFT
jp NormalStep
; 5337
Movement_big_step_right: ; 5337
ld a, STEP_BIKE << 2 | RIGHT
jp NormalStep
; 533c
Movement_turn_away_down: ; 533c
ld a, STEP_SLOW << 2 | DOWN
jp TurningStep
; 5341
Movement_turn_away_up: ; 5341
ld a, STEP_SLOW << 2 | UP
jp TurningStep
; 5346
Movement_turn_away_left: ; 5346
ld a, STEP_SLOW << 2 | LEFT
jp TurningStep
; 534b
Movement_turn_away_right: ; 534b
ld a, STEP_SLOW << 2 | RIGHT
jp TurningStep
; 5350
Movement_turn_in_down: ; 5350
ld a, STEP_WALK << 2 | DOWN
jp TurningStep
; 5355
Movement_turn_in_up: ; 5355
ld a, STEP_WALK << 2 | UP
jp TurningStep
; 535a
Movement_turn_in_left: ; 535a
ld a, STEP_WALK << 2 | LEFT
jp TurningStep
; 535f
Movement_turn_in_right: ; 535f
ld a, STEP_WALK << 2 | RIGHT
jp TurningStep
; 5364
Movement_turn_waterfall_down: ; 5364
ld a, STEP_BIKE << 2 | DOWN
jp TurningStep
; 5369
Movement_turn_waterfall_up: ; 5369
ld a, STEP_BIKE << 2 | UP
jp TurningStep
; 536e
Movement_turn_waterfall_left: ; 536e
ld a, STEP_BIKE << 2 | LEFT
jp TurningStep
; 5373
Movement_turn_waterfall_right: ; 5373
ld a, STEP_BIKE << 2 | RIGHT
jp TurningStep
; 5378
Movement_slow_slide_step_down: ; 5378
ld a, STEP_SLOW << 2 | DOWN
jp SlideStep
; 537d
Movement_slow_slide_step_up: ; 537d
ld a, STEP_SLOW << 2 | UP
jp SlideStep
; 5382
Movement_slow_slide_step_left: ; 5382
ld a, STEP_SLOW << 2 | LEFT
jp SlideStep
; 5387
Movement_slow_slide_step_right: ; 5387
ld a, STEP_SLOW << 2 | RIGHT
jp SlideStep
; 538c
Movement_slide_step_down: ; 538c
ld a, STEP_WALK << 2 | DOWN
jp SlideStep
; 5391
Movement_slide_step_up: ; 5391
ld a, STEP_WALK << 2 | UP
jp SlideStep
; 5396
Movement_slide_step_left: ; 5396
ld a, STEP_WALK << 2 | LEFT
jp SlideStep
; 539b
Movement_slide_step_right: ; 539b
ld a, STEP_WALK << 2 | RIGHT
jp SlideStep
; 53a0
Movement_fast_slide_step_down: ; 53a0
ld a, STEP_BIKE << 2 | DOWN
jp SlideStep
; 53a5
Movement_fast_slide_step_up: ; 53a5
ld a, STEP_BIKE << 2 | UP
jp SlideStep
; 53aa
Movement_fast_slide_step_left: ; 53aa
ld a, STEP_BIKE << 2 | LEFT
jp SlideStep
; 53af
Movement_fast_slide_step_right: ; 53af
ld a, STEP_BIKE << 2 | RIGHT
jp SlideStep
; 53b4
Movement_slow_jump_step_down: ; 53b4
ld a, STEP_SLOW << 2 | DOWN
jp JumpStep
; 53b9
Movement_slow_jump_step_up: ; 53b9
ld a, STEP_SLOW << 2 | UP
jp JumpStep
; 53be
Movement_slow_jump_step_left: ; 53be
ld a, STEP_SLOW << 2 | LEFT
jp JumpStep
; 53c3
Movement_slow_jump_step_right: ; 53c3
ld a, STEP_SLOW << 2 | RIGHT
jp JumpStep
; 53c8
Movement_jump_step_down: ; 53c8
ld a, STEP_WALK << 2 | DOWN
jp JumpStep
; 53cd
Movement_jump_step_up: ; 53cd
ld a, STEP_WALK << 2 | UP
jp JumpStep
; 53d2
Movement_jump_step_left: ; 53d2
ld a, STEP_WALK << 2 | LEFT
jp JumpStep
; 53d7
Movement_jump_step_right: ; 53d7
ld a, STEP_WALK << 2 | RIGHT
jp JumpStep
; 53dc
Movement_fast_jump_step_down: ; 53dc
ld a, STEP_BIKE << 2 | DOWN
jp JumpStep
; 53e1
Movement_fast_jump_step_up: ; 53e1
ld a, STEP_BIKE << 2 | UP
jp JumpStep
; 53e6
Movement_fast_jump_step_left: ; 53e6
ld a, STEP_BIKE << 2 | LEFT
jp JumpStep
; 53eb
Movement_fast_jump_step_right: ; 53eb
ld a, STEP_BIKE << 2 | RIGHT
jp JumpStep
; 53f0
Movement_turn_step_down: ; 53f0
ld a, OW_DOWN
jr TurnStep
Movement_turn_step_up: ; 53f4
ld a, OW_UP
jr TurnStep
Movement_turn_step_left: ; 53f8
ld a, OW_LEFT
jr TurnStep
Movement_turn_step_right: ; 53fc
ld a, OW_RIGHT
jr TurnStep
TurnStep: ; 5400
ld hl, OBJECT_1D ; new facing
add hl, bc
ld [hl], a
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_STEP
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_HALF_STEP
ret
; 5412
NormalStep: ; 5412
call InitStep
call UpdateTallGrassFlags
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_STEP
ld hl, OBJECT_NEXT_TILE
add hl, bc
ld a, [hl]
call CheckSuperTallGrassTile
jr z, .shake_grass
call CheckGrassTile
jr c, .skip_grass
.shake_grass
call ShakeGrass
.skip_grass
ld hl, wCenteredObject
ld a, [hMapObjectIndexBuffer]
cp [hl]
jr z, .player
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_NPC_WALK
ret
.player
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_PLAYER_WALK
ret
; 5446
TurningStep: ; 5446
call InitStep
call UpdateTallGrassFlags
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_SPIN
ld hl, wCenteredObject
ld a, [hMapObjectIndexBuffer]
cp [hl]
jr z, .player
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_NPC_WALK
ret
.player
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_PLAYER_WALK
ret
; 5468
SlideStep: ; 5468
call InitStep
call UpdateTallGrassFlags
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_STAND
ld hl, wCenteredObject
ld a, [hMapObjectIndexBuffer]
cp [hl]
jr z, .player
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_NPC_WALK
ret
.player
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_PLAYER_WALK
ret
; 548a
JumpStep: ; 548a
call InitStep
ld hl, OBJECT_1F
add hl, bc
ld [hl], $0
ld hl, OBJECT_FLAGS2
add hl, bc
res OVERHEAD, [hl]
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_STEP
call SpawnShadow
ld hl, wCenteredObject
ld a, [hMapObjectIndexBuffer]
cp [hl]
jr z, .player
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_NPC_JUMP
ret
.player
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_PLAYER_JUMP
ret
; 54b8

573
engine/overworld/npc_movement.asm Executable file
View File

@@ -0,0 +1,573 @@
Function6ec1: ; 6ec1
ld hl, OBJECT_PALETTE
add hl, bc
bit 5, [hl]
jr z, .not_bit_5
ld hl, OBJECT_FLAGS1
add hl, bc
bit 4, [hl] ; lost, uncomment next line to fix
; jr nz, .resume
push hl
push bc
call Function6f2c
pop bc
pop hl
ret c
jr .resume
.not_bit_5
ld hl, OBJECT_FLAGS1
add hl, bc
bit 4, [hl]
jr nz, .resume
push hl
push bc
call Function6f07
pop bc
pop hl
ret c
.resume
bit 6, [hl]
jr nz, .bit_6
push hl
push bc
call WillObjectBumpIntoSomeoneElse
pop bc
pop hl
ret c
.bit_6
bit 5, [hl]
jr nz, .bit_5
push hl
call HasObjectReachedMovementLimit
pop hl
ret c
push hl
call IsObjectMovingOffEdgeOfScreen
pop hl
ret c
.bit_5
and a
ret
; 6f07
Function6f07: ; 6f07
call Function6f5f
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 hl, OBJECT_PALETTE
add hl, bc
bit OAM_PRIORITY, [hl]
jp nz, Function6fa1
ld hl, OBJECT_NEXT_TILE
add hl, bc
ld a, [hl]
ld d, a
call GetTileCollision
and a ; LANDTILE
jr z, Function6f3e
scf
ret
; 6f2c
Function6f2c: ; 6f2c
call Function6f5f
ret c
ld hl, OBJECT_NEXT_TILE
add hl, bc
ld a, [hl]
call GetTileCollision
cp WATERTILE
jr z, Function6f3e
scf
ret
; 6f3e
Function6f3e: ; 6f3e
ld hl, OBJECT_NEXT_TILE
add hl, bc
ld a, [hl]
call Function6f7f
ret nc
push af
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld a, [hl]
maskbits NUM_DIRECTIONS
ld e, a
ld d, 0
ld hl, .data_6f5b
add hl, de
pop af
and [hl]
ret z
scf
ret
; 6f5b
.data_6f5b
db DOWN_MASK, UP_MASK, RIGHT_MASK, LEFT_MASK
; 6f5f
Function6f5f: ; 6f5f
ld hl, OBJECT_STANDING_TILE
add hl, bc
ld a, [hl]
call Function6f7f
ret nc
push af
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
maskbits NUM_DIRECTIONS
ld e, a
ld d, 0
ld hl, .data_6f7b
add hl, de
pop af
and [hl]
ret z
scf
ret
; 6f7b
.data_6f7b
db UP_MASK, DOWN_MASK, LEFT_MASK, RIGHT_MASK
; 6f7f
Function6f7f: ; 6f7f
ld d, a
and $f0
cp $b0
jr z, .done
cp $c0
jr z, .done
xor a
ret
.done
ld a, d
and 7
ld e, a
ld d, 0
ld hl, .data_6f99
add hl, de
ld a, [hl]
scf
ret
; 6f99
.data_6f99
db 8, 4, 1, 2
db 10, 6, 9, 5
; 6fa1
Function6fa1: ; 6fa1
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld a, [hl]
maskbits NUM_DIRECTIONS
jr z, .down
dec a
jr z, .up
dec a
jr z, .left
jr .right
.down
inc e
push de
inc d
jr .continue
.up
push de
inc d
jr .continue
.left
push de
inc e
jr .continue
.right
inc d
push de
inc e
.continue
call GetCoordTile
call GetTileCollision
pop de
and a ; LANDTILE
jr nz, .not_land
call GetCoordTile
call GetTileCollision
and a ; LANDTILE
jr nz, .not_land
xor a
ret
.not_land
scf
ret
; 6fd9
CheckFacingObject:: ; 6fd9
call GetFacingTileCoord
; Double the distance for counter tiles.
call CheckCounterTile
jr nz, .asm_6ff1
ld a, [wPlayerStandingMapX]
sub d
cpl
inc a
add d
ld d, a
ld a, [wPlayerStandingMapY]
sub e
cpl
inc a
add e
ld e, a
.asm_6ff1
ld bc, wObjectStructs ; redundant
ld a, 0
ld [hMapObjectIndexBuffer], a
call IsNPCAtCoord
ret nc
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld a, [hl]
cp STANDING
jr z, .standing
xor a
ret
.standing
scf
ret
; 7009
WillObjectBumpIntoSomeoneElse: ; 7009
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld d, [hl]
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld e, [hl]
jr IsNPCAtCoord
; 7015
Unreferenced_Function7015:
ld a, [hMapObjectIndexBuffer]
call GetObjectStruct
call .CheckWillBeFacingNPC
call IsNPCAtCoord
ret
.CheckWillBeFacingNPC: ; 7021
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld d, [hl]
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld e, [hl]
call GetSpriteDirection
and a
jr z, .down
cp OW_UP
jr z, .up
cp OW_LEFT
jr z, .left
inc d
ret
.down
inc e
ret
.up
dec e
ret
.left
dec d
ret
; 7041
IsNPCAtCoord: ; 7041
ld bc, wObjectStructs
xor a
.loop
ld [hObjectStructIndexBuffer], a
call DoesObjectHaveASprite
jr z, .next
ld hl, OBJECT_FLAGS1
add hl, bc
bit 7, [hl]
jr nz, .next
ld hl, OBJECT_PALETTE
add hl, bc
bit 7, [hl]
jr z, .got
call Function7171
jr nc, .ok
jr .ok2
.got
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld a, [hl]
cp d
jr nz, .ok
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld a, [hl]
cp e
jr nz, .ok
.ok2
ld a, [hMapObjectIndexBuffer]
ld l, a
ld a, [hObjectStructIndexBuffer]
cp l
jr nz, .setcarry
.ok
ld hl, OBJECT_MAP_X
add hl, bc
ld a, [hl]
cp d
jr nz, .next
ld hl, OBJECT_MAP_Y
add hl, bc
ld a, [hl]
cp e
jr nz, .next
ld a, [hMapObjectIndexBuffer]
ld l, a
ld a, [hObjectStructIndexBuffer]
cp l
jr nz, .setcarry
.next
ld hl, OBJECT_STRUCT_LENGTH
add hl, bc
ld b, h
ld c, l
ld a, [hObjectStructIndexBuffer]
inc a
cp NUM_OBJECT_STRUCTS
jr nz, .loop
and a
ret
.setcarry
scf
ret
; 70a4
HasObjectReachedMovementLimit: ; 70a4
ld hl, OBJECT_RADIUS
add hl, bc
ld a, [hl]
and a
jr z, .nope
and $f
jr z, .check_y
ld e, a
ld d, a
ld hl, OBJECT_INIT_X
add hl, bc
ld a, [hl]
sub d
ld d, a
ld a, [hl]
add e
ld e, a
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld a, [hl]
cp d
jr z, .yes
cp e
jr z, .yes
.check_y
ld hl, OBJECT_RADIUS
add hl, bc
ld a, [hl]
swap a
and $f
jr z, .nope
ld e, a
ld d, a
ld hl, OBJECT_INIT_Y
add hl, bc
ld a, [hl]
sub d
ld d, a
ld a, [hl]
add e
ld e, a
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld a, [hl]
cp d
jr z, .yes
cp e
jr z, .yes
.nope
xor a
ret
.yes
scf
ret
; 70ed
IsObjectMovingOffEdgeOfScreen: ; 70ed
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld a, [wXCoord]
cp [hl]
jr z, .check_y
jr nc, .yes
add $9
cp [hl]
jr c, .yes
.check_y
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld a, [wYCoord]
cp [hl]
jr z, .nope
jr nc, .yes
add $8
cp [hl]
jr c, .yes
.nope
and a
ret
.yes
scf
ret
; 7113
Unreferenced_Function7113:
ld a, [wPlayerStandingMapX]
ld d, a
ld a, [wPlayerStandingMapY]
ld e, a
ld bc, wObjectStructs
xor a
.loop
ld [hObjectStructIndexBuffer], a
call DoesObjectHaveASprite
jr z, .next
ld hl, OBJECT_MOVEMENTTYPE
add hl, bc
ld a, [hl]
cp SPRITEMOVEDATA_BIGDOLLSYM
jr nz, .not_snorlax
call Function7171
jr c, .yes
jr .next
.not_snorlax
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld a, [hl]
cp e
jr nz, .check_current_coords
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld a, [hl]
cp d
jr nz, .check_current_coords
ld a, [hObjectStructIndexBuffer]
cp $0
jr z, .next
jr .yes
.check_current_coords
ld hl, OBJECT_MAP_Y
add hl, bc
ld a, [hl]
cp e
jr nz, .next
ld hl, OBJECT_MAP_X
add hl, bc
ld a, [hl]
cp d
jr nz, .next
jr .yes
.next
ld hl, OBJECT_STRUCT_LENGTH
add hl, bc
ld b, h
ld c, l
ld a, [hObjectStructIndexBuffer]
inc a
cp NUM_OBJECT_STRUCTS
jr nz, .loop
xor a
ret
.yes
scf
ret
; 7171
Function7171: ; 7171
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld a, d
sub [hl]
jr c, .nope
cp $2
jr nc, .nope
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld a, e
sub [hl]
jr c, .nope
cp $2
jr nc, .nope
scf
ret
.nope
and a
ret
; 718d

715
engine/overworld/overworld.asm Executable file
View File

@@ -0,0 +1,715 @@
GetEmote2bpp: ; 1412a
ld a, $1
ld [rVBK], a
call Get2bpp
xor a
ld [rVBK], a
ret
; 14135
_ReplaceKrisSprite:: ; 14135
call GetPlayerSprite
ld a, [wUsedSprites]
ld [hUsedSpriteIndex], a
ld a, [wUsedSprites + 1]
ld [hUsedSpriteTile], a
call GetUsedSprite
ret
; 14146
Function14146: ; mobile
ld hl, wSpriteFlags
ld a, [hl]
push af
res 7, [hl]
set 6, [hl]
call LoadUsedSpritesGFX
pop af
ld [wSpriteFlags], a
ret
; 14157
Function14157: ; mobile
ld hl, wSpriteFlags
ld a, [hl]
push af
set 7, [hl]
res 6, [hl]
call LoadUsedSpritesGFX
pop af
ld [wSpriteFlags], a
ret
; 14168
RefreshSprites:: ; 14168
call .Refresh
call LoadUsedSpritesGFX
ret
; 1416f
.Refresh: ; 1416f
xor a
ld bc, wUsedSpritesEnd - wUsedSprites
ld hl, wUsedSprites
call ByteFill
call GetPlayerSprite
call AddMapSprites
call LoadAndSortSprites
ret
; 14183
GetPlayerSprite: ; 14183
; Get Chris or Kris's sprite.
ld hl, ChrisStateSprites
ld a, [wPlayerSpriteSetupFlags]
bit PLAYERSPRITESETUP_FEMALE_TO_MALE_F, a
jr nz, .go
ld a, [wPlayerGender]
bit PLAYERGENDER_FEMALE_F, a
jr z, .go
ld hl, KrisStateSprites
.go
ld a, [wPlayerState]
ld c, a
.loop
ld a, [hli]
cp c
jr z, .good
inc hl
cp -1
jr nz, .loop
; Any player state not in the array defaults to Chris's sprite.
xor a ; ld a, PLAYER_NORMAL
ld [wPlayerState], a
ld a, SPRITE_CHRIS
jr .finish
.good
ld a, [hl]
.finish
ld [wUsedSprites + 0], a
ld [wPlayerSprite], a
ld [wPlayerObjectSprite], a
ret
INCLUDE "data/sprites/player_sprites.asm"
AddMapSprites: ; 141c9
call GetMapEnvironment
call CheckOutdoorMap
jr z, .outdoor
call AddIndoorSprites
ret
.outdoor
call AddOutdoorSprites
ret
; 141d9
AddIndoorSprites: ; 141d9
ld hl, wMap1ObjectSprite
ld a, 1
.loop
push af
ld a, [hl]
call AddSpriteGFX
ld de, OBJECT_LENGTH
add hl, de
pop af
inc a
cp NUM_OBJECTS
jr nz, .loop
ret
; 141ee
AddOutdoorSprites: ; 141ee
ld a, [wMapGroup]
dec a
ld c, a
ld b, 0
ld hl, OutdoorSprites
add hl, bc
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
ld c, MAX_OUTDOOR_SPRITES
.loop
push bc
ld a, [hli]
call AddSpriteGFX
pop bc
dec c
jr nz, .loop
ret
; 14209
LoadUsedSpritesGFX: ; 14209
ld a, MAPCALLBACK_SPRITES
call RunMapCallback
call GetUsedSprites
call .LoadMiscTiles
ret
; 14215
.LoadMiscTiles: ; 14215
ld a, [wSpriteFlags]
bit 6, a
ret nz
ld c, EMOTE_SHADOW
farcall LoadEmote
call GetMapEnvironment
call CheckOutdoorMap
ld c, EMOTE_GRASS_RUSTLE
jr z, .outdoor
ld c, EMOTE_BOULDER_DUST
.outdoor
farcall LoadEmote
ret
; 14236
SafeGetSprite: ; 14236
push hl
call GetSprite
pop hl
ret
; 1423c
GetSprite: ; 1423c
call GetMonSprite
ret c
ld hl, OverworldSprites + SPRITEDATA_ADDR
dec a
ld c, a
ld b, 0
ld a, NUM_SPRITEDATA_FIELDS
call AddNTimes
; load the address into de
ld a, [hli]
ld e, a
ld a, [hli]
ld d, a
; load the length into c
ld a, [hli]
swap a
ld c, a
; load the sprite bank into both b and h
ld b, [hl]
ld a, [hli]
; load the sprite type into l
ld l, [hl]
ld h, a
ret
; 14259
GetMonSprite: ; 14259
; Return carry if a monster sprite was loaded.
cp SPRITE_POKEMON
jr c, .Normal
cp SPRITE_DAY_CARE_MON_1
jr z, .BreedMon1
cp SPRITE_DAY_CARE_MON_2
jr z, .BreedMon2
cp SPRITE_VARS
jr nc, .Variable
jr .Icon
.Normal:
and a
ret
.Icon:
sub SPRITE_POKEMON
ld e, a
ld d, 0
ld hl, SpriteMons
add hl, de
ld a, [hl]
jr .Mon
.BreedMon1
ld a, [wBreedMon1Species]
jr .Mon
.BreedMon2
ld a, [wBreedMon2Species]
.Mon:
ld e, a
and a
jr z, .NoBreedmon
farcall LoadOverworldMonIcon
ld l, 1
ld h, 0
scf
ret
.Variable:
sub SPRITE_VARS
ld e, a
ld d, 0
ld hl, wVariableSprites
add hl, de
ld a, [hl]
and a
jp nz, GetMonSprite
.NoBreedmon:
ld a, 1
ld l, 1
ld h, 0
and a
ret
; 142a7
_DoesSpriteHaveFacings:: ; 142a7
; Checks to see whether we can apply a facing to a sprite.
; Returns carry unless the sprite is a Pokemon or a Still Sprite.
cp SPRITE_POKEMON
jr nc, .only_down
push hl
push bc
ld hl, OverworldSprites + SPRITEDATA_TYPE
dec a
ld c, a
ld b, 0
ld a, NUM_SPRITEDATA_FIELDS
call AddNTimes
ld a, [hl]
pop bc
pop hl
cp STILL_SPRITE
jr nz, .only_down
scf
ret
.only_down
and a
ret
; 142c4
_GetSpritePalette:: ; 142c4
ld a, c
call GetMonSprite
jr c, .is_pokemon
ld hl, OverworldSprites + SPRITEDATA_PALETTE
dec a
ld c, a
ld b, 0
ld a, NUM_SPRITEDATA_FIELDS
call AddNTimes
ld c, [hl]
ret
.is_pokemon
xor a
ld c, a
ret
; 142db
LoadAndSortSprites: ; 142db
call LoadSpriteGFX
call SortUsedSprites
call ArrangeUsedSprites
ret
; 142e5
AddSpriteGFX: ; 142e5
; Add any new sprite ids to a list of graphics to be loaded.
; Return carry if the list is full.
push hl
push bc
ld b, a
ld hl, wUsedSprites + 2
ld c, SPRITE_GFX_LIST_CAPACITY - 1
.loop
ld a, [hl]
cp b
jr z, .exists
and a
jr z, .new
inc hl
inc hl
dec c
jr nz, .loop
pop bc
pop hl
scf
ret
.exists
pop bc
pop hl
and a
ret
.new
ld [hl], b
pop bc
pop hl
and a
ret
; 14306
LoadSpriteGFX: ; 14306
; Bug: b is not preserved, so it's useless as a next count.
; Uncomment the lines below to fix.
ld hl, wUsedSprites
ld b, SPRITE_GFX_LIST_CAPACITY
.loop
ld a, [hli]
and a
jr z, .done
push hl
call .LoadSprite
pop hl
ld [hli], a
dec b
jr nz, .loop
.done
ret
.LoadSprite:
; push bc
call GetSprite
; pop bc
ld a, l
ret
; 1431e
SortUsedSprites: ; 1431e
; Bubble-sort sprites by type.
; Run backwards through wUsedSprites to find the last one.
ld c, SPRITE_GFX_LIST_CAPACITY
ld de, wUsedSprites + (SPRITE_GFX_LIST_CAPACITY - 1) * 2
.FindLastSprite:
ld a, [de]
and a
jr nz, .FoundLastSprite
dec de
dec de
dec c
jr nz, .FindLastSprite
.FoundLastSprite:
dec c
jr z, .quit
; If the length of the current sprite is
; higher than a later one, swap them.
inc de
ld hl, wUsedSprites + 1
.CheckSprite:
push bc
push de
push hl
.CheckFollowing:
ld a, [de]
cp [hl]
jr nc, .loop
; Swap the two sprites.
ld b, a
ld a, [hl]
ld [hl], b
ld [de], a
dec de
dec hl
ld a, [de]
ld b, a
ld a, [hl]
ld [hl], b
ld [de], a
inc de
inc hl
; Keep doing this until everything's in order.
.loop
dec de
dec de
dec c
jr nz, .CheckFollowing
pop hl
inc hl
inc hl
pop de
pop bc
dec c
jr nz, .CheckSprite
.quit
ret
; 14355
ArrangeUsedSprites: ; 14355
; Get the length of each sprite and space them out in VRAM.
; Crystal introduces a second table in VRAM bank 0.
ld hl, wUsedSprites
ld c, SPRITE_GFX_LIST_CAPACITY
ld b, 0
.FirstTableLength:
; Keep going until the end of the list.
ld a, [hli]
and a
jr z, .quit
ld a, [hl]
call GetSpriteLength
; Spill over into the second table after $80 tiles.
add b
cp $80
jr z, .loop
jr nc, .SecondTable
.loop
ld [hl], b
inc hl
ld b, a
; Assumes the next table will be reached before c hits 0.
dec c
jr nz, .FirstTableLength
.SecondTable:
; The second tile table starts at tile $80.
ld b, $80
dec hl
.SecondTableLength:
; Keep going until the end of the list.
ld a, [hli]
and a
jr z, .quit
ld a, [hl]
call GetSpriteLength
; There are only two tables, so don't go any further than that.
add b
jr c, .quit
ld [hl], b
ld b, a
inc hl
dec c
jr nz, .SecondTableLength
.quit
ret
; 14386
GetSpriteLength: ; 14386
; Return the length of sprite type a in tiles.
cp WALKING_SPRITE
jr z, .AnyDirection
cp STANDING_SPRITE
jr z, .AnyDirection
cp STILL_SPRITE
jr z, .OneDirection
ld a, 12
ret
.AnyDirection:
ld a, 12
ret
.OneDirection:
ld a, 4
ret
; 1439b
GetUsedSprites: ; 1439b
ld hl, wUsedSprites
ld c, SPRITE_GFX_LIST_CAPACITY
.loop
ld a, [wSpriteFlags]
res 5, a
ld [wSpriteFlags], a
ld a, [hli]
and a
jr z, .done
ld [hUsedSpriteIndex], a
ld a, [hli]
ld [hUsedSpriteTile], a
bit 7, a
jr z, .dont_set
ld a, [wSpriteFlags]
set 5, a ; load VBank0
ld [wSpriteFlags], a
.dont_set
push bc
push hl
call GetUsedSprite
pop hl
pop bc
dec c
jr nz, .loop
.done
ret
; 143c8
GetUsedSprite: ; 143c8
ld a, [hUsedSpriteIndex]
call SafeGetSprite
ld a, [hUsedSpriteTile]
call .GetTileAddr
push hl
push de
push bc
ld a, [wSpriteFlags]
bit 7, a
jr nz, .skip
call .CopyToVram
.skip
pop bc
ld l, c
ld h, $0
rept 4
add hl, hl
endr
pop de
add hl, de
ld d, h
ld e, l
pop hl
ld a, [wSpriteFlags]
bit 5, a
jr nz, .done
bit 6, a
jr nz, .done
ld a, [hUsedSpriteIndex]
call _DoesSpriteHaveFacings
jr c, .done
ld a, h
add $8
ld h, a
call .CopyToVram
.done
ret
; 14406
.GetTileAddr: ; 14406
; Return the address of tile (a) in (hl).
and $7f
ld l, a
ld h, 0
rept 4
add hl, hl
endr
ld a, l
add LOW(vTiles0)
ld l, a
ld a, h
adc HIGH(vTiles0)
ld h, a
ret
; 14418
.CopyToVram: ; 14418
ld a, [rVBK]
push af
ld a, [wSpriteFlags]
bit 5, a
ld a, $1
jr z, .bankswitch
ld a, $0
.bankswitch
ld [rVBK], a
call Get2bpp
pop af
ld [rVBK], a
ret
; 1442f
LoadEmote:: ; 1442f
; Get the address of the pointer to emote c.
ld a, c
ld bc, 6 ; sizeof(emote)
ld hl, Emotes
call AddNTimes
; Load the emote address into de
ld e, [hl]
inc hl
ld d, [hl]
; load the length of the emote (in tiles) into c
inc hl
ld c, [hl]
swap c
; load the emote pointer bank into b
inc hl
ld b, [hl]
; load the VRAM destination into hl
inc hl
ld a, [hli]
ld h, [hl]
ld l, a
; if the emote has a length of 0, do not proceed (error handling)
ld a, c
and a
ret z
call GetEmote2bpp
ret
; 1444d
INCLUDE "data/sprites/emotes.asm"
INCLUDE "data/sprites/sprite_mons.asm"
INCLUDE "data/maps/outdoor_sprites.asm"
INCLUDE "data/sprites/sprites.asm"

View File

@@ -0,0 +1,851 @@
DoPlayerMovement:: ; 80000
call .GetDPad
ld a, movement_step_sleep
ld [wMovementAnimation], a
xor a
ld [wd041], a
call .TranslateIntoMovement
ld c, a
ld a, [wMovementAnimation]
ld [wPlayerNextMovement], a
ret
.GetDPad:
ld a, [hJoyDown]
ld [wCurInput], a
; Standing downhill instead moves down.
ld hl, wBikeFlags
bit BIKEFLAGS_DOWNHILL_F, [hl]
ret z
ld c, a
and D_PAD
ret nz
ld a, c
or D_DOWN
ld [wCurInput], a
ret
; 8002d
.TranslateIntoMovement:
ld a, [wPlayerState]
cp PLAYER_NORMAL
jr z, .Normal
cp PLAYER_SURF
jr z, .Surf
cp PLAYER_SURF_PIKA
jr z, .Surf
cp PLAYER_BIKE
jr z, .Normal
cp PLAYER_SKATE
jr z, .Ice
.Normal:
call .CheckForced
call .GetAction
call .CheckTile
ret c
call .CheckTurning
ret c
call .TryStep
ret c
call .TryJump
ret c
call .CheckWarp
ret c
jr .NotMoving
.Surf:
call .CheckForced
call .GetAction
call .CheckTile
ret c
call .CheckTurning
ret c
call .TrySurf
ret c
jr .NotMoving
.Ice:
call .CheckForced
call .GetAction
call .CheckTile
ret c
call .CheckTurning
ret c
call .TryStep
ret c
call .TryJump
ret c
call .CheckWarp
ret c
ld a, [wWalkingDirection]
cp STANDING
jr z, .HitWall
call .BumpSound
.HitWall:
call .StandInPlace
xor a
ret
.NotMoving:
ld a, [wWalkingDirection]
cp STANDING
jr z, .Standing
; Walking into an edge warp won't bump.
ld a, [wEngineBuffer4]
and a
jr nz, .CantMove
call .BumpSound
.CantMove:
call ._WalkInPlace
xor a
ret
.Standing:
call .StandInPlace
xor a
ret
; 800b7
.CheckTile: ; 800b7
; Tiles such as waterfalls and warps move the player
; in a given direction, overriding input.
ld a, [wPlayerStandingTile]
ld c, a
call CheckWhirlpoolTile
jr c, .not_whirlpool
ld a, 3
scf
ret
.not_whirlpool
and $f0
cp HI_NYBBLE_CURRENT
jr z, .water
cp HI_NYBBLE_WALK
jr z, .land1
cp HI_NYBBLE_WALK_ALT
jr z, .land2
cp HI_NYBBLE_WARPS
jr z, .warps
jr .no_walk
.water
ld a, c
maskbits NUM_DIRECTIONS
ld c, a
ld b, 0
ld hl, .water_table
add hl, bc
ld a, [hl]
ld [wWalkingDirection], a
jr .continue_walk
.water_table
db RIGHT ; COLL_WATERFALL_RIGHT
db LEFT ; COLL_WATERFALL_LEFT
db UP ; COLL_WATERFALL_UP
db DOWN ; COLL_WATERFALL
.land1
ld a, c
and 7
ld c, a
ld b, 0
ld hl, .land1_table
add hl, bc
ld a, [hl]
cp STANDING
jr z, .no_walk
ld [wWalkingDirection], a
jr .continue_walk
.land1_table
db STANDING ; COLL_BRAKE
db RIGHT ; COLL_WALK_RIGHT
db LEFT ; COLL_WALK_LEFT
db UP ; COLL_WALK_UP
db DOWN ; COLL_WALK_DOWN
db STANDING ; COLL_BRAKE_45
db STANDING ; COLL_BRAKE_46
db STANDING ; COLL_BRAKE_47
.land2
ld a, c
and 7
ld c, a
ld b, 0
ld hl, .land2_table
add hl, bc
ld a, [hl]
cp STANDING
jr z, .no_walk
ld [wWalkingDirection], a
jr .continue_walk
.land2_table
db RIGHT ; COLL_WALK_RIGHT_ALT
db LEFT ; COLL_WALK_LEFT_ALT
db UP ; COLL_WALK_UP_ALT
db DOWN ; COLL_WALK_DOWN_ALT
db STANDING ; COLL_BRAKE_ALT
db STANDING ; COLL_BRAKE_55
db STANDING ; COLL_BRAKE_56
db STANDING ; COLL_BRAKE_57
.warps
ld a, c
cp COLL_DOOR
jr z, .down
cp COLL_DOOR_79
jr z, .down
cp COLL_STAIRCASE
jr z, .down
cp COLL_CAVE
jr nz, .no_walk
.down
ld a, DOWN
ld [wWalkingDirection], a
jr .continue_walk
.no_walk
xor a
ret
.continue_walk
ld a, STEP_WALK
call .DoStep
ld a, 5
scf
ret
; 80147
.CheckTurning: ; 80147
; If the player is turning, change direction first. This also lets
; the player change facing without moving by tapping a direction.
ld a, [wPlayerTurningDirection]
cp 0
jr nz, .not_turning
ld a, [wWalkingDirection]
cp STANDING
jr z, .not_turning
ld e, a
ld a, [wPlayerDirection]
rrca
rrca
maskbits NUM_DIRECTIONS
cp e
jr z, .not_turning
ld a, STEP_TURN
call .DoStep
ld a, 2
scf
ret
.not_turning
xor a
ret
; 8016b
.TryStep: ; 8016b
; Surfing actually calls .TrySurf directly instead of passing through here.
ld a, [wPlayerState]
cp PLAYER_SURF
jr z, .TrySurf
cp PLAYER_SURF_PIKA
jr z, .TrySurf
call .CheckLandPerms
jr c, .bump
call .CheckNPC
and a
jr z, .bump
cp 2
jr z, .bump
ld a, [wPlayerStandingTile]
call CheckIceTile
jr nc, .ice
; Downhill riding is slower when not moving down.
call .BikeCheck
jr nz, .walk
ld hl, wBikeFlags
bit BIKEFLAGS_DOWNHILL_F, [hl]
jr z, .fast
ld a, [wWalkingDirection]
cp DOWN
jr z, .fast
ld a, STEP_WALK
call .DoStep
scf
ret
.fast
ld a, STEP_BIKE
call .DoStep
scf
ret
.walk
ld a, STEP_WALK
call .DoStep
scf
ret
.ice
ld a, STEP_ICE
call .DoStep
scf
ret
; unused
xor a
ret
.bump
xor a
ret
; 801c0
.TrySurf: ; 801c0
call .CheckSurfPerms
ld [wd040], a
jr c, .surf_bump
call .CheckNPC
ld [wd03f], a
and a
jr z, .surf_bump
cp 2
jr z, .surf_bump
ld a, [wd040]
and a
jr nz, .ExitWater
ld a, STEP_WALK
call .DoStep
scf
ret
.ExitWater:
call .GetOutOfWater
call PlayMapMusic
ld a, STEP_WALK
call .DoStep
ld a, 6
scf
ret
.surf_bump
xor a
ret
; 801f3
.TryJump: ; 801f3
ld a, [wPlayerStandingTile]
ld e, a
and $f0
cp HI_NYBBLE_LEDGES
jr nz, .DontJump
ld a, e
and 7
ld e, a
ld d, 0
ld hl, .data_8021e
add hl, de
ld a, [wFacingDirection]
and [hl]
jr z, .DontJump
ld de, SFX_JUMP_OVER_LEDGE
call PlaySFX
ld a, STEP_LEDGE
call .DoStep
ld a, 7
scf
ret
.DontJump:
xor a
ret
.data_8021e
db FACE_RIGHT ; COLL_HOP_RIGHT
db FACE_LEFT ; COLL_HOP_LEFT
db FACE_UP ; COLL_HOP_UP
db FACE_DOWN ; COLL_HOP_DOWN
db FACE_RIGHT | FACE_DOWN ; COLL_HOP_DOWN_RIGHT
db FACE_DOWN | FACE_LEFT ; COLL_HOP_DOWN_LEFT
db FACE_UP | FACE_RIGHT ; COLL_HOP_UP_RIGHT
db FACE_UP | FACE_LEFT ; COLL_HOP_UP_LEFT
; 80226
.CheckWarp: ; 80226
; Bug: Since no case is made for STANDING here, it will check
; [.edgewarps + $ff]. This resolves to $3e at $8035a.
; This causes wd041 to be nonzero when standing on tile $3e,
; making bumps silent.
ld a, [wWalkingDirection]
; cp STANDING
; jr z, .not_warp
ld e, a
ld d, 0
ld hl, .EdgeWarps
add hl, de
ld a, [wPlayerStandingTile]
cp [hl]
jr nz, .not_warp
ld a, 1
ld [wd041], a
ld a, [wWalkingDirection]
; This is in the wrong place.
cp STANDING
jr z, .not_warp
ld e, a
ld a, [wPlayerDirection]
rrca
rrca
maskbits NUM_DIRECTIONS
cp e
jr nz, .not_warp
call WarpCheck
jr nc, .not_warp
call .StandInPlace
scf
ld a, 1
ret
.not_warp
xor a
ret
.EdgeWarps:
db COLL_WARP_CARPET_DOWN
db COLL_WARP_CARPET_UP
db COLL_WARP_CARPET_LEFT
db COLL_WARP_CARPET_RIGHT
; 8025f
.DoStep:
ld e, a
ld d, 0
ld hl, .Steps
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wWalkingDirection]
ld e, a
cp STANDING
jp z, .StandInPlace
add hl, de
ld a, [hl]
ld [wMovementAnimation], a
ld hl, .FinishFacing
add hl, de
ld a, [hl]
ld [wPlayerTurningDirection], a
ld a, 4
ret
.Steps:
dw .SlowStep
dw .NormalStep
dw .FastStep
dw .JumpStep
dw .SlideStep
dw .TurningStep
dw .BackJumpStep
dw .FinishFacing
.SlowStep:
slow_step DOWN
slow_step UP
slow_step LEFT
slow_step RIGHT
.NormalStep:
step DOWN
step UP
step LEFT
step RIGHT
.FastStep:
big_step DOWN
big_step UP
big_step LEFT
big_step RIGHT
.JumpStep:
jump_step DOWN
jump_step UP
jump_step LEFT
jump_step RIGHT
.SlideStep:
fast_slide_step DOWN
fast_slide_step UP
fast_slide_step LEFT
fast_slide_step RIGHT
.BackJumpStep:
jump_step UP
jump_step DOWN
jump_step RIGHT
jump_step LEFT
.TurningStep:
turn_step DOWN
turn_step UP
turn_step LEFT
turn_step RIGHT
.FinishFacing:
db $80 + DOWN
db $80 + UP
db $80 + LEFT
db $80 + RIGHT
; 802b3
.StandInPlace: ; 802b3
ld a, 0
ld [wPlayerTurningDirection], a
ld a, movement_step_sleep
ld [wMovementAnimation], a
xor a
ret
; 802bf
._WalkInPlace: ; 802bf
ld a, 0
ld [wPlayerTurningDirection], a
ld a, movement_step_bump
ld [wMovementAnimation], a
xor a
ret
; 802cb
.CheckForced: ; 802cb
; When sliding on ice, input is forced to remain in the same direction.
call CheckStandingOnIce
ret nc
ld a, [wPlayerTurningDirection]
cp 0
ret z
maskbits NUM_DIRECTIONS
ld e, a
ld d, 0
ld hl, .forced_dpad
add hl, de
ld a, [wCurInput]
and BUTTONS
or [hl]
ld [wCurInput], a
ret
.forced_dpad
db D_DOWN, D_UP, D_LEFT, D_RIGHT
; 802ec
.GetAction: ; 802ec
; Poll player input and update movement info.
ld hl, .table
ld de, .table2 - .table1
ld a, [wCurInput]
bit D_DOWN_F, a
jr nz, .d_down
bit D_UP_F, a
jr nz, .d_up
bit D_LEFT_F, a
jr nz, .d_left
bit D_RIGHT_F, a
jr nz, .d_right
; Standing
jr .update
.d_down add hl, de
.d_up add hl, de
.d_left add hl, de
.d_right add hl, de
.update
ld a, [hli]
ld [wWalkingDirection], a
ld a, [hli]
ld [wFacingDirection], a
ld a, [hli]
ld [wWalkingX], a
ld a, [hli]
ld [wWalkingY], a
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [hl]
ld [wWalkingTile], a
ret
.table
; struct:
; walk direction
; facing
; x movement
; y movement
; tile collision pointer
.table1
db STANDING, FACE_CURRENT, 0, 0
dw wPlayerStandingTile
.table2
db RIGHT, FACE_RIGHT, 1, 0
dw wTileRight
db LEFT, FACE_LEFT, -1, 0
dw wTileLeft
db UP, FACE_UP, 0, -1
dw wTileUp
db DOWN, FACE_DOWN, 0, 1
dw wTileDown
; 80341
.CheckNPC: ; 80341
; Returns 0 if there is an NPC in front that you can't move
; Returns 1 if there is no NPC in front
; Returns 2 if there is a movable NPC in front
ld a, 0
ld [hMapObjectIndexBuffer], a
; Load the next X coordinate into d
ld a, [wPlayerStandingMapX]
ld d, a
ld a, [wWalkingX]
add d
ld d, a
; Load the next Y coordinate into e
ld a, [wPlayerStandingMapY]
ld e, a
ld a, [wWalkingY]
add e
ld e, a
; Find an object struct with coordinates equal to d,e
ld bc, wObjectStructs ; redundant
farcall IsNPCAtCoord
jr nc, .is_npc
call .CheckStrengthBoulder
jr c, .no_bump
xor a
ret
.is_npc
ld a, 1
ret
.no_bump
ld a, 2
ret
; 8036f
.CheckStrengthBoulder: ; 8036f
ld hl, wBikeFlags
bit BIKEFLAGS_STRENGTH_ACTIVE_F, [hl]
jr z, .not_boulder
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld a, [hl]
cp STANDING
jr nz, .not_boulder
ld hl, OBJECT_PALETTE
add hl, bc
bit 6, [hl]
jr z, .not_boulder
ld hl, OBJECT_FLAGS2
add hl, bc
set 2, [hl]
ld a, [wWalkingDirection]
ld d, a
ld hl, OBJECT_RANGE
add hl, bc
ld a, [hl]
and $fc
or d
ld [hl], a
scf
ret
.not_boulder
xor a
ret
; 8039e
.CheckLandPerms: ; 8039e
; Return 0 if walking onto land and tile permissions allow it.
; Otherwise, return carry.
ld a, [wTilePermissions]
ld d, a
ld a, [wFacingDirection]
and d
jr nz, .NotWalkable
ld a, [wWalkingTile]
call .CheckWalkable
jr c, .NotWalkable
xor a
ret
.NotWalkable:
scf
ret
; 803b4
.CheckSurfPerms: ; 803b4
; Return 0 if moving in water, or 1 if moving onto land.
; Otherwise, return carry.
ld a, [wTilePermissions]
ld d, a
ld a, [wFacingDirection]
and d
jr nz, .NotSurfable
ld a, [wWalkingTile]
call .CheckSurfable
jr c, .NotSurfable
and a
ret
.NotSurfable:
scf
ret
; 803ca
.BikeCheck: ; 803ca
ld a, [wPlayerState]
cp PLAYER_BIKE
ret z
cp PLAYER_SKATE
ret
; 803d3
.CheckWalkable: ; 803d3
; Return 0 if tile a is land. Otherwise, return carry.
call GetTileCollision
and a ; LANDTILE?
ret z
scf
ret
; 803da
.CheckSurfable: ; 803da
; Return 0 if tile a is water, or 1 if land.
; Otherwise, return carry.
call GetTileCollision
cp WATERTILE
jr z, .Water
; Can walk back onto land from water.
and a ; LANDTILE?
jr z, .Land
jr .Neither
.Water:
xor a
ret
.Land:
ld a, 1
and a
ret
.Neither:
scf
ret
; 803ee
.BumpSound: ; 803ee
call CheckSFX
ret c
ld de, SFX_BUMP
call PlaySFX
ret
; 803f9
.GetOutOfWater: ; 803f9
push bc
ld a, PLAYER_NORMAL
ld [wPlayerState], a
call ReplaceKrisSprite ; UpdateSprites
pop bc
ret
; 80404
CheckStandingOnIce:: ; 80404
ld a, [wPlayerTurningDirection]
cp 0
jr z, .not_ice
cp $f0
jr z, .not_ice
ld a, [wPlayerStandingTile]
call CheckIceTile
jr nc, .yep
ld a, [wPlayerState]
cp PLAYER_SKATE
jr nz, .not_ice
.yep
scf
ret
.not_ice
and a
ret
; 80422
StopPlayerForEvent:: ; 80422
ld hl, wPlayerNextMovement
ld a, movement_step_sleep
cp [hl]
ret z
ld [hl], a
ld a, 0
ld [wPlayerTurningDirection], a
ret
; 80430

View File

@@ -0,0 +1,856 @@
BlankScreen: ; 8000
call DisableSpriteUpdates
xor a
ld [hBGMapMode], a
call ClearBGPalettes
call ClearSprites
hlcoord 0, 0
ld bc, wTileMapEnd - wTileMap
ld a, " "
call ByteFill
hlcoord 0, 0, wAttrMap
ld bc, wAttrMapEnd - wAttrMap
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, PLAYER_OBJECT
call GetMapObject
ld hl, MAPOBJECT_COLOR
add hl, bc
ln e, PAL_NPC_RED, OBJECTTYPE_SCRIPT
ld a, [wPlayerSpriteSetupFlags]
bit PLAYERSPRITESETUP_FEMALE_TO_MALE_F, a
jr nz, .ok
ld a, [wPlayerGender]
bit PLAYERGENDER_FEMALE_F, a
jr z, .ok
ln e, PAL_NPC_BLUE, OBJECTTYPE_SCRIPT
.ok
ld [hl], e
ld a, PLAYER_OBJECT
ld [hMapObjectIndexBuffer], a
ld bc, wMapObjects
ld a, PLAYER_OBJECT
ld [hObjectStructIndexBuffer], a
ld de, wObjectStructs
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.
object_event -4, -4, SPRITE_CHRIS, SPRITEMOVEDATA_PLAYER, 15, 15, -1, -1, 0, OBJECTTYPE_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, [wXCoord]
add 4
ld d, a
ld a, [wYCoord]
add 4
ld e, a
pop bc
call CopyDECoordsToMapObject
ret
WriteObjectXY:: ; 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, [wXCoord]
add 4
ld d, a
ld hl, wPlayerStandingMapX
sub [hl]
ld [hl], d
ld hl, wMapObjects + MAPOBJECT_X_COORD
ld [hl], d
ld hl, wPlayerLastMapX
ld [hl], d
ld d, a
ld a, [wYCoord]
add 4
ld e, a
ld hl, wPlayerStandingMapY
sub [hl]
ld [hl], e
ld hl, wMapObjects + MAPOBJECT_Y_COORD
ld [hl], e
ld hl, wPlayerLastMapY
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, wObjectStructs + 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, wVramState
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 PALETTE_MASK
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, wMapObjects + 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, [wXCoord]
ld d, a
ld a, [wYCoord]
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, [wYCoord]
sub 1
jr .Vertical
.Down: ; 81e5
ld a, [wYCoord]
add 9
.Vertical: ; 81ea
ld d, a
ld a, [wXCoord]
ld e, a
ld bc, wMapObjects + 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, [wXCoord]
sub 1
jr .Horizontal
.Right: ; 8239
ld a, [wXCoord]
add 10
.Horizontal: ; 823e
ld e, a
ld a, [wYCoord]
ld d, a
ld bc, wMapObjects + 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, wYCoord
sub [hl]
and $f
swap a
ld hl, wPlayerBGMapOffsetY
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, wXCoord
sub [hl]
and $f
swap a
ld hl, wPlayerBGMapOffsetX
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
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
SurfStartStep: ; 8379
call InitMovementBuffer
call .GetMovementData
call AppendToMovementBuffer
ld a, movement_step_end
call AppendToMovementBuffer
ret
.GetMovementData: ; 8388
ld a, [wPlayerDirection]
srl a
srl a
maskbits NUM_DIRECTIONS
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
; object 2 is now in bc, object 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, wXCoord
sub [hl]
and $f
swap a
ld hl, wPlayerBGMapOffsetX
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, wYCoord
sub [hl]
and $f
swap a
ld hl, wPlayerBGMapOffsetY
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

270
engine/overworld/player_step.asm Executable file
View File

@@ -0,0 +1,270 @@
_HandlePlayerStep:: ; d497 (3:5497)
ld a, [wPlayerStepFlags]
and a
ret z
bit 7, a ; starting step
jr nz, .update_overworld_map
bit 6, a ; finishing step
jr nz, .update_player_coords
bit 5, a ; ongoing step
jr nz, .finish
ret
.update_overworld_map
ld a, 4
ld [wHandlePlayerStep], a
call UpdateOverworldMap
jr .finish
.update_player_coords
call UpdatePlayerCoords
jr .finish
.finish
call HandlePlayerStep
ld a, [wPlayerStepVectorX]
ld d, a
ld a, [wPlayerStepVectorY]
ld e, a
ld a, [wPlayerBGMapOffsetX]
sub d
ld [wPlayerBGMapOffsetX], a
ld a, [wPlayerBGMapOffsetY]
sub e
ld [wPlayerBGMapOffsetY], a
ret
ScrollScreen:: ; d4d2 (3:54d2)
ld a, [wPlayerStepVectorX]
ld d, a
ld a, [wPlayerStepVectorY]
ld e, a
ld a, [hSCX]
add d
ld [hSCX], a
ld a, [hSCY]
add e
ld [hSCY], a
ret
HandlePlayerStep: ; d4e5 (3:54e5)
ld hl, wHandlePlayerStep
ld a, [hl]
and a
ret z
dec [hl]
ld a, [hl]
ld hl, .Jumptable
rst JumpTable
ret
.Jumptable: ; d4f2 (3:54f2)
dw GetMovementPermissions
dw BufferScreen
dw .mobile
dw .fail2
; The rest are never used. Ever.
dw .fail1
dw .fail1
dw .fail1
dw .fail1
dw .fail1
dw .fail1
dw .fail1
.fail1 ; d508 (3:5508)
ret
.mobile ; d509 (3:5509)
farcall StubbedTrainerRankings_StepCount
ret
.fail2 ; d510 (3:5510)
ret
UpdatePlayerCoords: ; d511 (3:5511)
ld a, [wPlayerStepDirection]
and a
jr nz, .check_step_down
ld hl, wYCoord
inc [hl]
ret
.check_step_down
cp UP
jr nz, .check_step_left
ld hl, wYCoord
dec [hl]
ret
.check_step_left
cp LEFT
jr nz, .check_step_right
ld hl, wXCoord
dec [hl]
ret
.check_step_right
cp RIGHT
ret nz
ld hl, wXCoord
inc [hl]
ret
UpdateOverworldMap: ; d536 (3:5536)
ld a, [wPlayerStepDirection]
and a
jr z, .step_down
cp UP
jr z, .step_up
cp LEFT
jr z, .step_left
cp RIGHT
jr z, .step_right
ret
.step_down
call .ScrollOverworldMapDown
call LoadMapPart
call ScrollMapUp
ret
.step_up
call .ScrollOverworldMapUp
call LoadMapPart
call ScrollMapDown
ret
.step_left
call .ScrollOverworldMapLeft
call LoadMapPart
call ScrollMapRight
ret
.step_right
call .ScrollOverworldMapRight
call LoadMapPart
call ScrollMapLeft
ret
.ScrollOverworldMapDown: ; d571 (3:5571)
ld a, [wBGMapAnchor]
add 2 * BG_MAP_WIDTH
ld [wBGMapAnchor], a
jr nc, .not_overflowed
ld a, [wBGMapAnchor + 1]
inc a
and %11
or HIGH(vBGMap0)
ld [wBGMapAnchor + 1], a
.not_overflowed
ld hl, wMetatileStandingY
inc [hl]
ld a, [hl]
cp 2 ; was 1
jr nz, .done_down
ld [hl], 0
call .Add6ToOverworldMapAnchor
.done_down
ret
.Add6ToOverworldMapAnchor: ; d595 (3:5595)
ld hl, wOverworldMapAnchor
ld a, [wMapWidth]
add 6
add [hl]
ld [hli], a
ret nc
inc [hl]
ret
.ScrollOverworldMapUp: ; d5a2 (3:55a2)
ld a, [wBGMapAnchor]
sub 2 * BG_MAP_WIDTH
ld [wBGMapAnchor], a
jr nc, .not_underflowed
ld a, [wBGMapAnchor + 1]
dec a
and %11
or HIGH(vBGMap0)
ld [wBGMapAnchor + 1], a
.not_underflowed
ld hl, wMetatileStandingY
dec [hl]
ld a, [hl]
cp -1 ; was 0
jr nz, .done_up
ld [hl], $1
call .Sub6FromOverworldMapAnchor
.done_up
ret
.Sub6FromOverworldMapAnchor: ; d5c6 (3:55c6)
ld hl, wOverworldMapAnchor
ld a, [wMapWidth]
add 6
ld b, a
ld a, [hl]
sub b
ld [hli], a
ret nc
dec [hl]
ret
.ScrollOverworldMapLeft: ; d5d5 (3:55d5)
ld a, [wBGMapAnchor]
ld e, a
and $e0
ld d, a
ld a, e
sub $2
and $1f
or d
ld [wBGMapAnchor], a
ld hl, wMetatileStandingX
dec [hl]
ld a, [hl]
cp -1
jr nz, .done_left
ld [hl], 1
call .DecrementwOverworldMapAnchor
.done_left
ret
.DecrementwOverworldMapAnchor: ; d5f4 (3:55f4)
ld hl, wOverworldMapAnchor
ld a, [hl]
sub 1
ld [hli], a
ret nc
dec [hl]
ret
.ScrollOverworldMapRight: ; d5fe (3:55fe)
ld a, [wBGMapAnchor]
ld e, a
and $e0
ld d, a
ld a, e
add $2
and $1f
or d
ld [wBGMapAnchor], a
ld hl, wMetatileStandingX
inc [hl]
ld a, [hl]
cp 2
jr nz, .done_right
ld [hl], 0
call .IncrementwOverworldMapAnchor
.done_right
ret
.IncrementwOverworldMapAnchor: ; d61d (3:561d)
ld hl, wOverworldMapAnchor
ld a, [hl]
add 1
ld [hli], a
ret nc
inc [hl]
ret

File diff suppressed because it is too large Load Diff

191
engine/overworld/select_menu.asm Executable file
View File

@@ -0,0 +1,191 @@
SelectMenu:: ; 13327
call CheckRegisteredItem
jr c, .NotRegistered
jp UseRegisteredItem
.NotRegistered:
call OpenText
ld b, BANK(ItemMayBeRegisteredText)
ld hl, ItemMayBeRegisteredText
call MapTextbox
call WaitButton
jp CloseText
; 13340
ItemMayBeRegisteredText: ; 13340
text_jump UnknownText_0x1c1cf3
db "@"
; 13345
CheckRegisteredItem: ; 13345
ld a, [wWhichRegisteredItem]
and a
jr z, .NoRegisteredItem
and REGISTERED_POCKET
rlca
rlca
ld hl, .Pockets
rst JumpTable
ret
.Pockets:
; entries correspond to *_POCKET constants
dw .CheckItem
dw .CheckBall
dw .CheckKeyItem
dw .CheckTMHM
.CheckItem:
ld hl, wNumItems
call .CheckRegisteredNo
jr c, .NoRegisteredItem
inc hl
ld e, a
ld d, 0
add hl, de
add hl, de
call .IsSameItem
jr c, .NoRegisteredItem
and a
ret
.CheckKeyItem:
ld a, [wRegisteredItem]
ld hl, wKeyItems
ld de, 1
call IsInArray
jr nc, .NoRegisteredItem
ld a, [wRegisteredItem]
ld [wCurItem], a
and a
ret
.CheckBall:
ld hl, wNumBalls
call .CheckRegisteredNo
jr nc, .NoRegisteredItem
inc hl
ld e, a
ld d, 0
add hl, de
add hl, de
call .IsSameItem
jr c, .NoRegisteredItem
ret
.CheckTMHM:
jr .NoRegisteredItem
.NoRegisteredItem:
xor a
ld [wWhichRegisteredItem], a
ld [wRegisteredItem], a
scf
ret
; 133a6
.CheckRegisteredNo: ; 133a6
ld a, [wWhichRegisteredItem]
and REGISTERED_NUMBER
dec a
cp [hl]
jr nc, .NotEnoughItems
ld [wCurItemQuantity], a
and a
ret
.NotEnoughItems:
scf
ret
; 133b6
.IsSameItem: ; 133b6
ld a, [wRegisteredItem]
cp [hl]
jr nz, .NotSameItem
ld [wCurItem], a
and a
ret
.NotSameItem:
scf
ret
; 133c3
UseRegisteredItem: ; 133c3
farcall CheckItemMenu
ld a, [wItemAttributeParamBuffer]
ld hl, .SwitchTo
rst JumpTable
ret
.SwitchTo:
; entries correspond to ITEMMENU_* constants
dw .CantUse
dw .NoFunction
dw .NoFunction
dw .NoFunction
dw .Current
dw .Party
dw .Overworld
; 133df
.NoFunction: ; 133df
call OpenText
call CantUseItem
call CloseText
and a
ret
; 133ea
.Current: ; 133ea
call OpenText
call DoItemEffect
call CloseText
and a
ret
; 133f5
.Party: ; 133f5
call RefreshScreen
call FadeToMenu
call DoItemEffect
call CloseSubmenu
call CloseText
and a
ret
; 13406
.Overworld: ; 13406
call RefreshScreen
ld a, 1
ld [wUsingItemWithSelect], a
call DoItemEffect
xor a
ld [wUsingItemWithSelect], a
ld a, [wItemEffectSucceeded]
cp 1
jr nz, ._cantuse
scf
ld a, HMENURETURN_SCRIPT
ld [hMenuReturn], a
ret
; 13422
.CantUse: ; 13422
call RefreshScreen
._cantuse
call CantUseItem
call CloseText
and a
ret
; 1342d

View File

@@ -0,0 +1,62 @@
INCLUDE "data/maps/spawn_points.asm"
LoadSpawnPoint: ; 1531f
; loads the spawn point in wDefaultSpawnpoint
push hl
push de
ld a, [wDefaultSpawnpoint]
cp SPAWN_N_A
jr z, .spawn_n_a
ld l, a
ld h, 0
add hl, hl
add hl, hl
ld de, SpawnPoints
add hl, de
ld a, [hli]
ld [wMapGroup], a
ld a, [hli]
ld [wMapNumber], a
ld a, [hli]
ld [wXCoord], a
ld a, [hli]
ld [wYCoord], a
.spawn_n_a
pop de
pop hl
ret
; 15344
IsSpawnPoint: ; 15344
; Checks if the map loaded in de is a spawn point. Returns carry if it's a spawn point.
ld hl, SpawnPoints
ld c, 0
.loop
ld a, [hl]
cp SPAWN_N_A
jr z, .nope
cp d
jr nz, .next
inc hl
ld a, [hld]
cp e
jr z, .yes
.next
push bc
ld bc, 4 ; length of a spawn table entry
add hl, bc
pop bc
inc c
jr .loop
.nope
and a
ret
.yes
scf
ret
; 15363

110
engine/overworld/tile_events.asm Executable file
View File

@@ -0,0 +1,110 @@
CheckWarpCollision:: ; 1499a
; Is this tile a warp?
ld a, [wPlayerStandingTile]
cp COLL_PIT
jr z, .warp
cp COLL_PIT_68
jr z, .warp
and $f0
cp HI_NYBBLE_WARPS
jr z, .warp
and a
ret
.warp
scf
ret
; 149af
CheckDirectionalWarp:: ; 149af
; If this is a directional warp, clear carry (press the designated button to warp).
; Else, set carry (immediate warp).
ld a, [wPlayerStandingTile]
cp COLL_WARP_CARPET_DOWN
jr z, .directional
cp COLL_WARP_CARPET_LEFT
jr z, .directional
cp COLL_WARP_CARPET_UP
jr z, .directional
cp COLL_WARP_CARPET_RIGHT
jr z, .directional
scf
ret
.directional
xor a
ret
; 149c6
CheckWarpFacingDown: ; 149c6
ld de, 1
ld hl, .blocks
ld a, [wPlayerStandingTile]
call IsInArray
ret
; 149d3
.blocks ; 149d3
db COLL_DOOR
db COLL_DOOR_79
db COLL_STAIRCASE
db COLL_STAIRCASE_73
db COLL_CAVE
db COLL_CAVE_74
db COLL_WARP_PANEL
db COLL_DOOR_75
db COLL_DOOR_7D
db -1
; 149dd
CheckGrassCollision:: ; 149dd
ld a, [wPlayerStandingTile]
ld hl, .blocks
ld de, 1
call IsInArray
ret
; 149ea
.blocks ; 149ea
db COLL_CUT_08
db COLL_TALL_GRASS
db COLL_LONG_GRASS
db COLL_CUT_28
db COLL_WATER
db COLL_GRASS_48
db COLL_GRASS_49
db COLL_GRASS_4A
db COLL_GRASS_4B
db COLL_GRASS_4C
db -1
; 149f5
CheckCutCollision: ; 149f5
ld a, c
ld hl, .blocks
ld de, 1
call IsInArray
ret
; 14a00
.blocks ; 14a00
db COLL_CUT_TREE
db COLL_CUT_TREE_1A
db COLL_TALL_GRASS_10
db COLL_TALL_GRASS
db COLL_LONG_GRASS
db COLL_LONG_GRASS_1C
db -1
; 14a07
GetWarpSFX:: ; 14a07
ld a, [wPlayerStandingTile]
ld de, SFX_ENTER_DOOR
cp COLL_DOOR
ret z
ld de, SFX_WARP_TO
cp COLL_WARP_PANEL
ret z
ld de, SFX_EXIT_BUILDING
ret
; 14a1a

465
engine/overworld/time.asm Executable file
View File

@@ -0,0 +1,465 @@
_InitializeStartDay: ; 113d6
call InitializeStartDay
ret
; 113da
ClearDailyTimers: ; 113da
xor a
ld [wLuckyNumberDayBuffer], a
ld [wUnusedTwoDayTimer], a
ld [wDailyResetTimer], a
ret
; 113e5
InitCallReceiveDelay:: ; 113e5
xor a
ld [wTimeCyclesSinceLastCall], a
NextCallReceiveDelay: ; 113e9
ld a, [wTimeCyclesSinceLastCall]
cp 3
jr c, .okay
ld a, 3
.okay
ld e, a
ld d, 0
ld hl, .ReceiveCallDelays
add hl, de
ld a, [hl]
jp RestartReceiveCallDelay
; 113fd
.ReceiveCallDelays:
db 20, 10, 5, 3
; 11401
CheckReceiveCallTimer: ; 11401
call CheckReceiveCallDelay ; check timer
ret nc
ld hl, wTimeCyclesSinceLastCall
ld a, [hl]
cp 3
jr nc, .ok
inc [hl]
.ok
call NextCallReceiveDelay ; restart timer
scf
ret
; 11413
InitOneDayCountdown: ; 11413
ld a, 1
InitNDaysCountdown: ; 11415
ld [hl], a
push hl
call UpdateTime
pop hl
inc hl
call CopyDayToHL
ret
; 11420
CheckDayDependentEventHL: ; 11420
inc hl
push hl
call CalcDaysSince
call GetDaysSince
pop hl
dec hl
call UpdateTimeRemaining
ret
; 1142e
RestartReceiveCallDelay: ; 1142e
ld hl, wReceiveCallDelay_MinsRemaining
ld [hl], a
call UpdateTime
ld hl, wReceiveCallDelay_StartTime
call CopyDayHourMinToHL
ret
; 1143c
CheckReceiveCallDelay: ; 1143c
ld hl, wReceiveCallDelay_StartTime
call CalcMinsHoursDaysSince
call GetMinutesSinceIfLessThan60
ld hl, wReceiveCallDelay_MinsRemaining
call UpdateTimeRemaining
ret
; 1144c
RestartDailyResetTimer: ; 1144c
ld hl, wDailyResetTimer
jp InitOneDayCountdown
; 11452
CheckDailyResetTimer:: ; 11452
ld hl, wDailyResetTimer
call CheckDayDependentEventHL
ret nc
xor a
ld hl, wDailyFlags
ld [hli], a ; wDailyFlags
ld [hli], a ; wWeeklyFlags
ld [hli], a ; wSwarmFlags
ld [hl], a ; wSwarmFlags + 1
ld hl, wDailyRematchFlags
rept 4
ld [hli], a
endr
ld hl, wDailyPhoneItemFlags
rept 4
ld [hli], a
endr
ld hl, wDailyPhoneTimeOfDayFlags
rept 4
ld [hli], a
endr
ld hl, wKenjiBreakTimer
ld a, [hl]
and a
jr z, .RestartKenjiBreakCountdown
dec [hl]
jr nz, .DontRestartKenjiBreakCountdown
.RestartKenjiBreakCountdown:
call SampleKenjiBreakCountdown
.DontRestartKenjiBreakCountdown:
jr RestartDailyResetTimer
; 11485
SampleKenjiBreakCountdown: ; 11485
; Generate a random number between 3 and 6
call Random
and %11
add 3
ld [wKenjiBreakTimer], a
ret
; 11490
StartBugContestTimer: ; 11490
ld a, BUG_CONTEST_MINUTES
ld [wBugContestMinsRemaining], a
ld a, BUG_CONTEST_SECONDS
ld [wBugContestSecsRemaining], a
call UpdateTime
ld hl, wBugContestStartTime
call CopyDayHourMinSecToHL
ret
; 114a4
CheckBugContestTimer:: ; 114a4 (4:54a4)
ld hl, wBugContestStartTime
call CalcSecsMinsHoursDaysSince
ld a, [wDaysSince]
and a
jr nz, .timed_out
ld a, [wHoursSince]
and a
jr nz, .timed_out
ld a, [wSecondsSince]
ld b, a
ld a, [wBugContestSecsRemaining]
sub b
jr nc, .okay
add 60
.okay
ld [wBugContestSecsRemaining], a
ld a, [wMinutesSince]
ld b, a
ld a, [wBugContestMinsRemaining]
sbc b
ld [wBugContestMinsRemaining], a
jr c, .timed_out
and a
ret
.timed_out
xor a
ld [wBugContestMinsRemaining], a
ld [wBugContestSecsRemaining], a
scf
ret
InitializeStartDay: ; 114dd
call UpdateTime
ld hl, wTimerEventStartDay
call CopyDayToHL
ret
; 114e7
CheckPokerusTick:: ; 114e7
ld hl, wTimerEventStartDay
call CalcDaysSince
call GetDaysSince
and a
jr z, .done ; not even a day has passed since game start
ld b, a
farcall ApplyPokerusTick
.done
xor a
ret
; 114fc
SetUnusedTwoDayTimer: ; 114fc
ld a, 2
ld hl, wUnusedTwoDayTimer
ld [hl], a
call UpdateTime
ld hl, wUnusedTwoDayTimerStartDate
call CopyDayToHL
ret
; 1150c
CheckUnusedTwoDayTimer: ; 1150c
ld hl, wUnusedTwoDayTimerStartDate
call CalcDaysSince
call GetDaysSince
ld hl, wUnusedTwoDayTimer
call UpdateTimeRemaining
ret
; 1151c
; unused
ld hl, wDailyFlags
set DAILYFLAGS_FISH_SWARM_F, [hl]
ret
; 11522
; unused
and a
ld hl, wDailyFlags
bit DAILYFLAGS_FISH_SWARM_F, [hl]
ret nz
scf
ret
; 1152b
RestartLuckyNumberCountdown: ; 1152b
call .GetDaysUntilNextFriday
ld hl, wLuckyNumberDayBuffer
jp InitNDaysCountdown
; 11534
.GetDaysUntilNextFriday: ; 11534
call GetWeekday
ld c, a
ld a, FRIDAY
sub c
jr z, .friday_saturday
jr nc, .earlier ; could have done "ret nc"
.friday_saturday
add 7
.earlier
ret
; 11542
_CheckLuckyNumberShowFlag: ; 11542
ld hl, wLuckyNumberDayBuffer
jp CheckDayDependentEventHL
; 11548
DoMysteryGiftIfDayHasPassed: ; 11548
ld a, BANK(sMysteryGiftTimer)
call GetSRAMBank
ld hl, sMysteryGiftTimer
ld a, [hli]
ld [wBuffer1], a
ld a, [hl]
ld [wBuffer2], a
call CloseSRAM
ld hl, wBuffer1
call CheckDayDependentEventHL
jr nc, .not_timed_out
ld hl, wBuffer1
call InitOneDayCountdown
call CloseSRAM
farcall Function1050c8
.not_timed_out
ld a, BANK(sMysteryGiftTimer)
call GetSRAMBank
ld hl, wBuffer1
ld a, [hli]
ld [sMysteryGiftTimer], a
ld a, [hl]
ld [sMysteryGiftTimer + 1], a
call CloseSRAM
ret
; 11586
UpdateTimeRemaining: ; 11586
; If the amount of time elapsed exceeds the capacity of its
; unit, skip this part.
cp -1
jr z, .set_carry
ld c, a
ld a, [hl] ; time remaining
sub c
jr nc, .ok
xor a
.ok
ld [hl], a
jr z, .set_carry
xor a
ret
.set_carry
xor a
ld [hl], a
scf
ret
; 11599
GetSecondsSinceIfLessThan60: ; 11599
ld a, [wDaysSince]
and a
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wHoursSince]
and a
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wMinutesSince]
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wSecondsSince]
ret
; 115ae
GetMinutesSinceIfLessThan60: ; 115ae
ld a, [wDaysSince]
and a
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wHoursSince]
and a
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wMinutesSince]
ret
; 115be
GetHoursSinceIfLessThan24: ; 115be
ld a, [wDaysSince]
and a
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wHoursSince]
ret
; 115c8
GetDaysSince: ; 115c8
ld a, [wDaysSince]
ret
; 115cc
GetTimeElapsed_ExceedsUnitLimit: ; 115cc
ld a, -1
ret
; 115cf
CalcDaysSince: ; 115cf
xor a
jr _CalcDaysSince
; 115d2
CalcHoursDaysSince: ; 115d2
inc hl
xor a
jr _CalcHoursDaysSince
; 115d6
CalcMinsHoursDaysSince: ; 115d6
inc hl
inc hl
xor a
jr _CalcMinsHoursDaysSince
; 115db
CalcSecsMinsHoursDaysSince: ; 115db
inc hl
inc hl
inc hl
ld a, [hSeconds]
ld c, a
sub [hl]
jr nc, .skip
add 60
.skip
ld [hl], c ; current seconds
dec hl
ld [wSecondsSince], a ; seconds since
_CalcMinsHoursDaysSince: ; 115eb
ld a, [hMinutes]
ld c, a
sbc [hl]
jr nc, .skip
add 60
.skip
ld [hl], c ; current minutes
dec hl
ld [wMinutesSince], a ; minutes since
_CalcHoursDaysSince: ; 115f8
ld a, [hHours]
ld c, a
sbc [hl]
jr nc, .skip
add 24
.skip
ld [hl], c ; current hours
dec hl
ld [wHoursSince], a ; hours since
_CalcDaysSince:
ld a, [wCurDay]
ld c, a
sbc [hl]
jr nc, .skip
add 20 * 7
.skip
ld [hl], c ; current days
ld [wDaysSince], a ; days since
ret
; 11613
CopyDayHourMinSecToHL: ; 11613
ld a, [wCurDay]
ld [hli], a
ld a, [hHours]
ld [hli], a
ld a, [hMinutes]
ld [hli], a
ld a, [hSeconds]
ld [hli], a
ret
; 11621
CopyDayToHL: ; 11621
ld a, [wCurDay]
ld [hl], a
ret
; 11626
CopyDayHourToHL: ; 11626
ld a, [wCurDay]
ld [hli], a
ld a, [hHours]
ld [hli], a
ret
; 1162e
CopyDayHourMinToHL: ; 1162e
ld a, [wCurDay]
ld [hli], a
ld a, [hHours]
ld [hli], a
ld a, [hMinutes]
ld [hli], a
ret
; 11639

151
engine/overworld/variables.asm Executable file
View File

@@ -0,0 +1,151 @@
_GetVarAction:: ; 80648 (20:4648)
ld a, c
cp NUM_VARS
jr c, .valid
xor a
.valid
ld c, a
ld b, 0
ld hl, .VarActionTable
add hl, bc
add hl, bc
add hl, bc
ld e, [hl]
inc hl
ld d, [hl]
inc hl
ld b, [hl]
ld a, b
and RETVAR_EXECUTE
jr nz, .call
ld a, b
and RETVAR_ADDR_DE
ret nz
ld a, [de]
jr .loadstringbuffer2
.call
call _de_
ret
.loadstringbuffer2 ; 8066c (20:466c)
ld de, wStringBuffer2
ld [de], a
ret
; 80671 (20:4671)
.VarActionTable: ; 80671
; entries correspond to VAR_* constants
; RETVAR_STRBUF2: copy [de] to wStringBuffer2
; RETVAR_ADDR_DE: return address in de
; RETVAR_EXECUTE: call function
dwb wStringBuffer2, RETVAR_STRBUF2
dwb wPartyCount, RETVAR_STRBUF2
dwb .BattleResult, RETVAR_EXECUTE
dwb wBattleType, RETVAR_ADDR_DE
dwb wTimeOfDay, RETVAR_STRBUF2
dwb .CountCaughtMons, RETVAR_EXECUTE
dwb .CountSeenMons, RETVAR_EXECUTE
dwb .CountBadges, RETVAR_EXECUTE
dwb wPlayerState, RETVAR_ADDR_DE
dwb .PlayerFacing, RETVAR_EXECUTE
dwb hHours, RETVAR_STRBUF2
dwb .DayOfWeek, RETVAR_EXECUTE
dwb wMapGroup, RETVAR_STRBUF2
dwb wMapNumber, RETVAR_STRBUF2
dwb .UnownCaught, RETVAR_EXECUTE
dwb wEnvironment, RETVAR_STRBUF2
dwb .BoxFreeSpace, RETVAR_EXECUTE
dwb wBugContestMinsRemaining, RETVAR_STRBUF2
dwb wXCoord, RETVAR_STRBUF2
dwb wYCoord, RETVAR_STRBUF2
dwb wSpecialPhoneCallID, RETVAR_STRBUF2
dwb wNrOfBeatenBattleTowerTrainers, RETVAR_STRBUF2
dwb wKurtApricornQuantity, RETVAR_STRBUF2
dwb wCurrentCaller, RETVAR_ADDR_DE
dwb wBlueCardBalance, RETVAR_ADDR_DE
dwb wBuenasPassword, RETVAR_ADDR_DE
dwb wKenjiBreakTimer, RETVAR_STRBUF2
dwb NULL, RETVAR_STRBUF2
; 806c5
.CountCaughtMons: ; 806c5
; Caught mons.
ld hl, wPokedexCaught
ld b, wEndPokedexCaught - wPokedexCaught
call CountSetBits
ld a, [wd265]
jp .loadstringbuffer2
; 806d3
.CountSeenMons: ; 806d3
; Seen mons.
ld hl, wPokedexSeen
ld b, wEndPokedexSeen - wPokedexSeen
call CountSetBits
ld a, [wd265]
jp .loadstringbuffer2
; 806e1
.CountBadges: ; 806e1
; Number of owned badges.
ld hl, wBadges
ld b, 2
call CountSetBits
ld a, [wd265]
jp .loadstringbuffer2
; 806ef
.PlayerFacing: ; 806ef
; The direction the player is facing.
ld a, [wPlayerDirection]
and $c
rrca
rrca
jp .loadstringbuffer2
; 806f9
.DayOfWeek: ; 806f9
; The day of the week.
call GetWeekday
jp .loadstringbuffer2
; 806ff
.UnownCaught: ; 806ff
; Number of unique Unown caught.
call .count
ld a, b
jp .loadstringbuffer2
.count
ld hl, wUnownDex
ld b, 0
.loop
ld a, [hli]
and a
ret z
inc b
ld a, b
cp NUM_UNOWN
jr c, .loop
ret
; 80715
.BoxFreeSpace: ; 80715
; Remaining slots in the current box.
ld a, BANK(sBoxCount)
call GetSRAMBank
ld hl, sBoxCount
ld a, MONS_PER_BOX
sub [hl]
ld b, a
call CloseSRAM
ld a, b
jp .loadstringbuffer2
; 80728
.BattleResult: ; 80728
ld a, [wBattleResult]
and $3f
jp .loadstringbuffer2
; 80730

View File

@@ -0,0 +1,439 @@
HandleNewMap: ; 1045b0
call Clearwc7e8
call ResetMapBufferEventFlags
call ResetFlashIfOutOfCave
call GetCurrentMapSceneID
call ResetBikeFlags
ld a, MAPCALLBACK_NEWMAP
call RunMapCallback
InitCommandQueue: ; 1045c4
farcall ClearCmdQueue
ld a, MAPCALLBACK_CMDQUEUE
call RunMapCallback
call GetMapTimeOfDay
ld [wMapTimeOfDay], a
ret
EnterMapConnection: ; 1045d6
; Return carry if a connection has been entered.
ld a, [wPlayerStepDirection]
and a
jp z, .south
cp UP
jp z, .north
cp LEFT
jp z, .west
cp RIGHT
jp z, .east
ret
.west
ld a, [wWestConnectedMapGroup]
ld [wMapGroup], a
ld a, [wWestConnectedMapNumber]
ld [wMapNumber], a
ld a, [wWestConnectionStripXOffset]
ld [wXCoord], a
ld a, [wWestConnectionStripYOffset]
ld hl, wYCoord
add [hl]
ld [hl], a
ld c, a
ld hl, wWestConnectionWindow
ld a, [hli]
ld h, [hl]
ld l, a
srl c
jr z, .skip_to_load
ld a, [wWestConnectedMapWidth]
add 6
ld e, a
ld d, 0
.loop
add hl, de
dec c
jr nz, .loop
.skip_to_load
ld a, l
ld [wOverworldMapAnchor], a
ld a, h
ld [wOverworldMapAnchor + 1], a
jp .done
.east
ld a, [wEastConnectedMapGroup]
ld [wMapGroup], a
ld a, [wEastConnectedMapNumber]
ld [wMapNumber], a
ld a, [wEastConnectionStripXOffset]
ld [wXCoord], a
ld a, [wEastConnectionStripYOffset]
ld hl, wYCoord
add [hl]
ld [hl], a
ld c, a
ld hl, wEastConnectionWindow
ld a, [hli]
ld h, [hl]
ld l, a
srl c
jr z, .skip_to_load2
ld a, [wEastConnectedMapWidth]
add 6
ld e, a
ld d, 0
.loop2
add hl, de
dec c
jr nz, .loop2
.skip_to_load2
ld a, l
ld [wOverworldMapAnchor], a
ld a, h
ld [wOverworldMapAnchor + 1], a
jp .done
.north
ld a, [wNorthConnectedMapGroup]
ld [wMapGroup], a
ld a, [wNorthConnectedMapNumber]
ld [wMapNumber], a
ld a, [wNorthConnectionStripYOffset]
ld [wYCoord], a
ld a, [wNorthConnectionStripXOffset]
ld hl, wXCoord
add [hl]
ld [hl], a
ld c, a
ld hl, wNorthConnectionWindow
ld a, [hli]
ld h, [hl]
ld l, a
ld b, 0
srl c
add hl, bc
ld a, l
ld [wOverworldMapAnchor], a
ld a, h
ld [wOverworldMapAnchor + 1], a
jp .done
.south
ld a, [wSouthConnectedMapGroup]
ld [wMapGroup], a
ld a, [wSouthConnectedMapNumber]
ld [wMapNumber], a
ld a, [wSouthConnectionStripYOffset]
ld [wYCoord], a
ld a, [wSouthConnectionStripXOffset]
ld hl, wXCoord
add [hl]
ld [hl], a
ld c, a
ld hl, wSouthConnectionWindow
ld a, [hli]
ld h, [hl]
ld l, a
ld b, 0
srl c
add hl, bc
ld a, l
ld [wOverworldMapAnchor], a
ld a, h
ld [wOverworldMapAnchor + 1], a
.done
scf
ret
; 1046c6
LoadWarpData: ; 1046c6
call .SaveDigWarp
call .SetSpawn
ld a, [wNextWarp]
ld [wWarpNumber], a
ld a, [wNextMapGroup]
ld [wMapGroup], a
ld a, [wNextMapNumber]
ld [wMapNumber], a
ret
.SaveDigWarp: ; 1046df (41:46df)
call GetMapEnvironment
call CheckOutdoorMap
ret nz
ld a, [wNextMapGroup]
ld b, a
ld a, [wNextMapNumber]
ld c, a
call GetAnyMapEnvironment
call CheckIndoorMap
ret nz
; MOUNT_MOON_SQUARE and TIN_TOWER_ROOF are outdoor maps within indoor maps.
; Dig and Escape Rope should not take you to them.
ld a, [wPrevMapGroup]
cp GROUP_MOUNT_MOON_SQUARE ; GROUP_TIN_TOWER_ROOF
jr nz, .not_mt_moon_or_tin_tower
ld a, [wPrevMapNumber]
cp MAP_MOUNT_MOON_SQUARE
ret z
cp MAP_TIN_TOWER_ROOF
ret z
.not_mt_moon_or_tin_tower
ld a, [wPrevWarp]
ld [wDigWarpNumber], a
ld a, [wPrevMapGroup]
ld [wDigMapGroup], a
ld a, [wPrevMapNumber]
ld [wDigMapNumber], a
ret
.SetSpawn: ; 104718 (41:4718)
call GetMapEnvironment
call CheckOutdoorMap
ret nz
ld a, [wNextMapGroup]
ld b, a
ld a, [wNextMapNumber]
ld c, a
call GetAnyMapEnvironment
call CheckIndoorMap
ret nz
ld a, [wNextMapGroup]
ld b, a
ld a, [wNextMapNumber]
ld c, a
; Respawn in Pokémon Centers.
call GetAnyMapTileset
ld a, c
cp TILESET_POKECENTER
jr z, .pokecenter_pokecom
cp TILESET_POKECOM_CENTER
jr z, .pokecenter_pokecom
ret
.pokecenter_pokecom
ld a, [wPrevMapGroup]
ld [wLastSpawnMapGroup], a
ld a, [wPrevMapNumber]
ld [wLastSpawnMapNumber], a
ret
LoadMapTimeOfDay: ; 104750
ld hl, wVramState
res 6, [hl]
ld a, $1
ld [wSpriteUpdatesEnabled], a
farcall ReplaceTimeOfDayPals
farcall UpdateTimeOfDayPal
call OverworldTextModeSwitch
call .ClearBGMap
call .PushAttrMap
ret
.ClearBGMap: ; 104770 (41:4770)
ld a, HIGH(vBGMap0)
ld [wBGMapAnchor + 1], a
xor a ; LOW(vBGMap0)
ld [wBGMapAnchor], a
ld [hSCY], a
ld [hSCX], a
farcall ApplyBGMapAnchorToObjects
ld a, [rVBK]
push af
ld a, $1
ld [rVBK], a
xor a
ld bc, vBGMap1 - vBGMap0
hlbgcoord 0, 0
call ByteFill
pop af
ld [rVBK], a
ld a, "■"
ld bc, vBGMap1 - vBGMap0
hlbgcoord 0, 0
call ByteFill
ret
.PushAttrMap: ; 1047a3 (41:47a3)
decoord 0, 0
call .copy
ld a, [hCGB]
and a
ret z
decoord 0, 0, wAttrMap
ld a, $1
ld [rVBK], a
.copy
hlbgcoord 0, 0
ld c, SCREEN_WIDTH
ld b, SCREEN_HEIGHT
.row
push bc
.column
ld a, [de]
inc de
ld [hli], a
dec c
jr nz, .column
ld bc, BG_MAP_WIDTH - SCREEN_WIDTH
add hl, bc
pop bc
dec b
jr nz, .row
ld a, $0
ld [rVBK], a
ret
LoadGraphics: ; 1047cf
call LoadTileset
call LoadTilesetGFX
xor a
ld [hMapAnims], a
xor a
ld [hTileAnimFrame], a
farcall RefreshSprites
call LoadFontsExtra
farcall LoadOverworldFont
ret
LoadMapPalettes: ; 1047eb
ld b, SCGB_MAPPALS
jp GetSGBLayout
; 1047f0
RefreshMapSprites: ; 1047f0
call ClearSprites
farcall ReturnFromMapSetupScript
call GetMovementPermissions
farcall RefreshPlayerSprite
farcall CheckReplaceKrisSprite
ld hl, wPlayerSpriteSetupFlags
bit PLAYERSPRITESETUP_SKIP_RELOAD_GFX_F, [hl]
jr nz, .skip
ld hl, wVramState
set 0, [hl]
call SafeUpdateSprites
.skip
ld a, [wPlayerSpriteSetupFlags]
and %00011100
ld [wPlayerSpriteSetupFlags], a
ret
CheckMovingOffEdgeOfMap:: ; 104820 (41:4820)
ld a, [wPlayerStepDirection]
cp STANDING
ret z
and a ; DOWN
jr z, .down
cp UP
jr z, .up
cp LEFT
jr z, .left
cp RIGHT
jr z, .right
and a
ret
.down
ld a, [wPlayerStandingMapY]
sub 4
ld b, a
ld a, [wMapHeight]
add a
cp b
jr z, .ok
and a
ret
.up
ld a, [wPlayerStandingMapY]
sub 4
cp -1
jr z, .ok
and a
ret
.left
ld a, [wPlayerStandingMapX]
sub 4
cp -1
jr z, .ok
and a
ret
.right
ld a, [wPlayerStandingMapX]
sub 4
ld b, a
ld a, [wMapWidth]
add a
cp b
jr z, .ok
and a
ret
.ok
scf
ret
GetCoordOfUpperLeftCorner:: ; 10486d
ld hl, wOverworldMap
ld a, [wXCoord]
bit 0, a
jr nz, .increment_then_halve1
srl a
add $1
jr .resume
.increment_then_halve1
add $1
srl a
.resume
ld c, a
ld b, $0
add hl, bc
ld a, [wMapWidth]
add $6
ld c, a
ld b, $0
ld a, [wYCoord]
bit 0, a
jr nz, .increment_then_halve2
srl a
add $1
jr .resume2
.increment_then_halve2
add $1
srl a
.resume2
call AddNTimes
ld a, l
ld [wOverworldMapAnchor], a
ld a, h
ld [wOverworldMapAnchor + 1], a
ld a, [wYCoord]
and $1
ld [wMetatileStandingY], a
ld a, [wXCoord]
and $1
ld [wMetatileStandingX], a
ret
; 1048ba

1000
engine/overworld/wildmons.asm Executable file

File diff suppressed because it is too large Load Diff