Use enum for FlagJudge operations

This commit is contained in:
Mateon1 2024-09-19 18:52:50 +02:00
parent b5bb921ade
commit e2e085f33b
No known key found for this signature in database
GPG Key ID: 6A6067123E4CAF6E
4 changed files with 37 additions and 23 deletions

View File

@ -1,6 +1,20 @@
#ifndef GUARD_EVENT_FLAG_H
#define GUARD_EVENT_FLAG_H
enum FlagJudgeOperation {
JUDGE_TRUE,
JUDGE_FALSE,
JUDGE_EQ,
JUDGE_GT,
JUDGE_LT,
JUDGE_GE,
JUDGE_LE,
JUDGE_NE,
JUDGE_AND_NONZERO,
JUDGE_XOR_NONZERO, // logically identical to JUDGE_NE
JUDGE_BIT_SET,
};
// size: 0x10
struct ScriptVarInfo {
s16 type;
@ -37,13 +51,13 @@ bool8 ScriptVarScenarioEqual(s16 param_1, u32 param_2, s32 param_3);
bool8 ScriptVarScenarioAfter(s16 param_1, u32 param_2, s32 param_3);
void sub_8001D88(void);
u32 _FlagCalc(s32 param_1, s32 param_2, u32 operation);
bool8 _FlagJudge(s32 param_1, s32 param_2, u32 operation);
bool8 _FlagJudge(s32 param_1, s32 param_2, enum FlagJudgeOperation operation);
u32 FlagCalc(s32 r0, s32 r1, u32 operation);
void UpdateScriptVarWithImmediate(u8 *localVarBuf, s16 varId, s32 val, u32 operation);
void UpdateScriptVarWithVar(u8 *localVarBuf, s16 dstVarId, s16 srcVarId, u32 operation);
bool8 FlagJudge(s32 r0, s32 r1, u32 operation);
bool8 JudgeVarWithImmediate(u8 *param_1, s16 param_2, s32 param_3, u32 operation);
bool8 JudgeVarWithVar(u8 *param_1, s16 param_2, s16 param_3, u32 operation);
bool8 FlagJudge(s32 r0, s32 r1, enum FlagJudgeOperation operation);
bool8 JudgeVarWithImmediate(u8 *param_1, s16 param_2, s32 param_3, enum FlagJudgeOperation operation);
bool8 JudgeVarWithVar(u8 *param_1, s16 param_2, s16 param_3, enum FlagJudgeOperation operation);
bool8 sub_80023E4(u32 param_1);
u8 sub_8002658(s16 param_1);
s16 sub_8002694(u8 param_1);

View File

@ -353,30 +353,30 @@ u32 _FlagCalc(s32 param_1, s32 param_2, u32 operation)
}
}
bool8 _FlagJudge(s32 param_1, s32 param_2, u32 operation)
bool8 _FlagJudge(s32 param_1, s32 param_2, enum FlagJudgeOperation operation)
{
switch(operation) {
case 0:
return 1;
case 1:
return 0;
case 2:
case JUDGE_TRUE:
return TRUE;
case JUDGE_FALSE:
return FALSE;
case JUDGE_EQ:
return param_1 == param_2;
case 7:
case JUDGE_NE:
return param_1 != param_2;
case 3:
case JUDGE_GT:
return param_1 > param_2;
case 5:
case JUDGE_GE:
return param_1 >= param_2;
case 4:
case JUDGE_LT:
return param_1 < param_2;
case 6:
case JUDGE_LE:
return param_1 <= param_2;
case 8:
case JUDGE_AND_NONZERO:
return (param_1 & param_2) != 0;
case 9:
case JUDGE_XOR_NONZERO:
return (param_1 ^ param_2) != 0;
case 10:
case JUDGE_BIT_SET:
return param_1 >> (param_2) & 1;
default:
FatalError(&gUnknown_80B7350,gUnknown_80B735C, operation); // event flag rule error %d
@ -414,12 +414,12 @@ void UpdateScriptVarWithVar(u8 *param_1, s16 param_2, s16 param_3, u32 operation
SetScriptVarValue(param_1,param_2_s32,uVar3);
}
bool8 FlagJudge(s32 r0, s32 r1, u32 operation)
bool8 FlagJudge(s32 r0, s32 r1, enum FlagJudgeOperation operation)
{
return _FlagJudge(r0, r1, operation);
}
bool8 JudgeVarWithImmediate(u8 *param_1, s16 param_2, s32 param_3, u32 operation)
bool8 JudgeVarWithImmediate(u8 *param_1, s16 param_2, s32 param_3, enum FlagJudgeOperation operation)
{
s32 uVar1;
@ -427,7 +427,7 @@ bool8 JudgeVarWithImmediate(u8 *param_1, s16 param_2, s32 param_3, u32 operation
return _FlagJudge(uVar1,param_3,operation);
}
bool8 JudgeVarWithVar(u8 *param_1, s16 param_2, s16 param_3, u32 operation)
bool8 JudgeVarWithVar(u8 *param_1, s16 param_2, s16 param_3, enum FlagJudgeOperation operation)
{
s32 uVar1;
s32 uVar2;

View File

@ -1499,7 +1499,7 @@ s32 ExecuteScriptCommand(Action *action) {
break;
}
case 0xb3: {
if ((u8)JudgeVarWithImmediate(NULL, curCmd.argShort, curCmd.arg1, 2)) {
if ((u8)JudgeVarWithImmediate(NULL, curCmd.argShort, curCmd.arg1, JUDGE_EQ)) {
scriptData->script.ptr = FindLabel(action, (u8)curCmd.argByte);
}
break;

View File

@ -90,7 +90,7 @@ ScriptCommand *ResolveJump(Action *action, s32 r1)
if (script.op == 0xCC)
{
if(FlagJudge(r1, script.arg1, 0x2))
if(FlagJudge(r1, script.arg1, JUDGE_EQ))
return FindLabel(action, script.argShort);
}
else if (script.op == 0xCD)