Rename wCurSpaceData and wTempSpaceData to *SpaceStruct and create space_struct macro

This commit is contained in:
xCrystal 2023-10-20 20:16:10 +02:00
parent fc7b65347f
commit b0e2e7aef3
4 changed files with 18 additions and 19 deletions

View File

@ -348,20 +348,20 @@ $~~~~$<c>then always returns PLAYERMOVEMENT_FINISH but often is overwritten by c
- Addresses within *wCurMapData* ~ *wCurMapDataEnd*: preserved on save. - Addresses within *wCurMapData* ~ *wCurMapDataEnd*: preserved on save.
- **wCurTurn** - **wCurTurn**
- **wCurSpace** - **wCurSpace**
- **wCurSpaceData**: - **wCurSpaceStruct**:
- **wCurSpaceXCoord** - **wCurSpaceXCoord**
- **wCurSpaceYCoord** - **wCurSpaceYCoord**
- **wCurSpaceEffect** - **wCurSpaceEffect**
- **wCurSpaceNextSpace**. - **wCurSpaceNextSpace**.
- **wTempSpaceData**: shares memory region with string buffers from *wStringBuffer3* onwards. Temporary scope. Same structure as *wCurSpaceData* - **wTempSpaceStruct**: shares memory region with string buffers from *wStringBuffer3* onwards. Temporary scope. Same structure as *wCurSpaceStruct*
### Workflow ### Workflow
1) ``OverworldLoop`` is called from ``GameMenu_WorldMap`` with either ``hMapEntryMethod`` = ``MAPSETUP_ENTERLEVEL`` or ``hMapEntryMethod`` = ``MAPSETUP_CONTINUE``. 1) ``OverworldLoop`` is called from ``GameMenu_WorldMap`` with either ``hMapEntryMethod`` = ``MAPSETUP_ENTERLEVEL`` or ``hMapEntryMethod`` = ``MAPSETUP_CONTINUE``.
2) ``StartMap`` resets ``wCurTurn`` and ``wCurSpace`` if ``MAPSETUP_ENTERLEVEL``. ``StartMap`` sets ``hCurBoardEvent`` to ``BOARDEVENT_DISPLAY_MENU``. ``wScriptFlags2`` is cleared. ``wMapStatus`` is set to ``MAPSTATUS_HANDLE`` causing ``HandleMap`` to be called. 2) ``StartMap`` resets ``wCurTurn`` and ``wCurSpace`` if ``MAPSETUP_ENTERLEVEL``. ``StartMap`` sets ``hCurBoardEvent`` to ``BOARDEVENT_DISPLAY_MENU``. ``wScriptFlags2`` is cleared. ``wMapStatus`` is set to ``MAPSTATUS_HANDLE`` causing ``HandleMap`` to be called.
3) ``MapEvents`` (from ``HandleMap``) calls ``PlayerEvents``. ``CheckBoardEvent`` queues ``BoardMenuScript`` which is executed by ``ScriptEvents``. 3) ``MapEvents`` (from ``HandleMap``) calls ``PlayerEvents``. ``CheckBoardEvent`` queues ``BoardMenuScript`` which is executed by ``ScriptEvents``.
4) ``BoardMenuScript``.``Upkeep`` saves the game, clears ``wTurnData[]``, increases ``wCurTurn``, and loads current space to ``wCurSpaceData[]``. 4) ``BoardMenuScript``.``Upkeep`` saves the game, clears ``wTurnData[]``, increases ``wCurTurn``, and loads current space to ``wCurSpaceStruct[]``.
- If player exits, the ``exitoverworld`` script sets ``wMapStatus`` to ``MAPSTATUS_DONE``. This causes ``OverworldLoop`` to return back to the game menu. **Exit this workflow**. - If player exits, the ``exitoverworld`` script sets ``wMapStatus`` to ``MAPSTATUS_DONE``. This causes ``OverworldLoop`` to return back to the game menu. **Exit this workflow**.
5) Player rolls die and the animation plays. After the animation, ``wDisplaySecondarySprites``.``SECONDARYSPRITES_SPACES_LEFT_F`` is set and ``hCurBoardEvent`` is set to ``BOARDEVENT_HANDLE_BOARD``. At the end of this ``HandleMap`` iteration, ``CheckPlayerState`` sets ``wMapEventStatus`` to ``MAPEVENTS_ON`` (``wScriptFlags2`` is not touched so it remains cleared). 5) Player rolls die and the animation plays. After the animation, ``wDisplaySecondarySprites``.``SECONDARYSPRITES_SPACES_LEFT_F`` is set and ``hCurBoardEvent`` is set to ``BOARDEVENT_HANDLE_BOARD``. At the end of this ``HandleMap`` iteration, ``CheckPlayerState`` sets ``wMapEventStatus`` to ``MAPEVENTS_ON`` (``wScriptFlags2`` is not touched so it remains cleared).
6) In the next ``HandleMap`` iteration, ``CheckBoardEvent`` from ``PlayerEvents`` jumps to ``.board`` and then to ``.no_space_effect`` due to ``wScriptFlags2[4]`` not being set. 6) In the next ``HandleMap`` iteration, ``CheckBoardEvent`` from ``PlayerEvents`` jumps to ``.board`` and then to ``.no_space_effect`` due to ``wScriptFlags2[4]`` not being set.
@ -371,7 +371,7 @@ $~~~~$<c>then always returns PLAYERMOVEMENT_FINISH but often is overwritten by c
10) In the next ``HandleMap`` iteration, ``CheckBoardEvent.board`` is called with ``wScriptFlags2[4]`` set. 10) In the next ``HandleMap`` iteration, ``CheckBoardEvent.board`` is called with ``wScriptFlags2[4]`` set.
- If player is not above a tile (``wPlayerTile``) with a space collision: ``wScriptFlags2[4]`` is reset. **Go back to 7)**. - If player is not above a tile (``wPlayerTile``) with a space collision: ``wScriptFlags2[4]`` is reset. **Go back to 7)**.
- If player is above a tile, the corresponding space script is queued to be executed by ``ScriptEvents`` in the current ``HandleMap`` iteration. ``wScriptFlags2[4]`` is reset. **Continue to 11)**. - If player is above a tile, the corresponding space script is queued to be executed by ``ScriptEvents`` in the current ``HandleMap`` iteration. ``wScriptFlags2[4]`` is reset. **Continue to 11)**.
11) The space script loads the value of ``wCurSpaceNextSpace`` into ``wCurSpace``, loads the new space data to ``wCurSpaceData[]``, and decreases ``wSpacesLeft``. 11) The space script loads the value of ``wCurSpaceNextSpace`` into ``wCurSpace``, loads the new space data to ``wCurSpaceStruct[]``, and decreases ``wSpacesLeft``.
- If ``wSpacesLeft`` is non-0, **go back to 6)**. - If ``wSpacesLeft`` is non-0, **go back to 6)**.
12) ``hCurBoardEvent`` is set to ``BOARDEVENT_END_TURN``. ``CheckBoardEvent`` does nothing in this state. In the first subsequent ``HandleMap`` iteration where no other kind of event triggers causing ``PlayerEvents`` to return early, ``hCurBoardEvent`` is set to ``BOARDEVENT_DISPLAY_MENU``. 12) ``hCurBoardEvent`` is set to ``BOARDEVENT_END_TURN``. ``CheckBoardEvent`` does nothing in this state. In the first subsequent ``HandleMap`` iteration where no other kind of event triggers causing ``PlayerEvents`` to return early, ``hCurBoardEvent`` is set to ``BOARDEVENT_DISPLAY_MENU``.
13) **Go back to 3)** 13) **Go back to 3)**

