From b25139d4ca15594a5dfcf3f7c9d83591bd035cf1 Mon Sep 17 00:00:00 2001 From: xCrystal Date: Mon, 4 Mar 2024 16:13:43 +0100 Subject: [PATCH] Multiplayer engine: handle player state [Commit 7] (#40) --- docs/develop/ram_addresses.md | 4 ++-- engine/board/menu.asm | 2 ++ engine/board/next_player_turn.asm | 21 +++++++++++++++++++++ engine/board/spaces.asm | 2 ++ engine/overworld/events.asm | 3 +++ engine/overworld/player_object.asm | 9 ++++++++- engine/overworld/spawn_points.asm | 7 +++++++ ram/wram.asm | 14 ++++++++++---- 8 files changed, 55 insertions(+), 7 deletions(-) diff --git a/docs/develop/ram_addresses.md b/docs/develop/ram_addresses.md index 1f2ab20e7..031e636cc 100755 --- a/docs/develop/ram_addresses.md +++ b/docs/develop/ram_addresses.md @@ -2,7 +2,7 @@ - **hCurBoardEvent**: holds a *BOARDEVENT_* value. -- **wTurnData** ~ **wTurnDataEnd**: turn-scoped, not preserved on save, and cleared at the beginning of BoardMenuScript (i.e. on turn begin). It's part of *wMapStatus* ~ *wMapStatusEnd*, so it's also cleared by *StartMap*. Includes: +- **wTurnData** ~ **wTurnDataEnd**: not preserved on save, and turn-scoped; cleared at the beginning of BoardMenuScript (i.e. on turn begin). It's part of *wMapStatus* ~ *wMapStatusEnd*, so it's also cleared by *StartMap*. Includes: - **wDieRoll** - **wSpacesLeft** @@ -18,7 +18,7 @@ - **wCurSpaceNextSpace** for non-branch spaces - **wCurOverworldMiscPal** -- Addresses within *wPlayerData* ~ *wPlayerDataEnd*: game-scoped (change between levels or on level start/end, but now within), preserved on save. Includes: +- Addresses within *wPlayerData* ~ *wPlayerDataEnd*: game-scoped (change between levels or on level start/end, but not within), preserved on save. Includes: - **wUnlockedLevels**: flag array that tracks progression regarding which levels have been unlocked. - **wClearedLevelsStage\**: flag array that tracks progression regarding which levels have been cleared. Each level can have up to four stages (clearable endings). - **wUnlockedTechniques**: flag array that tracks progression regarding which techniques have been unlocked. diff --git a/engine/board/menu.asm b/engine/board/menu.asm index 14f66d515..c8683a61a 100755 --- a/engine/board/menu.asm +++ b/engine/board/menu.asm @@ -126,6 +126,8 @@ BoardMenuScript:: ld [wPlayer1XCoord], a ld a, [wPlayerDirection] ld [wBeforeViewMapDirection], a + ld a, [wPlayerState] + ld [wPlayer1State], a xor a ld [wViewMapModeDisplacementY], a ld [wViewMapModeDisplacementX], a diff --git a/engine/board/next_player_turn.asm b/engine/board/next_player_turn.asm index 39dae24bb..dd1362c9d 100755 --- a/engine/board/next_player_turn.asm +++ b/engine/board/next_player_turn.asm @@ -4,6 +4,27 @@ GotoNextPlayerScript:: end .RotateTurnPlayer: +; backup state of player being rotated out + ld a, [wCurTurnPlayer] + ld hl, wPlayer1Location + ld bc, wPlayer2Location - wPlayer1Location + call AddNTimes + ld a, [wMapGroup] + ld [hli], a ; wPlayer*MapGroup + ld a, [wMapNumber] + ld [hli], a ; wPlayer*MapNumber + ld a, [wYCoord] + ld [hli], a ; wPlayer*YCoord + ld a, [wXCoord] + ld [hl], a ; wPlayer*XCoord + ld a, [wCurTurnPlayer] + ld hl, wPlayer1State + ld c, a + ld b, 0 + add hl, bc + ld a, [wPlayerState] + ld [hl], a ; wPlayer*State +; rotate turn player ld hl, wNumLevelPlayers ld a, [wCurTurnPlayer] inc a diff --git a/engine/board/spaces.asm b/engine/board/spaces.asm index 01ceda228..a61db405a 100755 --- a/engine/board/spaces.asm +++ b/engine/board/spaces.asm @@ -302,6 +302,8 @@ PromptPlayerToChooseBranchDirection: ld [wPlayer1XCoord], a ld a, [wPlayerDirection] ld [wBeforeViewMapDirection], a + ld a, [wPlayerState] + ld [wPlayer1State], a xor a ld [wViewMapModeDisplacementY], a ld [wViewMapModeDisplacementX], a diff --git a/engine/overworld/events.asm b/engine/overworld/events.asm index 8bade92ca..e83b2466a 100644 --- a/engine/overworld/events.asm +++ b/engine/overworld/events.asm @@ -190,6 +190,9 @@ StartMap: ld [hli], a ; wPrevWarp ld [hli], a ; wPrevMapGroup ld [hl], a ; wPrevMapNumber + ; wPlayerState is later set by RefreshMapSprites->CheckUpdatePlayerSprite in the map setup script. + ; however, space tiles are neutral to both PLAYER_NORMAL and PLAYER_SURF, so, given that the + ; default spawn point in a given level is a (grey) space, what is set here will be carried over. ld [wPlayerState], a ; PLAYER_NORMAL ld [wCurOverworldMiscPal], a ; OW_MISC_BOARD_MENU_ITEMS | BOARDMENUITEM_DIE ld hl, wStatusFlags diff --git a/engine/overworld/player_object.asm b/engine/overworld/player_object.asm index ddf463a04..353e7684c 100644 --- a/engine/overworld/player_object.asm +++ b/engine/overworld/player_object.asm @@ -1028,7 +1028,14 @@ MockPlayerObject: ; adjust sprite id and palette number .loop - ld a, [wPlayerState] + ld a, [wMockingWhichPlayer] + ld de, wPlayer1State + add e + ld e, a + ld a, d + adc 0 + ld d, a + ld a, [de] cp [hl] inc hl jr nz, .next diff --git a/engine/overworld/spawn_points.asm b/engine/overworld/spawn_points.asm index d2a6e24c5..09b98c9e1 100644 --- a/engine/overworld/spawn_points.asm +++ b/engine/overworld/spawn_points.asm @@ -40,6 +40,13 @@ EnterMapSpawnPoint: ld [wYCoord], a ld a, [hl] ld [wXCoord], a + ld a, [wCurTurnPlayer] + ld hl, wPlayer1State + ld c, a + ld b, 0 + add hl, bc + ld a, [hl] + ld [wPlayerState], a .spawn_n_a pop de diff --git a/ram/wram.asm b/ram/wram.asm index f79746b59..55b97212f 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -2572,15 +2572,14 @@ wCurTurnPlayer:: db ; 0-3 wCurSpaceStruct:: space_struct wCurSpace wCurSpaceStructEnd:: -wCurOverworldMiscPal:: db - -; in multiplayer only, original location of each player +; used by MockPlayerObject and RepositionMockedPlayerObject +; original location (map and coords) of each player wPlayer1Location:: player_location wPlayer1 wPlayer2Location:: player_location wPlayer2 wPlayer3Location:: player_location wPlayer3 wPlayer4Location:: player_location wPlayer4 -; used in MockPlayerObject_* and RepositionMockedPlayerObjects_Connection +; used in MockPlayerObject and RepositionMockedPlayerObject ; player 1: used during a View Map mode session or in multiplayer ; player 2-4: used in multiplayer wPlayer1MockYCoord:: db @@ -2592,6 +2591,13 @@ wPlayer3MockXCoord:: db wPlayer4MockYCoord:: db wPlayer4MockXCoord:: db +wPlayer1State:: db +wPlayer2State:: db +wPlayer3State:: db +wPlayer4State:: db + +wCurOverworldMiscPal:: db + wCurMapDataEnd::