diff --git a/include/ground_lives_helper.h b/include/ground_lives_helper.h index 5499af5a3..4bd68d041 100644 --- a/include/ground_lives_helper.h +++ b/include/ground_lives_helper.h @@ -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); diff --git a/include/ground_script.h b/include/ground_script.h index 29cb8461d..69abd5a22 100644 --- a/include/ground_script.h +++ b/include/ground_script.h @@ -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); diff --git a/include/structs/str_ground_script.h b/include/structs/str_ground_script.h index 359d11bee..defe50bb5 100644 --- a/include/structs/str_ground_script.h +++ b/include/structs/str_ground_script.h @@ -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; diff --git a/src/ground_effect.c b/src/ground_effect.c index 6956f8c0d..a83f80da7 100644 --- a/src/ground_effect.c +++ b/src/ground_effect.c @@ -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); } } } diff --git a/src/ground_lives.c b/src/ground_lives.c index 2643e0e57..07eb72c6f 100644 --- a/src/ground_lives.c +++ b/src/ground_lives.c @@ -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; diff --git a/src/ground_map.c b/src/ground_map.c index ea68be8ca..b462cf33f 100644 --- a/src/ground_map.c +++ b/src/ground_map.c @@ -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) diff --git a/src/ground_object.c b/src/ground_object.c index e4c3c4f4f..cbbd5e53f 100644 --- a/src/ground_object.c +++ b/src/ground_object.c @@ -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); diff --git a/src/ground_script.c b/src/ground_script.c index 250cca8cc..04ad4c8be 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -173,7 +173,7 @@ static void InitScriptData(ScriptData *a0) s32 i; a0->state = -1; - a0->savedState = 0; + a0->savedState = ESC_RET_00; a0->script.ptr2 = 0; a0->script.ptr = 0; a0->savedScript.ptr2 = 0; @@ -235,49 +235,49 @@ void InitAction2(Action *action) InitAction(action); } -UNUSED static s16 sub_809D654(Action *action) +UNUSED static s16 Action_GetSavedState(Action *action) { return action->scriptData.savedState; } UNUSED static s16 sub_809D65C(Action *action) { - if(action->scriptData.savedState != 0) + if (action->scriptData.savedState != ESC_RET_00) return action->scriptData.state; else return -1; } -bool8 sub_809D678(Action *action) +bool8 Action_SavedStateIsNot0(Action *action) { - return action->scriptData.savedState == 0 ? FALSE : TRUE; + return action->scriptData.savedState == ESC_RET_00 ? FALSE : TRUE; } bool8 sub_809D684(Action *action, ScriptInfoSmall *scriptInfo) { - if(action->scriptData.savedState != 0) - { - if(action->scriptData.savedScript.ptr != 0) - { - if(action->scriptData.savedScript.ptr2 == scriptInfo->ptr) return 1; + if (action->scriptData.savedState != ESC_RET_00) { + if(action->scriptData.savedScript.ptr != NULL) { + if (action->scriptData.savedScript.ptr2 == scriptInfo->ptr) + return TRUE; } - else - { - if(action->scriptData.script.ptr2 == scriptInfo->ptr) return 1; + else { + if (action->scriptData.script.ptr2 == scriptInfo->ptr) + return TRUE; } } - if(action->scriptData2.savedState != 0) - { - if(action->scriptData2.savedScript.ptr != 0) - { - if(action->scriptData2.savedScript.ptr2 == scriptInfo->ptr) return 1; + + if (action->scriptData2.savedState != ESC_RET_00) { + if (action->scriptData2.savedScript.ptr != NULL) { + if (action->scriptData2.savedScript.ptr2 == scriptInfo->ptr) + return TRUE; } - else - { - if(action->scriptData2.script.ptr2 == scriptInfo->ptr) return 1; + else { + if (action->scriptData2.script.ptr2 == scriptInfo->ptr) + return TRUE; } } - return 0; + + return FALSE; } void SetPredefinedScript(Action *param_1, s16 index, const ScriptCommand *param_3) @@ -324,7 +324,7 @@ static bool8 ActionResetScriptDataForDeletion(Action *param_1, const DebugLocati { InitScriptData(¶m_1->scriptData); InitScriptData(¶m_1->scriptData2); - param_1->scriptData.savedState = 4; + param_1->scriptData.savedState = ESC_RET_04; return TRUE; } @@ -375,7 +375,7 @@ bool8 GroundScript_ExecutePP(Action *action, ActionUnkIds *param_2, ScriptInfoSm sub_809D520(&action->unkC); } action->scriptData.state = param_3->state; - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; action->scriptData.script.group = param_3->group; action->scriptData.script.sector = param_3->sector; action->scriptData.script.ptr = param_3->ptr; @@ -409,7 +409,7 @@ static bool8 GroundScriptCheckLockCondition(Action *param_1, s16 param_2) } else { param_1->scriptData.unk22 = param_2_s32; - param_1->scriptData.savedState = 2; + param_1->scriptData.savedState = ESC_RET_02; gAnyScriptLocked = 1; return TRUE; } @@ -484,7 +484,7 @@ static bool8 GroundScriptLockCond(Action *param_1, s16 index, s32 param_3) gScriptLocks[index_s32] = 1; gScriptLockConds[index_s32] = 1; } - param_1->scriptData.savedState = 2; + param_1->scriptData.savedState = ESC_RET_02; gAnyScriptLocked = 1; return TRUE; } @@ -493,11 +493,11 @@ s16 HandleAction(Action *action, const DebugLocation *debug) { ScriptCommand cmd; - if (action->scriptData.savedState) { + if (action->scriptData.savedState != ESC_RET_00) { bool8 loopContinue = TRUE; while (loopContinue) { switch (action->scriptData.savedState) { - case 2: { + case ESC_RET_02: { switch (action->scriptData.curScriptOp) { // handled cases (all hex) // 03, 04, 05, 06, 07, 22..28, 2c, 30..38, 39, 3a, 3b, 3c, 3d, 3e, 3f, @@ -527,7 +527,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) loopContinue = FALSE; } else { - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; } break; } @@ -535,7 +535,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) if (action->callbacks->func4C_spriteRelatedCheck(action->parentObject)) loopContinue = FALSE; else - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; break; } @@ -543,7 +543,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) if (action->callbacks->func50_spriteRelated(action->parentObject)) loopContinue = FALSE; else - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; break; } @@ -558,7 +558,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) if (sub_8099B94()) loopContinue = FALSE; else - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; break; } @@ -568,10 +568,10 @@ s16 HandleAction(Action *action, const DebugLocation *debug) if (action->scriptData.unk2C++ < 180 * 60) loopContinue = FALSE; else - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; } else { - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; } break; } @@ -582,10 +582,10 @@ s16 HandleAction(Action *action, const DebugLocation *debug) if (action->scriptData.unk2C++ < 60 * 60) loopContinue = FALSE; else - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; } else { - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; } break; } @@ -603,12 +603,12 @@ s16 HandleAction(Action *action, const DebugLocation *debug) ClampPixelPos(&pos2, action->scriptData.unk30); if (pos2.x == 0 && pos2.y == 0) { - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; break; } if (action->callbacks->moveRelative(action->parentObject, &pos2) & 9) { - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; break; } @@ -620,7 +620,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) loopContinue = FALSE; } else { - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; } } else { @@ -645,7 +645,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) pos2.y = action->scriptData.pos2.y - pos.y; ClampPixelPos(&pos2, action->scriptData.unk30); if (pos2.x == 0 && pos2.y == 0) { - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; break; } res = action->callbacks->moveRelative(action->parentObject, &pos2); @@ -655,7 +655,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) action->scriptData.storedDir = dirS8; action->callbacks->setDirection(action->parentObject, dir); if (res & 9) { - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; break; } action->callbacks->setEventIndex(action->parentObject, 0x1000); @@ -666,7 +666,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) loopContinue = FALSE; } else { - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; } } else { @@ -696,7 +696,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) loopContinue = FALSE; } else { - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; } break; } @@ -734,7 +734,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) loopContinue = FALSE; } else { - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; } break; } @@ -745,7 +745,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) action->callbacks->getPosHeightAndUnk(action->parentObject, &height, &unk); delta = action->scriptData.unk48 - height; if (delta == 0) { - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; break; } // oh wow, cmn instruction @@ -763,7 +763,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) pos = SetVecFromDirectionSpeed(dir, action->scriptData.unk30); if (action->callbacks->moveRelative(action->parentObject, &pos) & 9) { - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; break; } action->callbacks->setEventIndex(action->parentObject, 0x1000); @@ -773,7 +773,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) loopContinue = FALSE; } else { - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; } break; } @@ -841,7 +841,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) } } if (tmp2 == -1 || tmp2 == dir) { - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; break; } @@ -864,7 +864,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) if (sub_809D234()) loopContinue = FALSE; else - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; break; } @@ -875,7 +875,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) } else { action->scriptData.script.ptr = ResolveJump(action, gUnlockBranchLabels[action->scriptData.branchDiscriminant]); - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; } break; } @@ -893,7 +893,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) loopContinue = FALSE; } else { - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; sub_80A87AC(0, 0); } break; @@ -906,7 +906,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) loopContinue = FALSE; } else { - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; sub_80A87AC(0, 0); } break; @@ -919,7 +919,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) loopContinue = FALSE; } else { - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; action->scriptData.script.ptr = ResolveJump(action, tmp); } break; @@ -931,7 +931,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) } else { action->scriptData.script.ptr = ResolveJump(action, val); - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; sub_80A87AC(0, 0); } break; @@ -947,7 +947,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) GroundMainGroundRequest((s16)FriendAreaIdToMapId((u8)val), 0, cmd.argShort); } action->scriptData.script.ptr = ResolveJump(action, val); - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; sub_80A87AC(0, 0); break; } @@ -977,7 +977,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) sub_8098DCC(cmd.argShort); action->scriptData.script.ptr = ResolveJump(action, 0); sub_80A87AC(0, 0); - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; break; } SetScriptVarValue(NULL, 19, 19); @@ -1108,7 +1108,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) } if (action->scriptData.branchDiscriminant == 3) { cmd = *action->scriptData.curPtr; - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; sub_80999FC(cmd.argShort); GroundMap_ExecuteEvent(EVENT_RESCUE, FALSE); if (action->unk8.unk0 == 0) continue; @@ -1130,7 +1130,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) sub_8099220(0, 0); SetScriptVarValue(NULL, 19, -1); action->scriptData.script.ptr = ResolveJump(action, -1); - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; break; } case CMD_BYTE_3D: { @@ -1151,7 +1151,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) } } action->scriptData.script.ptr = ResolveJump(action, val); - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; sub_80A87AC(0, 0); break; } @@ -1165,7 +1165,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) SetRescueTeamName(sPokeNameBuffer); } action->scriptData.script.ptr = ResolveJump(action, val); - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; sub_80A87AC(0, 0); break; } @@ -1193,7 +1193,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) } } action->scriptData.script.ptr = ResolveJump(action, val); - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; sub_80A87AC(0, 0); } else { @@ -1217,7 +1217,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) cmd = *action->scriptData.curPtr; action->scriptData.script.ptr = FindLabel(action, cmd.argShort); } - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; sub_80A87AC(0, 0); } else { @@ -1232,7 +1232,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) bool8 flag = FALSE; if (action->scriptData.branchDiscriminant < 0) { if (action->scriptData.script.ptr->op != CMD_BYTE_D1) { - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; break; } } @@ -1248,7 +1248,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) while (action->scriptData.script.ptr->op == CMD_BYTE_D1) { action->scriptData.script.ptr++; } - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; break; } } @@ -1292,7 +1292,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) cmd = *(action->scriptData.curPtr + action->scriptData.branchDiscriminant + tmp); action->scriptData.script.ptr = FindLabel(action, cmd.argShort); } - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; sub_80A87AC(0, 0); } else { @@ -1306,7 +1306,7 @@ s16 HandleAction(Action *action, const DebugLocation *debug) } else { action->scriptData.script.ptr = ResolveJump(action, gUnlockBranchLabels[1]); - action->scriptData.savedState = 3; + action->scriptData.savedState = ESC_RET_03; } break; } @@ -1436,12 +1436,12 @@ s16 HandleAction(Action *action, const DebugLocation *debug) } break; } - case 3: { + case ESC_RET_03: { s32 state = ExecuteScriptCommand(action); action->scriptData.savedState = state; switch ((s16)state) { - case 0: { - if (action->scriptData2.savedState) { + case ESC_RET_00: { + if (action->scriptData2.savedState != ESC_RET_00) { action->scriptData = action->scriptData2; if (action->callbacks->setDirection && action->scriptData.storedDir != -1) { u32 tmp; @@ -1458,29 +1458,37 @@ s16 HandleAction(Action *action, const DebugLocation *debug) else { InitScriptData(&action->scriptData); } - return 3; + return ESC_RET_03; } - case 3: return 3; - case 4: return 4; - case 1: return 1; - case 2: default: { + case ESC_RET_03:{ + return ESC_RET_03; + } + case ESC_RET_04:{ + return ESC_RET_04; + } + case ESC_RET_01:{ + return ESC_RET_01; + } + case ESC_RET_02: + default: { action->scriptData.unk2C = 0; break; } } break; } - case 0: - case 1: - case 4: { + case ESC_RET_00: + case ESC_RET_01: + case ESC_RET_04: { return action->scriptData.savedState; } } } - return 3; + + return ESC_RET_03; } - return 0; + return ESC_RET_00; } #define MapValueOrDefault(curCmd, defaultVal, dst) \ @@ -1489,32 +1497,20 @@ s16 HandleAction(Action *action, const DebugLocation *debug) *(dst) = tmp; \ } -#define SectorValueOrDefault(curCmd, defaultVal, dst) \ +#define SectorValueOrDefault(curCmd, defaultVal, dst) \ { \ s32 tmp = (s8)(curCmd)->argByte < 0 ? (defaultVal) : (s8)(curCmd)->argByte; \ *(dst) = tmp; \ } -#define GroupValueOrDefault(curCmd, defaultVal, dst) \ +#define GroupValueOrDefault(curCmd, defaultVal, dst) \ { \ s32 tmp = (curCmd)->argShort < 0 ? (defaultVal) : (curCmd)->argShort; \ *(dst) = tmp; \ } // overlay_0000.bin::021497FC -// Return values: -// This function returns what's likely an enum, which controls the state of the script engine state machine, and possibly provides information to code calling the engine. -// The enum is shared at least with HandleAction. -// This value is saved into the state field of the Action when returned from this function. -// - Value 0 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 code 3 to the script engine caller. -// Caveat: If the scripting engine is in state 0, HandleAction will immediately return 0 without performing any work. -// - Value 1 is a terminal state (script success? error?), no further scripting progress will happen. This code is always returned to the caller from now on. -// - Value 2 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 -// - Value 3 returns to the caller, but will give control back to ExecuteScriptCommand when reentering the script ("script not finished") -// - Value 4 is some kind of fatal error state, no further scripting progress will happen. This code is always returned to the caller from now on. +// Return value is enum "ESC_RetID" static s32 ExecuteScriptCommand(Action *action) { ScriptCommand curCmd; @@ -1565,11 +1561,11 @@ static s32 ExecuteScriptCommand(Action *action) } else { action->scriptData.branchDiscriminant = -1; } - return 2; // do action + return ESC_RET_02; } else { SetScriptVarValue(NULL, DUNGEON_SELECT, RescueDungeonToScriptDungeonId((s16)curCmd.arg1)); action->scriptData.branchDiscriminant = 1; - return 2; // do action + return ESC_RET_02; } break; } @@ -1578,20 +1574,20 @@ static s32 ExecuteScriptCommand(Action *action) if (ScriptSpecialTextHandler2(SPECIAL_TEXT_DOJO_ENTER, 0, NULL_MONORSTRPTR)) { sub_80A87AC(0, 11); action->scriptData.branchDiscriminant = 0; - return 2; + return ESC_RET_02; } else { action->scriptData.branchDiscriminant = -1; - return 2; + return ESC_RET_02; } } else { SetScriptVarValue(NULL, DUNGEON_ENTER, curCmd.arg1); action->scriptData.branchDiscriminant = 1; - return 2; + return ESC_RET_02; } } case CMD_BYTE_05: { action->scriptData.branchDiscriminant = 1; - return 2; + return ESC_RET_02; } case CMD_BYTE_07: { s32 tmp = (s16)curCmd.arg1; @@ -1605,10 +1601,10 @@ static s32 ExecuteScriptCommand(Action *action) } if (tmp != -1) { action->scriptData.branchDiscriminant = 1; - return 2; + return ESC_RET_02; } else { action->scriptData.branchDiscriminant = -1; - return 2; + return ESC_RET_02; } } case CMD_BYTE_08: // SELECT_MAP @@ -1828,7 +1824,7 @@ static s32 ExecuteScriptCommand(Action *action) gUnknown_2039A34 = map; GroundCancelAllEntities(); if (action->unk8.unk0 != 0) - return 4; // Fatal? + return ESC_RET_04; } break; } @@ -1902,38 +1898,38 @@ static s32 ExecuteScriptCommand(Action *action) } } GroundLives_ExecutePlayerScriptActionLives(action->unk8.unk2, ret); - return 3; + return ESC_RET_03; } break; } case CMD_BYTE_22: { sub_80999E8(curCmd.argShort); if (curCmd.argByte != 0) - return 2; + return ESC_RET_02; break; } case CMD_BYTE_23: { sub_80999FC(curCmd.argShort); if (curCmd.argByte != 0) - return 2; + return ESC_RET_02; break; } case CMD_BYTE_24: { sub_8099A10(curCmd.argShort, curCmd.arg1, curCmd.arg2); if (curCmd.argByte != 0) - return 2; + return ESC_RET_02; break; } case CMD_BYTE_25: { sub_8099A34(curCmd.argShort); if (curCmd.argByte != 0) - return 2; + return ESC_RET_02; break; } case CMD_BYTE_26: { sub_8099A48(curCmd.argShort); if (curCmd.argByte != 0) - return 2; + return ESC_RET_02; break; } case CMD_BYTE_27: // FLASH_FROM @@ -1948,7 +1944,7 @@ static s32 ExecuteScriptCommand(Action *action) break; } if (curCmd.argByte != FALSE) - return 2; + return ESC_RET_02; break; } case CMD_BYTE_29: { @@ -1968,7 +1964,7 @@ static s32 ExecuteScriptCommand(Action *action) break; sub_80A87AC(0, 10); if (GroundScriptCheckLockCondition(action, 0)) - return 2; + return ESC_RET_02; break; } case CMD_BYTE_30: { @@ -2105,7 +2101,7 @@ static s32 ExecuteScriptCommand(Action *action) if (ret) { sub_80A87AC(0, 10); if (GroundScriptCheckLockCondition(action, 0)) - return 2; + return ESC_RET_02; } break; } @@ -2113,7 +2109,7 @@ static s32 ExecuteScriptCommand(Action *action) if ((s8)ScriptPrintTextOnBgAuto(curCmd.argShort, curCmd.argPtr) && curCmd.argShort >= 0) { sub_80A87AC(0, 10); if (GroundScriptCheckLockCondition(action, 0)) - return 2; + return ESC_RET_02; } break; } @@ -2121,18 +2117,18 @@ static s32 ExecuteScriptCommand(Action *action) sub_809AFC8((u8)curCmd.argByte > 0, curCmd.arg1, (s16)curCmd.arg2, curCmd.argPtr); if (GroundScriptCheckLockCondition(action, 1)) { sub_80A87AC(0, 11); - return 2; + return ESC_RET_02; } break; } case CMD_BYTE_3C: { // SPECIAL_TEXT ScriptSpecialTextHandler(curCmd.argByte, curCmd.arg1, curCmd.arg2, STR_TO_MONORSTRPTR((u8*)curCmd.argPtr)); sub_80A87AC(0, 11); - return 2; + return ESC_RET_02; } case CMD_BYTE_3B: { scriptData->unk2A = 0; - return 2; + return ESC_RET_02; } case CMD_BYTE_3D: { s32 i; @@ -2145,13 +2141,13 @@ static s32 ExecuteScriptCommand(Action *action) sPokeNameBuffer[POKEMON_NAME_LENGTH] = 0; ScriptSpecialTextHandler2(SPECIAL_TEXT_PLAYER_NAME_INPUT, 0, STR_TO_MONORSTRPTR(sPokeNameBuffer)); sub_80A87AC(0, 11); - return 2; + return ESC_RET_02; } break; } else { ScriptSpecialTextHandler2(SPECIAL_TEXT_PLAYER_NAME_INPUT, 1, STR_TO_MONORSTRPTR(sPokeNameBuffer)); sub_80A87AC(0, 11); - return 2; + return ESC_RET_02; } } case CMD_BYTE_3E: { @@ -2159,7 +2155,7 @@ static s32 ExecuteScriptCommand(Action *action) sPokeNameBuffer[10] = '\0'; ScriptSpecialTextHandler2(SPECIAL_TEXT_TEAM_NAME_INPUT, 0, STR_TO_MONORSTRPTR(sPokeNameBuffer)); sub_80A87AC(0, 11); - return 2; + return ESC_RET_02; } case CMD_BYTE_3F: { s32 i; @@ -2168,7 +2164,7 @@ static s32 ExecuteScriptCommand(Action *action) ScriptSpecialTextHandler2(SPECIAL_TEXT_PASSWORD_INPUT, (u8)curCmd.argByte, STR_TO_MONORSTRPTR(sPokeNameBuffer)); sub_80A87AC(0, 11); - return 2; + return ESC_RET_02; } case CMD_BYTE_42: { StopAllMusic_1(); @@ -2297,7 +2293,7 @@ static s32 ExecuteScriptCommand(Action *action) unk.y = curCmd.arg2 << 8; action->callbacks->moveReal(action->parentObject, &unk); scriptData->unk2A = (u8)curCmd.argByte; - return 2; + return ESC_RET_02; } case CMD_BYTE_59: { PixelPos unk; @@ -2305,7 +2301,7 @@ static s32 ExecuteScriptCommand(Action *action) unk.y = curCmd.arg1 << 8; action->callbacks->moveRelative(action->parentObject, &unk); scriptData->unk2A = (u8)curCmd.argByte; - return 2; + return ESC_RET_02; } case CMD_BYTE_5A: { PixelPos unk; @@ -2313,7 +2309,7 @@ static s32 ExecuteScriptCommand(Action *action) unk.y = OtherRandInt(curCmd.arg1) << 8; action->callbacks->moveRelative(action->parentObject, &unk); scriptData->unk2A = (u8)curCmd.argByte; - return 2; + return ESC_RET_02; } case CMD_BYTE_5B: { PixelPos unk; @@ -2321,7 +2317,7 @@ static s32 ExecuteScriptCommand(Action *action) GroundLink_GetPos((s16)curCmd.arg1, &unk); action->callbacks->moveReal(action->parentObject, &unk); scriptData->unk2A = (u8)curCmd.argByte; - return 2; + return ESC_RET_02; } case CMD_BYTE_5C: { PixelPos pos, pos1, pos2; @@ -2331,7 +2327,7 @@ static s32 ExecuteScriptCommand(Action *action) pos.y = pos1.y + OtherRandInt(pos2.y - pos1.y); action->callbacks->moveReal(action->parentObject, &pos); scriptData->unk2A = (u8)curCmd.argByte; - return 2; + return ESC_RET_02; } case CMD_BYTE_5D: { PixelPos unk; @@ -2340,7 +2336,7 @@ static s32 ExecuteScriptCommand(Action *action) sub_80A8FD8(res, &unk); action->callbacks->moveReal(action->parentObject, &unk); scriptData->unk2A = (u8)curCmd.argByte; - return 2; + return ESC_RET_02; } break; } @@ -2357,7 +2353,7 @@ static s32 ExecuteScriptCommand(Action *action) action->scriptData.storedDir = dir; action->callbacks->setDirection(action->parentObject, dir); scriptData->unk2A = (u8)curCmd.argByte; - return 2; + return ESC_RET_02; } case CMD_BYTE_5F: { PixelPos pos; @@ -2376,7 +2372,7 @@ static s32 ExecuteScriptCommand(Action *action) case CMD_BYTE_60: { action->callbacks->setPosHeight(action->parentObject, curCmd.arg1 << 8); scriptData->unk2A = (u8)curCmd.argByte; - return 2; + return ESC_RET_02; } case CMD_BYTE_61: case CMD_BYTE_69: { @@ -2384,7 +2380,7 @@ static s32 ExecuteScriptCommand(Action *action) scriptData->pos2.y = curCmd.arg2 << 8; scriptData->unk30 = curCmd.argShort; scriptData->unk2A = -1; - return 2; + return ESC_RET_02; } case CMD_BYTE_62: case CMD_BYTE_6A: { @@ -2394,7 +2390,7 @@ static s32 ExecuteScriptCommand(Action *action) scriptData->pos2.y = pos.y + (curCmd.arg2 << 8); scriptData->unk30 = curCmd.argShort; scriptData->unk2A = -1; - return 2; + return ESC_RET_02; } case CMD_BYTE_63: case CMD_BYTE_6B: { @@ -2402,7 +2398,7 @@ static s32 ExecuteScriptCommand(Action *action) GroundLink_GetPos((s16)curCmd.arg1, &scriptData->pos2); scriptData->unk30 = curCmd.argShort; scriptData->unk2A = -1; - return 2; + return ESC_RET_02; } case CMD_BYTE_64: case CMD_BYTE_6C: { @@ -2410,7 +2406,7 @@ static s32 ExecuteScriptCommand(Action *action) GroundLink_GetPos((s16)curCmd.arg1, &scriptData->pos2); scriptData->unk30 = curCmd.argShort; scriptData->unk2A = (u8)curCmd.argByte; - return 2; + return ESC_RET_02; } case CMD_BYTE_65: case CMD_BYTE_6D: { @@ -2418,7 +2414,7 @@ static s32 ExecuteScriptCommand(Action *action) GroundLink_GetPos((s16)curCmd.arg1, &scriptData->pos2); scriptData->unk30 = curCmd.argShort; scriptData->unk2A = OtherRandInt((u8)curCmd.argByte); - return 2; + return ESC_RET_02; } case CMD_BYTE_66: case CMD_BYTE_67: @@ -2429,7 +2425,7 @@ static s32 ExecuteScriptCommand(Action *action) sub_80A8FD8(ret, &scriptData->pos2); scriptData->unk30 = curCmd.argShort; scriptData->unk2A = (u8)curCmd.argByte; - return 2; + return ESC_RET_02; } break; } @@ -2450,7 +2446,7 @@ static s32 ExecuteScriptCommand(Action *action) } else { scriptData->unk2A = curCmd.argShort; } - return 2; + return ESC_RET_02; } case CMD_BYTE_72: case CMD_BYTE_78: @@ -2466,7 +2462,7 @@ static s32 ExecuteScriptCommand(Action *action) } else { scriptData->unk2A = curCmd.argShort; } - return 2; + return ESC_RET_02; } case CMD_BYTE_73: case CMD_BYTE_79: @@ -2495,7 +2491,7 @@ static s32 ExecuteScriptCommand(Action *action) } else { scriptData->unk2A = curCmd.argShort; } - return 2; + return ESC_RET_02; } case CMD_BYTE_74: case CMD_BYTE_7A: @@ -2511,7 +2507,7 @@ static s32 ExecuteScriptCommand(Action *action) } else { scriptData->unk2A = curCmd.argShort; } - return 2; + return ESC_RET_02; } case CMD_BYTE_75: case CMD_BYTE_7B: @@ -2529,7 +2525,7 @@ static s32 ExecuteScriptCommand(Action *action) } else { scriptData->unk2A = curCmd.argShort; } - return 2; + return ESC_RET_02; } case CMD_BYTE_76: case CMD_BYTE_7C: @@ -2546,7 +2542,7 @@ static s32 ExecuteScriptCommand(Action *action) } else { scriptData->unk2A = curCmd.argShort; } - return 2; + return ESC_RET_02; } break; } @@ -2555,14 +2551,14 @@ static s32 ExecuteScriptCommand(Action *action) scriptData->unk48 = curCmd.arg1 << 8; scriptData->unk30 = curCmd.argShort; scriptData->unk2A = -1; - return 2; + return ESC_RET_02; } case CMD_BYTE_89: { action->scriptData.storedDir = curCmd.arg1; action->callbacks->setDirection(action->parentObject, (s8) curCmd.arg1); scriptData->unk30 = curCmd.argShort; scriptData->unk2A = (u8)curCmd.argByte; - return 2; + return ESC_RET_02; } case CMD_BYTE_8A: { // CMD_UNK_8A s8 dir; @@ -2571,13 +2567,13 @@ static s32 ExecuteScriptCommand(Action *action) action->callbacks->setDirection(action->parentObject, action->scriptData.storedDir); scriptData->unk30 = curCmd.argShort; scriptData->unk2A = (u8)curCmd.argByte; - return 2; + return ESC_RET_02; } case CMD_BYTE_8B: { // SET_DIR_WAIT action->scriptData.storedDir = curCmd.argShort; action->callbacks->setDirection(action->parentObject, action->scriptData.storedDir); scriptData->unk2A = (u8)curCmd.argByte; - return 2; + return ESC_RET_02; } case CMD_BYTE_8C: { // CMD_UNK_8C s32 ret = (s16)sub_80A7AE8((s16)curCmd.arg1); @@ -2588,7 +2584,7 @@ static s32 ExecuteScriptCommand(Action *action) action->callbacks->setDirection(action->parentObject, action->scriptData.storedDir); } scriptData->unk2A = (u8)curCmd.argByte; - return 2; + return ESC_RET_02; } case CMD_BYTE_8D: { // CMD_UNK_8D s8 dir; @@ -2596,7 +2592,7 @@ static s32 ExecuteScriptCommand(Action *action) action->scriptData.storedDir = TransformDirection1(dir, (u8)curCmd.argShort); action->callbacks->setDirection(action->parentObject, action->scriptData.storedDir); scriptData->unk2A = (u8)curCmd.argByte; - return 2; + return ESC_RET_02; } case CMD_BYTE_8E: // CMD_UNK_8E case CMD_BYTE_8F: // CMD_UNK_8F @@ -2650,25 +2646,25 @@ static s32 ExecuteScriptCommand(Action *action) action->callbacks->setDirection(action->parentObject, action->scriptData.storedDir); } scriptData->unk2A = (u8)curCmd.argByte; - return 2; + return ESC_RET_02; } case CMD_BYTE_93: // CMD_UNK_93 case CMD_BYTE_94: // CMD_UNK_94 case CMD_BYTE_95: { // CMD_UNK_95 scriptData->unk2A = 0; - return 2; + return ESC_RET_02; } case CMD_BYTE_91: { // ROTATE_TO action->scriptData.unk4D = (s8)curCmd.arg1; scriptData->unk2A = 0; - return 2; + return ESC_RET_02; } case CMD_BYTE_92: { // CMD_UNK_92 s8 unk; action->callbacks->getDirection(action->parentObject, &unk); action->scriptData.unk4D = TransformDirection1(unk, (u8)curCmd.arg1); scriptData->unk2A = 0; - return 2; + return ESC_RET_02; } case CMD_BYTE_97: { sub_809D124(curCmd.argShort, curCmd.arg1, curCmd.arg2); @@ -2719,13 +2715,13 @@ static s32 ExecuteScriptCommand(Action *action) switch (action->unk8.unk0) { case 1: sub_809D1A8(1, id, curCmd.argShort); - return 2; + return ESC_RET_02; case 2: sub_809D1A8(2, id, curCmd.argShort); - return 2; + return ESC_RET_02; case 3: sub_809D1A8(3, id, curCmd.argShort); - return 2; + return ESC_RET_02; } break; } @@ -2736,21 +2732,21 @@ static s32 ExecuteScriptCommand(Action *action) case 1: sub_80A8FD8(id, &unk); sub_809D190(0, &unk, curCmd.argShort); - return 2; + return ESC_RET_02; case 2: sub_80AC448(id, &unk); sub_809D190(0, &unk, curCmd.argShort); - return 2; + return ESC_RET_02; case 3: sub_80AD360(id, &unk); sub_809D190(0, &unk, curCmd.argShort); - return 2; + return ESC_RET_02; } break; } case CMD_BYTE_9D: { sub_809D1A8(1, 0, curCmd.argShort); - return 2; + return ESC_RET_02; } case CMD_BYTE_9E: { s32 id = action->callbacks->getIndex(action->parentObject); @@ -2759,13 +2755,13 @@ static s32 ExecuteScriptCommand(Action *action) switch (action->unk8.unk0) { case 1: sub_809D1E4(1, id, curCmd.argShort); - return 2; + return ESC_RET_02; case 2: sub_809D1E4(2, id, curCmd.argShort); - return 2; + return ESC_RET_02; case 3: sub_809D1E4(3, id, curCmd.argShort); - return 2; + return ESC_RET_02; } break; } @@ -2776,21 +2772,21 @@ static s32 ExecuteScriptCommand(Action *action) case 1: sub_80A8FD8(id, &unk); sub_809D1CC(0, &unk, curCmd.argShort); - return 2; + return ESC_RET_02; case 2: sub_80AC448(id, &unk); sub_809D1CC(0, &unk, curCmd.argShort); - return 2; + return ESC_RET_02; case 3: sub_80AD360(id, &unk); sub_809D1CC(0, &unk, curCmd.argShort); - return 2; + return ESC_RET_02; } break; } case CMD_BYTE_A0: { sub_809D1E4(1, 0, curCmd.argShort); - return 2; + return ESC_RET_02; } case CMD_BYTE_A1: { s32 id = action->callbacks->getIndex(action->parentObject); @@ -2799,13 +2795,13 @@ static s32 ExecuteScriptCommand(Action *action) switch (action->unk8.unk0) { case 1: sub_809D220(1, id, curCmd.argShort); - return 2; + return ESC_RET_02; case 2: sub_809D220(2, id, curCmd.argShort); - return 2; + return ESC_RET_02; case 3: sub_809D220(3, id, curCmd.argShort); - return 2; + return ESC_RET_02; } break; } @@ -2816,21 +2812,21 @@ static s32 ExecuteScriptCommand(Action *action) case 1: sub_80A8FD8(id, &unk); sub_809D208(0, &unk, curCmd.argShort); - return 2; + return ESC_RET_02; case 2: sub_80AC448(id, &unk); sub_809D208(0, &unk, curCmd.argShort); - return 2; + return ESC_RET_02; case 3: sub_80AD360(id, &unk); sub_809D208(0, &unk, curCmd.argShort); - return 2; + return ESC_RET_02; } break; } case CMD_BYTE_A3: { sub_809D220(1, 0, curCmd.argShort); - return 2; + return ESC_RET_02; } case CMD_BYTE_A4: { ResetScriptVarArray(scriptData->localVars.buf, curCmd.argShort); @@ -3084,12 +3080,12 @@ static s32 ExecuteScriptCommand(Action *action) scriptData->branchDiscriminant = GetScriptVarValue(scriptData->localVars.buf, curCmd.argShort); while (scriptData->script.ptr->op == CMD_BYTE_D0) { if (scriptData->script.ptr->argShort == scriptData->branchDiscriminant) - return 2; + return ESC_RET_02; scriptData->script.ptr++; } if (scriptData->script.ptr->op == CMD_BYTE_D1) { scriptData->branchDiscriminant = -1; - return 2; + return ESC_RET_02; } break; } @@ -3151,23 +3147,23 @@ static s32 ExecuteScriptCommand(Action *action) } if (GroundScriptCheckLockCondition(action, 1)) { sub_80A87AC(0, 11); - return 2; + return ESC_RET_02; } break; } case CMD_BYTE_DA: { if (GroundScriptCheckLockCondition(action, 1)) - return 2; + return ESC_RET_02; break; } case CMD_BYTE_DB: { // WAIT scriptData->unk2A = curCmd.argShort; - return 2; + return ESC_RET_02; } case CMD_BYTE_DC: { scriptData->unk2A = curCmd.argShort + OtherRandInt(curCmd.arg1 - curCmd.argShort); - return 2; + return ESC_RET_02; } case CMD_BYTE_DD: case CMD_BYTE_DE: @@ -3175,13 +3171,13 @@ static s32 ExecuteScriptCommand(Action *action) case CMD_BYTE_E0: case CMD_BYTE_E1: // WAIT_FANFARE1 case CMD_BYTE_E2: { // WAIT_FANFARE2 - return 2; + return ESC_RET_02; } case CMD_BYTE_E3: { scriptData->branchDiscriminant = curCmd.argShort; if (GroundScriptCheckLockCondition(action, curCmd.argShort)) - return 2; + return ESC_RET_02; break; } @@ -3193,7 +3189,7 @@ static s32 ExecuteScriptCommand(Action *action) scriptData->branchDiscriminant = curCmd.argShort; if (GroundScriptLockCond(action, curCmd.argShort, curCmd.argByte)) - return 2; + return ESC_RET_02; break; } @@ -3246,7 +3242,7 @@ static s32 ExecuteScriptCommand(Action *action) case CMD_BYTE_EE: { // RET_DIRECT if (scriptData->savedScript.ptr == NULL) { // DS: Assert(FALSE, "Script return stack error"); - return 0; + return ESC_RET_00; } scriptData->script = scriptData->savedScript; @@ -3256,11 +3252,11 @@ static s32 ExecuteScriptCommand(Action *action) } case CMD_BYTE_EF: // RET // DS: if (scriptData->savedScript.ptr != NULL) Assert(FALSE, "Script end stack error"); - return 0; + return ESC_RET_00; case CMD_BYTE_F0: // HALT - return 1; + return ESC_RET_01; case CMD_BYTE_F1: // END_DELETE - return 4; // fatal error? + return ESC_RET_04; case CMD_BYTE_F2: // CMD_F2 case CMD_BYTE_F3: // CMD_F3 case CMD_BYTE_F4: // LABEL @@ -3300,7 +3296,7 @@ UNUSED static bool8 GroundScript_ExecuteTrigger(s16 scriptID) ret = HandleAction(&action, DEBUG_LOC_PTR("../ground/ground_script.c", 4558, "GroundScript_ExecuteTrigger")); InitAction2(&action); - if (ret == 0) + if (ret == ESC_RET_00) return TRUE; return FALSE;