Define ExecuteScriptCommand return values

This commit is contained in:
Kermalis
2025-12-01 22:48:50 -05:00
parent b00bc93f5b
commit 67e9457ce6
8 changed files with 238 additions and 215 deletions

View File

@@ -9,6 +9,8 @@ void nullsub_118(void);
void sub_809CD68(struct GroundLives_Sub120 *dst);
void sub_809CD8C(struct GroundLives_Sub120 *dst, s32 a1);
s32 sub_809CDB8(struct GroundLives_Sub120 *dst);
// r6 is enum "ESC_RetID" ?
// param_4 is enum "ESC_RetID" ?
u32 sub_809CDC8(struct GroundLives_Sub120 *strPtr, u32 *r6, s8 *direction, s32 *param_4, PixelPos *unused, u32 flags);
s32 DpadToDirection(u16 dpad);

View File

@@ -30,7 +30,7 @@ void sub_809D4B0(void);
void sub_809D508(void);
void InitActionWithParams(Action *action, const CallbackData *callbacks, void *parent, s32 group, s32 sector);
void InitAction2(Action *action);
bool8 sub_809D678(Action *action);
bool8 Action_SavedStateIsNot0(Action *action);
bool8 sub_809D684(Action *action, ScriptInfoSmall *scriptInfo);
void SetPredefinedScript(Action *param_1, s16 index, const ScriptCommand *param_3);
bool8 GetPredefinedScript(Action *param_1, ScriptInfoSmall *script, s32 _index);
@@ -42,6 +42,7 @@ bool8 GroundScript_Cancel(Action *r0);
bool8 GroundScriptNotify(Action *param_1, s32 param_2);
void GroundScriptLockJumpZero(s16 index);
void GroundScriptLock(s16 index, s32 r1);
// Return value is enum "ESC_RetID"
s16 HandleAction(Action *action, const DebugLocation *debug);
void GroundScript_Unlock(void);

View File

