Multiplayer engine: handle player state [Commit 7] (#40)

This commit is contained in:
xCrystal
2024-03-04 16:13:43 +01:00
parent 340ef4147f
commit b25139d4ca
8 changed files with 55 additions and 7 deletions

View File

@@ -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\<N\>**: 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.

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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::