View File

@ -2301,11 +2301,11 @@ LoadMapTileset::
; a: which space to load ; a: which space to load
LoadTempSpaceData:: LoadTempSpaceData::
ld de, wTempSpaceData ld de, wTempSpaceStruct
jr LoadSpaceData jr LoadSpaceData
LoadCurSpaceData:: LoadCurSpaceData::
ld de, wCurSpaceData ld de, wCurSpaceStruct
ld a, [wCurSpace] ld a, [wCurSpace]
; fallthrough ; fallthrough
@ -2318,7 +2318,7 @@ LoadSpaceData::
ld a, [hli] ld a, [hli]
ld h, [hl] ld h, [hl]
ld l, a ld l, a
ld bc, wCurSpaceDataEnd - wCurSpaceData ; wTempSpaceDataEnd - wTempSpaceData ld bc, wCurSpaceStructEnd - wCurSpaceStruct ; wTempSpaceStructEnd - wTempSpaceStruct
pop af pop af
call AddNTimes call AddNTimes
pop de pop de

View File

@ -406,3 +406,10 @@ MACRO battle_bg_effect
\1BattleTurn:: db \1BattleTurn:: db
\1Param:: db \1Param:: db
ENDM ENDM
MACRO space_struct
\1XCoord:: db
\1YCoord:: db
\1Effect:: db
\1NextSpace:: db
ENDM

View File

@ -1678,12 +1678,8 @@ wStringBuffer4:: ds STRING_BUFFER_LENGTH
wStringBuffer5:: ds STRING_BUFFER_LENGTH wStringBuffer5:: ds STRING_BUFFER_LENGTH
NEXTU NEXTU
wTempSpaceData:: wTempSpaceStruct:: space_struct wTempSpace
wTempSpaceXCoord:: db wTempSpaceStructEnd::
wTempSpaceYCoord:: db
wTempSpaceEffect:: db
wTempSpaceNextSpace:: db
wTempSpaceDataEnd::
ENDU ENDU
wBattleMenuCursorPosition:: wBattleMenuCursorPosition::
@ -2513,12 +2509,8 @@ wScreenSave:: ds SCREEN_META_WIDTH * SCREEN_META_HEIGHT
wCurTurn:: db wCurTurn:: db
wCurSpace:: db wCurSpace:: db
wCurSpaceData:: wCurSpaceStruct:: space_struct wCurSpace
wCurSpaceXCoord:: db wCurSpaceStructEnd::
wCurSpaceYCoord:: db
wCurSpaceEffect:: db
wCurSpaceNextSpace:: db
wCurSpaceDataEnd::
wCurMapDataEnd:: wCurMapDataEnd::