set up proper levelscript system

This commit is contained in:
KalaayPT 2025-11-13 19:53:48 +01:00
parent b341c6be8f
commit 7bc432a66c
3 changed files with 133 additions and 0 deletions

View File

@ -4950,4 +4950,92 @@
.short 254, 0
.endm
/*
* This flag is used by ScriptEntry and ScriptEntryEnd to control where
* a user can add ScriptEntry commands (i.e., only at the start of the
* input file). It is NOT meant for direct usage.
*/
.set F_ACCEPT_SCRIPT_ENTRIES, TRUE
.macro ScriptEntry name
.if F_ACCEPT_SCRIPT_ENTRIES == TRUE
.long \name-.-4
.else
.error "cannot specify ScriptEntry after ScriptEntryEnd"
.endif
.endm
.macro ScriptEntryEnd
.set F_ACCEPT_SCRIPT_ENTRIES, FALSE
.short 0xFD13
.endm
.set F_INIT_SCRIPT_FRAME_TABLE_OPENED, FALSE
.set F_INIT_SCRIPT_FRAME_TABLE_CLOSED, FALSE
.macro InitScriptEntry_Fixed type, scriptID
.if F_ACCEPT_SCRIPT_ENTRIES == TRUE
.byte \type
.short \scriptID, 0
.else
.error "cannot specify InitScriptEntry after InitScriptEntryEnd"
.endif
.endm
.macro InitScriptEntry_OnFrameTable checksLabel
.if F_ACCEPT_SCRIPT_ENTRIES == TRUE
.set F_INIT_SCRIPT_FRAME_TABLE_OPENED, TRUE
.byte INIT_SCRIPT_ON_FRAME_TABLE
ScriptEntry \checksLabel
.else
.error "cannot specify InitScriptEntry after InitScriptEntryEnd"
.endif
.endm
.macro InitScriptEntry_OnTransition scriptID
InitScriptEntry_Fixed INIT_SCRIPT_ON_TRANSITION, \scriptID
.endm
.macro InitScriptEntry_OnResume scriptID
InitScriptEntry_Fixed INIT_SCRIPT_ON_RESUME, \scriptID
.endm
.macro InitScriptEntry_OnLoad scriptID
InitScriptEntry_Fixed INIT_SCRIPT_ON_LOAD, \scriptID
.endm
.macro InitScriptEntryEnd
.set F_ACCEPT_SCRIPT_ENTRIES, FALSE
.byte 0
.endm
.macro InitScriptGoToIfEqual var1, var2, scriptID
.if F_INIT_SCRIPT_FRAME_TABLE_OPENED == TRUE
.if F_INIT_SCRIPT_FRAME_TABLE_CLOSED == FALSE
.short \var1, \var2, \scriptID
.else
.error "cannot specify InitScriptGoToIfEqual after InitScriptFrameTableEnd"
.endif
.else
.error "cannot specify InitScriptGoToIfEqual before InitScriptEntry_OnFrameTable"
.endif
.endm
.macro InitScriptFrameTableEnd
.set F_INIT_SCRIPT_FRAME_TABLE_CLOSED, TRUE
.short 0
.endm
.macro InitScriptEnd
.if F_ACCEPT_SCRIPT_ENTRIES == TRUE
.error "cannot specify InitScriptEnd before InitScriptEntryEnd"
.endif
.if F_INIT_SCRIPT_FRAME_TABLE_OPENED == TRUE
.if F_INIT_SCRIPT_FRAME_TABLE_CLOSED == FALSE
.error "must close InitScriptEntry_OnFrameTable with InitScriptFrameTableEnd before InitScriptEnd"
.endif
.endif
.balign 4, 0
.endm
.endif ; ASM_SCRIPT_INC

View File

@ -0,0 +1,44 @@
#ifndef POKEPLATINUM_CONSTANTS_INIT_SCRIPT_TYPE_H
#define POKEPLATINUM_CONSTANTS_INIT_SCRIPT_TYPE_H
/*
Init Script Types
These constants describe types of non-event scripts which are defined for a particular map.
Each map has at most one script of each type, other than ON_FRAME_TABLE.
To see where each script type is run, look for calls to FieldSystem_RunInitScript.
*/
/*
Init Script Type: INIT_SCRIPT_ON_FRAME_TABLE
Before each frame of input processing, a table of conditions for the map is checked.
Runs the first script where its two condition variables are equal.
Therefore, any script invoked this way must at some point make its own condition false.
The first check only occurs after all other init script types have run.
*/
#define INIT_SCRIPT_ON_FRAME_TABLE 1
/*
Init Script Type: INIT_SCRIPT_ON_TRANSITION
Runs upon first entering a map, including when starting a new game or loading a save.
Runs before all other init script types, including ON_FRAME_TABLE.
Primary roles: modify object events, manage persisted map features
*/
#define INIT_SCRIPT_ON_TRANSITION 2
/*
Init Script Type: INIT_SCRIPT_ON_RESUME
Runs after the map has been fully loaded and drawn.
Can run again without leaving the map, e.g., when using a field move or item.
Primary roles: hide the player, modify object events
*/
#define INIT_SCRIPT_ON_RESUME 3
/*
Init Script Type: INIT_SCRIPT_ON_LOAD
Runs after the map layout is loaded (but not drawn yet).
Can run again without leaving the map, e.g., when using a field move or item.
Primary roles: modify warp events, set/unset flags tied to object events
*/
#define INIT_SCRIPT_ON_LOAD 4
#endif // POKEPLATINUM_CONSTANTS_INIT_SCRIPT_TYPE_H

View File

@ -23,6 +23,7 @@
#include "constants/std_script.h"
#include "constants/trainers.h"
#include "constants/vars.h"
#include "constants/init_script_types.h"
#define lt 0
#define eq 1