diff --git a/engine/board/menu.asm b/engine/board/menu.asm index deed53cd6..fc9720f18 100755 --- a/engine/board/menu.asm +++ b/engine/board/menu.asm @@ -15,12 +15,13 @@ BoardMenuScript:: ; save after opentext to reanchor map first ; save before processing variables like wCurTurn due to BoardMenuScript reentry after game reset farcall AutoSaveGameInOverworld - ld hl, wCurTurn - inc [hl] ld hl, wTurnData ld bc, wTurnDataEnd - wTurnData xor a - jp ByteFill + call ByteFill + ld hl, wCurTurn + inc [hl] + jp LoadCurSpaceData .Die: callasm BoardMenu_Die diff --git a/engine/board/movement.asm b/engine/board/movement.asm new file mode 100755 index 000000000..7a98231db --- /dev/null +++ b/engine/board/movement.asm @@ -0,0 +1,29 @@ +StepTowardsNextSpace:: + ld a, [wCurSpaceNextSpace] + call LoadTempSpaceData + ld a, [wTempSpaceXCoord] + ld c, a + ld a, [wXCoord] + cp c + jr z, .check_y + ld a, D_RIGHT + jr c, .done + ld a, D_LEFT + jr .done + +.check_y + ld a, [wTempSpaceYCoord] + ld c, a + ld a, [wYCoord] + cp c + jr z, .arrived + ld a, D_DOWN + jr c, .done + ld a, D_UP + jr .done + +.arrived + xor a +.done + ld [wCurInput], a + ret diff --git a/engine/board/spaces.asm b/engine/board/spaces.asm index efd3cb2d2..332b9fb5b 100755 --- a/engine/board/spaces.asm +++ b/engine/board/spaces.asm @@ -27,12 +27,18 @@ ArriveToRegularSpaceScript: end ArriveToRegularSpace: +; load new space + ld a, [wCurSpaceNextSpace] + ld [wCurSpace], a + call LoadCurSpaceData +; decrease wSpacesLeft and copy to hScriptVar ld hl, wSpacesLeft dec [hl] ld a, [hl] ld [hScriptVar], a +; if landed, clear spaces left sprites and a - jp nz, UpdateSecondarySprites + ret nz ld hl, wDisplaySecondarySprites res SECONDARYSPRITES_SPACES_LEFT_F, [hl] ret diff --git a/engine/items/tmhm.asm b/engine/items/tmhm.asm index 523e3bf53..bb6f2a867 100644 --- a/engine/items/tmhm.asm +++ b/engine/items/tmhm.asm @@ -71,10 +71,6 @@ AskTeachTMHM: ret ChooseMonToLearnTMHM: - ld hl, wStringBuffer2 - ld de, wTMHMMoveNameBackup - ld bc, MOVE_NAME_LENGTH - 1 - call CopyBytes call ClearBGPalettes ChooseMonToLearnTMHM_NoRefresh: farcall LoadPartyMenuGFX @@ -95,10 +91,6 @@ ChooseMonToLearnTMHM_NoRefresh: pop bc ; now contains the former contents of af jr z, .egg push bc - ld hl, wTMHMMoveNameBackup - ld de, wStringBuffer2 - ld bc, MOVE_NAME_LENGTH - 1 - call CopyBytes pop af ; now contains the original contents of af ret diff --git a/engine/overworld/player_movement.asm b/engine/overworld/player_movement.asm index b5b4a3a53..775f18442 100644 --- a/engine/overworld/player_movement.asm +++ b/engine/overworld/player_movement.asm @@ -11,19 +11,25 @@ DoPlayerMovement:: ret .GetDPad: + ldh a, [hCurBoardEvent] + cp BOARDEVENT_HANDLE_BOARD + jr nz, .not_auto_in_board + +; compute direction according to space layout and save to wCurInput + farcall StepTowardsNextSpace + ret + +.not_auto_in_board ldh 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 diff --git a/home/map.asm b/home/map.asm index f508cff0a..174e7d744 100644 --- a/home/map.asm +++ b/home/map.asm @@ -2298,3 +2298,29 @@ LoadMapTileset:: pop bc pop hl ret + +; a: which space to load +LoadTempSpaceData:: + ld de, wTempSpaceData + jr LoadSpaceData + +LoadCurSpaceData:: + ld de, wCurSpaceData + ld a, [wCurSpace] + ; fallthrough + +; de: location where to load +; a: which space to load +LoadSpaceData:: + push de + push af + ld hl, wMapSpacesPointer + ld a, [hli] + ld h, [hl] + ld l, a + ld bc, wCurSpaceDataEnd - wCurSpaceData ; wTempSpaceDataEnd - wTempSpaceData + pop af + call AddNTimes + pop de + ld a, [wMapScriptsBank] + jp FarCopyBytes diff --git a/main.asm b/main.asm index e9b7b3787..2a60cd583 100644 --- a/main.asm +++ b/main.asm @@ -244,6 +244,7 @@ SECTION "Board 1", ROMX INCLUDE "engine/board/menu.asm" INCLUDE "engine/board/spaces.asm" +INCLUDE "engine/board/movement.asm" SECTION "bank20", ROMX diff --git a/ram/wram.asm b/ram/wram.asm index 53e82bcfb..75a49e1b7 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -1669,14 +1669,23 @@ ENDU SECTION "More WRAM 1", WRAMX -wTMHMMoveNameBackup:: ds MOVE_NAME_LENGTH - wStringBuffer1:: ds STRING_BUFFER_LENGTH wStringBuffer2:: ds STRING_BUFFER_LENGTH + +UNION wStringBuffer3:: ds STRING_BUFFER_LENGTH wStringBuffer4:: ds STRING_BUFFER_LENGTH wStringBuffer5:: ds STRING_BUFFER_LENGTH +NEXTU +wTempSpaceData:: +wTempSpaceXCoord:: db +wTempSpaceYCoord:: db +wTempSpaceEffect:: db +wTempSpaceNextSpace:: db +wTempSpaceDataEnd:: +ENDU + wBattleMenuCursorPosition:: wStartMenuLastCursorPosition:: wBoardMenuLastCursorPosition:: @@ -2180,7 +2189,10 @@ ENDU wBattleAction:: db wLinkBattleSentAction:: db + +; wMapStatus ~ wMapStatusEnd is cleared in StartMap wMapStatus:: db + wMapEventStatus:: db wScriptFlags:: @@ -2236,13 +2248,14 @@ wReceiveCallDelay_StartTime:: ds 2 ; hour, min wBugContestMinsRemaining:: db wBugContestSecsRemaining:: db -wMapStatusEnd:: - +; TurnData ~ wTurnDataEnd is cleared at the beginning of BoardMenuScript (i.e. on turn begin) wTurnData:: wDieRoll:: db wSpacesLeft:: db wTurnDataEnd:: +wMapStatusEnd:: + wGameData:: wPlayerData:: wPlayerID:: dw @@ -2497,8 +2510,15 @@ wYCoord:: db wXCoord:: db wScreenSave:: ds SCREEN_META_WIDTH * SCREEN_META_HEIGHT -wCurSpace:: db wCurTurn:: db +wCurSpace:: db + +wCurSpaceData:: +wCurSpaceXCoord:: db +wCurSpaceYCoord:: db +wCurSpaceEffect:: db +wCurSpaceNextSpace:: db +wCurSpaceDataEnd:: wCurMapDataEnd::