@@ -5,6 +5,27 @@
#include "constants/script_cmd.h"
#include "structs/str_position.h"
enum ESC_RetID
{
// Indicates a RET on script engine level, HandleAction copies action->scriptData2 onto action->scriptData, and reinitializes scriptData2.
// If there is no active scriptData2 it clears and reinits scriptData.
// Ultimately returns ESC_RET_03 to the script engine caller.
// Caveat: If the scripting engine is in state 0, HandleAction will immediately return ESC_RET_00 without performing any work.
ESC_RET_00,
// A terminal state (script success? error?), no further scripting progress will happen.
// This code is always returned to the caller from now on.
ESC_RET_01,
// Gives control back to the HandleAction function (entry point into the scripting engine state machine).
// This is the only return value that does not return to the script engine caller.
// Async commands?
ESC_RET_02,
// Returns to the caller, but will give control back to ExecuteScriptCommand when reentering the script ("script not finished").
ESC_RET_03,
// Some kind of fatal error state, no further scripting progress will happen.
// This code is always returned to the caller from now on.
ESC_RET_04,
};
// size: 0x10
typedef struct ScriptCommand
{
@@ -44,7 +65,7 @@ typedef struct ActionUnkIds {
typedef struct ScriptData
{
/* 0x00 */ s16 state;
/* 0x02 */ s16 savedState;
/* 0x02 */ s16 savedState; // See enum "ESC_RetID"
/* 0x04 */ ScriptInfo script;
/* 0x10 */ ScriptInfo savedScript;
/* 0x1C */ const ScriptCommand *curPtr;

View File

@@ -739,25 +739,25 @@ void GroundEffect_Action(void)
{
GroundEffect *objectPtr;
s32 i;
s32 ret;
for (objectPtr = &gGroundEffects[0], i = 0; i < NUM_GROUND_EFFECTS; i = (s16)(i + 1), objectPtr++)
{
for (objectPtr = &gGroundEffects[0], i = 0; i < NUM_GROUND_EFFECTS; i = (s16)(i + 1), objectPtr++) {
if (objectPtr->kind != -1) {
ret = HandleAction(&objectPtr->action, DEBUG_LOC_PTR(gUnknown_81185D8, 0x560, "GroundEffect_Action"));
switch(ret)
{
case 4:
s32 ret = HandleAction(&objectPtr->action, DEBUG_LOC_PTR(gUnknown_81185D8, 1376, "GroundEffect_Action"));
switch (ret) {
case ESC_RET_04: {
GroundEffect_Delete(i);
continue;
case 0:
ExecutePredefinedScript(&objectPtr->action, NULL, 1, DEBUG_LOC_PTR(gUnknown_81185D8, 0x56A, "GroundEffect_Action"));
}
case ESC_RET_00: {
ExecutePredefinedScript(&objectPtr->action, NULL, 1, DEBUG_LOC_PTR(gUnknown_81185D8, 1386, "GroundEffect_Action"));
break;
}
}
if (objectPtr->directionRelated) {
objectPtr->directionRelated = FALSE;
sub_80A6EFC(&objectPtr->unk144,objectPtr->unk13E & 0x1f00,(s8)objectPtr->unk13E);
sub_80A6EFC(&objectPtr->unk144, objectPtr->unk13E & 0x1F00, (s8)objectPtr->unk13E);
}
}
}

View File

@@ -841,7 +841,7 @@ static s32 GroundLives_Add(s32 id_, const GroundLivesData *ptr, s32 group_, s32
u16 *ptrToUnk24;
s8 *ptrToStoredDir;
if (livesPtr->action.scriptData2.savedState != 0) {
if (livesPtr->action.scriptData2.savedState != ESC_RET_00) {
bakUnk24 = livesPtr->action.scriptData2.unk24;
bakStoredDir = livesPtr->action.scriptData2.storedDir;
@@ -1023,7 +1023,7 @@ UNUSED static bool8 sub_80A88A0(s32 id_)
struct GroundLive *livesPtr = &gGroundLives->array[id];
if (livesPtr->unk2 != -1) {
return sub_809D678(&livesPtr->action);
return Action_SavedStateIsNot0(&livesPtr->action);
}
return FALSE;
@@ -2699,12 +2699,14 @@ void GroundLives_Action(void)
for (livesPtr = &gGroundLives->array[0], i = 0; i < UNK_3001B84_ARR_COUNT; i = (s16)(i + 1), livesPtr++) {
if (livesPtr->unk2 != -1) {
s32 actionResult = (s16) HandleAction(&livesPtr->action, DEBUG_LOC_PTR("../ground/ground_lives.c", 4514, "GroundLives_Action"));
s32 actionResult = (s16)HandleAction(&livesPtr->action, DEBUG_LOC_PTR("../ground/ground_lives.c", 4514, "GroundLives_Action"));
switch (actionResult) {
case 4:
case ESC_RET_04: {
GroundLives_Delete(i);
continue;
case 0:
}
case ESC_RET_00: {
if (livesPtr->flags & 0x800) {
PixelPos var_44;
u32 var_4C = actionResult;
@@ -2772,6 +2774,7 @@ void GroundLives_Action(void)
ExecutePredefinedScript(&livesPtr->action, NULL, 1, DEBUG_LOC_PTR("../ground/ground_lives.c", 4622, "GroundLives_Action"));
}
break;
}
}
if (livesPtr->directionRelated) {
livesPtr->directionRelated = FALSE;

View File

@@ -345,7 +345,7 @@ void GroundMap_ExecuteEnter(s16 param_1)
UNUSED static bool8 sub_80A4D14(void)
{
return sub_809D678(&gGroundMapAction->action);
return Action_SavedStateIsNot0(&gGroundMapAction->action);
}
bool8 GroundMapNotifyAll(s16 param_1)
@@ -1373,7 +1373,7 @@ void sub_80A59A0(s32 param_1, PixelPos *param_2, u16 param_3)
void GroundMap_Action(void)
{
nullsub_123();
HandleAction(&gGroundMapAction->action, DEBUG_LOC_PTR("../ground/ground_map.c", 0x57F, "GroundMap_Action"));
HandleAction(&gGroundMapAction->action, DEBUG_LOC_PTR("../ground/ground_map.c", 1407, "GroundMap_Action"));
}
void sub_80A59DC(void)

View File

@@ -926,25 +926,25 @@ void GroundObject_Action(void)
{
GroundObject *objectPtr;
s32 i;
s32 ret;
for (objectPtr = &gGroundObjects[0], i = 0; i < NUM_GROUND_OBJECTS; i = (s16)(i + 1), objectPtr++)
{
for (objectPtr = &gGroundObjects[0], i = 0; i < NUM_GROUND_OBJECTS; i = (s16)(i + 1), objectPtr++) {
if (objectPtr->kind != -1) {
ret = HandleAction(&objectPtr->action, DEBUG_LOC_PTR(gGroundObjectFileName, 0x60D, "GroundObject_Action"));
switch(ret)
{
case 4:
s32 ret = HandleAction(&objectPtr->action, DEBUG_LOC_PTR(gGroundObjectFileName, 1549, "GroundObject_Action"));
switch (ret) {
case ESC_RET_04: {
GroundObject_Delete(i);
continue;
case 0:
ExecutePredefinedScript(&objectPtr->action, NULL, 1, DEBUG_LOC_PTR(gGroundObjectFileName, 0x617, "GroundObject_Action"));
}
case ESC_RET_00: {
ExecutePredefinedScript(&objectPtr->action, NULL, 1, DEBUG_LOC_PTR(gGroundObjectFileName, 1559, "GroundObject_Action"));
break;
}
}
if (objectPtr->directionRelated) {
objectPtr->directionRelated = FALSE;
sub_80A6EFC(&objectPtr->unk144,objectPtr->unk13E & 0x1f00,(s8)objectPtr->unk13E);
sub_80A6EFC(&objectPtr->unk144, objectPtr->unk13E & 0x1F00, (s8)objectPtr->unk13E);
}
}
}
@@ -964,7 +964,7 @@ void sub_80ACAD4(void)
s32 num = objectPtr->unk134.x + objectPtr->unk134.y;
if ((sub_80A66D4(&objectPtr->unk144))) {
objectPtr->directionRelated = 0;
sub_80A6EFC(&objectPtr->unk144,objectPtr->unk13E & 0x1f00,(s8)objectPtr->unk13E);
sub_80A6EFC(&objectPtr->unk144,objectPtr->unk13E & 0x1F00,(s8)objectPtr->unk13E);
}
if (objectPtr->unk140 != 0) {
sub_80A7040(&objectPtr->unk144,objectPtr->unk140,objectPtr->direction,0);

File diff suppressed because it is too large Load Diff