Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
z64a committed Oct 20, 2024
1 parent a2db06f commit 509d75a
Show file tree
Hide file tree
Showing 85 changed files with 953 additions and 935 deletions.
4 changes: 2 additions & 2 deletions include/common_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -912,8 +912,8 @@ typedef struct BattleStatus {
/* 0x07B */ u8 damageTaken;
/* 0x07C */ s8 changePartnerAllowed;
/* 0x07D */ s8 menuStatus[4]; ///< -1 = automatically pick the first move, 0 = disabled, 1 = enabled
/* 0x081 */ s8 actionSuccess; // degree of success for action command, -1 indicates failure, 0 is in progress, >0 is some degree of success
/* 0x082 */ s8 maxActionSuccess; // seems to indicate the maximum positive value for actionSuccess; never read and inconsistently used between various action commands
/* 0x081 */ s8 actionQuality; // degree of success for action command, -1 indicates failure, 0 is in progress, >0 is some degree of success
/* 0x082 */ s8 maxActionQuality; // seems to indicate the maximum positive value for actionQuality; never read and inconsistently used between various action commands
/* 0x083 */ s8 actionCommandMode;
/* 0x084 */ s8 actionProgress; // actionCommandVar1 ?
/* 0x085 */ s8 resultTier;
Expand Down
12 changes: 6 additions & 6 deletions include/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -1961,12 +1961,12 @@ typedef enum HitResult {
} HitResult;

typedef enum ActionResult {
ACTION_RESULT_NONE = 127,
ACTION_RESULT_MINUS_4 = -4,
ACTION_RESULT_MINUS_2 = -2,
ACTION_RESULT_EARLY = -1,
ACTION_RESULT_FAIL = 0,
ACTION_RESULT_SUCCESS = 1,
ACTION_RESULT_NONE = 127,
ACTION_RESULT_METER_BELOW_HALF = -4, // certain mashing comamnds fail with this value
ACTION_RESULT_METER_NOT_ENOUGH = -2, // certain mashing comamnds fail with this value
ACTION_RESULT_EARLY = -1, // timing commands too early fail with this value
ACTION_RESULT_FAIL = 0, // simple failure to complete action command
ACTION_RESULT_SUCCESS = 1,
} ActionResult;

typedef enum BlockResult {
Expand Down
4 changes: 2 additions & 2 deletions include/script_api/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ API_CALLABLE(EnablePlayerBlur);
API_CALLABLE(PlayerBasicJumpToGoal);
API_CALLABLE(PlayerSuperJumpToGoal);
API_CALLABLE(PlayerUltraJumpToGoal);
API_CALLABLE(GetPlayerActionSuccess);
API_CALLABLE(GetPlayerActionQuality);
API_CALLABLE(BindTakeTurn);
API_CALLABLE(PauseTakeTurn);
API_CALLABLE(ResumeTakeTurn);
Expand Down Expand Up @@ -283,7 +283,7 @@ API_CALLABLE(SetBattleCamTargetingModes);
API_CALLABLE(UseBattleCamPresetImmediately);
API_CALLABLE(UseBattleCamPresetWait);
API_CALLABLE(HideHealthBar);
API_CALLABLE(GetPartnerActionSuccess);
API_CALLABLE(GetPartnerActionQuality);
API_CALLABLE(CreateNpc);
API_CALLABLE(EnableBattleStatusBar);
API_CALLABLE(PlayerYieldTurn);
Expand Down
12 changes: 6 additions & 6 deletions src/battle/action_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,13 +677,13 @@ API_CALLABLE(SetupMashMeter) {
return ApiStatus_DONE2;
}

API_CALLABLE(GetActionSuccess) {
evt_set_variable(script, *script->ptrReadPos, gBattleStatus.actionSuccess);
API_CALLABLE(GetSmashActionQuality) {
evt_set_variable(script, *script->ptrReadPos, gBattleStatus.actionQuality);
return ApiStatus_DONE2;
}

API_CALLABLE(SetActionSuccess) {
gBattleStatus.actionSuccess = evt_get_variable(script, *script->ptrReadPos);
gBattleStatus.actionQuality = evt_get_variable(script, *script->ptrReadPos);
return ApiStatus_DONE2;
}

Expand Down Expand Up @@ -764,12 +764,12 @@ API_CALLABLE(ShowActionHud) {
return ApiStatus_DONE2;
}

API_CALLABLE(GetActionSuccessCopy) {
evt_set_variable(script, *script->ptrReadPos, gBattleStatus.actionSuccess);
API_CALLABLE(GetMashActionQuality) {
evt_set_variable(script, *script->ptrReadPos, gBattleStatus.actionQuality);
return ApiStatus_DONE2;
}

API_CALLABLE(GetActionResult) {
API_CALLABLE(GetJumpActionQuality) {
evt_set_variable(script, *script->ptrReadPos, gBattleStatus.actionResult);
return ApiStatus_DONE2;
}
Expand Down
8 changes: 4 additions & 4 deletions src/battle/action_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ enum ActionCommandModes {
AC_MODE_TUTORIAL_WAIT_INPUT = 3,
};

#define AC_ACTION_FAILED -1
#define AC_QUALITY_FAILED -1

// mash meter has 100 units for each 1%
#define ONE_PCT_MASH 100
Expand Down Expand Up @@ -205,7 +205,7 @@ s32 check_block_input(s32 buttonMask);
API_CALLABLE(LoadActionCommand);
API_CALLABLE(SetActionDifficultyTable);
API_CALLABLE(SetupMashMeter);
API_CALLABLE(GetActionSuccess);
API_CALLABLE(GetSmashActionQuality);
API_CALLABLE(SetActionSuccess);
API_CALLABLE(SetActionCommandMode);
API_CALLABLE(GetActionCommandMode);
Expand All @@ -216,8 +216,8 @@ API_CALLABLE(func_802693F0);
API_CALLABLE(InterruptActionCommand);
API_CALLABLE(InterruptLeechActionCommand);
API_CALLABLE(ShowActionHud);
API_CALLABLE(GetActionSuccessCopy);
API_CALLABLE(GetActionResult);
API_CALLABLE(GetMashActionQuality);
API_CALLABLE(GetJumpActionQuality);
API_CALLABLE(SetActionResult);
API_CALLABLE(GetBlockResult);
API_CALLABLE(GetActionProgress);
Expand Down
32 changes: 16 additions & 16 deletions src/battle/action_cmd/air_lift.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ API_CALLABLE(N(init)) {
s32 hid;

battleStatus->actionCmdDifficultyTable = actionCmdTableAirLift;
battleStatus->maxActionSuccess = 0;
battleStatus->maxActionQuality = 0;
battleStatus->actionResult = ACTION_RESULT_NONE;

action_command_init_status();
Expand All @@ -47,7 +47,7 @@ API_CALLABLE(N(init)) {
acs->barFillLevel = 0;
acs->barFillWidth = 0;
acs->isBarFilled = FALSE;
battleStatus->actionSuccess = 0;
battleStatus->actionQuality = 0;
battleStatus->actionProgress = 0;

N(HasStarted) = FALSE;
Expand Down Expand Up @@ -90,9 +90,9 @@ API_CALLABLE(N(start)) {
acs->variation = evt_get_variable(script, *args++);

acs->wrongButtonPressed = FALSE;
battleStatus->actionSuccess = 0;
battleStatus->actionQuality = 0;
battleStatus->actionResult = ACTION_RESULT_NONE;
battleStatus->maxActionSuccess = acs->mashMeterCutoffs[acs->mashMeterNumIntervals - 1];
battleStatus->maxActionQuality = acs->mashMeterCutoffs[acs->mashMeterNumIntervals - 1];

acs->any.unk_5C = 0;

Expand Down Expand Up @@ -202,32 +202,32 @@ void N(update)(void) {
hud_element_clear_flags(hid, HUD_ELEMENT_FLAG_DISABLED);
}

battleStatus->actionSuccess = acs->barFillLevel / ONE_PCT_MASH;
if (battleStatus->actionProgress < battleStatus->actionSuccess) {
battleStatus->actionProgress = battleStatus->actionSuccess;
battleStatus->actionQuality = acs->barFillLevel / ONE_PCT_MASH;
if (battleStatus->actionProgress < battleStatus->actionQuality) {
battleStatus->actionProgress = battleStatus->actionQuality;
}
sfx_adjust_env_sound_params(SOUND_LOOP_CHARGE_BAR, 0, 0, battleStatus->actionSuccess * 12);
sfx_adjust_env_sound_params(SOUND_LOOP_CHARGE_BAR, 0, 0, battleStatus->actionQuality * 12);

if (acs->stateTimer != 0) {
acs->stateTimer--;
return;
break;
}

if (acs->escapeChance == 0) {
battleStatus->actionProgress = 0;
}

// threshold for success is completely random, only guaranteed if the bar is 100% filled
battleStatus->actionSuccess = battleStatus->actionProgress;
if (rand_int(99) < battleStatus->actionSuccess) {
battleStatus->actionQuality = battleStatus->actionProgress;
if (rand_int(99) < battleStatus->actionQuality) {
battleStatus->actionResult = ACTION_RESULT_SUCCESS;
battleStatus->actionSuccess = 1;
battleStatus->actionQuality = 1;
} else {
battleStatus->actionResult = ACTION_RESULT_MINUS_2;
battleStatus->actionSuccess = AC_ACTION_FAILED;
battleStatus->actionResult = ACTION_RESULT_METER_NOT_ENOUGH;
battleStatus->actionQuality = AC_QUALITY_FAILED;
}

if (battleStatus->actionSuccess == 1) {
if (battleStatus->actionQuality == 1) {
increment_action_command_success_count();
}

Expand All @@ -245,7 +245,7 @@ void N(update)(void) {
}
if (acs->stateTimer != 0) {
acs->stateTimer--;
return;
break;
}
action_command_free();
break;
Expand Down
26 changes: 13 additions & 13 deletions src/battle/action_cmd/air_raid.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ API_CALLABLE(N(init)) {
BattleStatus* battleStatus = &gBattleStatus;
s32 hid;

battleStatus->maxActionSuccess = 100;
battleStatus->maxActionQuality = 100;
battleStatus->actionCmdDifficultyTable = actionCmdTableAirRaid;
battleStatus->actionResult = ACTION_RESULT_NONE;

if (battleStatus->actionCommandMode == AC_MODE_NOT_LEARNED) {
battleStatus->actionSuccess = 0;
battleStatus->actionQuality = 0;
return ApiStatus_DONE2;
}

Expand All @@ -49,7 +49,7 @@ API_CALLABLE(N(init)) {
acs->barFillLevel = 0;
acs->barFillWidth = 0;
acs->isBarFilled = FALSE;
battleStatus->actionSuccess = 0;
battleStatus->actionQuality = 0;
acs->hudPosX = -48;
acs->hudPosY = 80;

Expand Down Expand Up @@ -80,7 +80,7 @@ API_CALLABLE(N(start)) {
Bytecode* args = script->ptrReadPos;

if (battleStatus->actionCommandMode == AC_MODE_NOT_LEARNED) {
battleStatus->actionSuccess = 0;
battleStatus->actionQuality = 0;
return ApiStatus_DONE2;
}

Expand All @@ -95,9 +95,9 @@ API_CALLABLE(N(start)) {
acs->wrongButtonPressed = FALSE;
acs->barFillLevel = 0;
acs->barFillWidth = 0;
battleStatus->actionSuccess = 0;
battleStatus->actionQuality = 0;
battleStatus->actionResult = ACTION_RESULT_NONE;
battleStatus->maxActionSuccess = acs->mashMeterCutoffs[(acs->mashMeterNumIntervals - 1)];
battleStatus->maxActionQuality = acs->mashMeterCutoffs[(acs->mashMeterNumIntervals - 1)];
battleStatus->flags1 &= ~BS_FLAGS1_FREE_ACTION_COMMAND;
acs->state = AC_STATE_START;

Expand Down Expand Up @@ -243,23 +243,23 @@ void N(update)(void) {

if (acs->stateTimer != 0) {
acs->stateTimer--;
return;
break;
}

if (acs->barFillLevel == 0) {
battleStatus->actionSuccess = AC_ACTION_FAILED;
battleStatus->actionQuality = AC_QUALITY_FAILED;
} else {
battleStatus->actionSuccess = acs->barFillLevel / ONE_PCT_MASH;
battleStatus->actionQuality = acs->barFillLevel / ONE_PCT_MASH;
}

cutoff = acs->mashMeterCutoffs[acs->mashMeterNumIntervals - 1];
if (battleStatus->actionSuccess > cutoff) {
if (battleStatus->actionQuality > cutoff) {
battleStatus->actionResult = ACTION_RESULT_SUCCESS;
} else {
battleStatus->actionResult = ACTION_RESULT_MINUS_2;
battleStatus->actionResult = ACTION_RESULT_METER_NOT_ENOUGH;
}

if (battleStatus->actionSuccess == 100) {
if (battleStatus->actionQuality == 100) {
// only count 100% fill as success for this action command
increment_action_command_success_count();
}
Expand All @@ -272,7 +272,7 @@ void N(update)(void) {
case AC_STATE_DISPOSE:
if (acs->stateTimer != 0) {
acs->stateTimer--;
return;
break;
}
action_command_free();
break;
Expand Down
20 changes: 10 additions & 10 deletions src/battle/action_cmd/body_slam.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ API_CALLABLE(N(init)) {
BattleStatus* battleStatus = &gBattleStatus;
s32 hid;

battleStatus->maxActionSuccess = 100;
battleStatus->maxActionQuality = 100;
battleStatus->actionCmdDifficultyTable = actionCmdTableBodySlam;
battleStatus->actionResult = ACTION_RESULT_NONE;
if (battleStatus->actionCommandMode == AC_MODE_NOT_LEARNED) {
battleStatus->actionSuccess = 0;
battleStatus->actionQuality = 0;
return ApiStatus_DONE2;
}

Expand All @@ -37,7 +37,7 @@ API_CALLABLE(N(init)) {
acs->barFillLevel = 0;
acs->barFillWidth = 0;
acs->isBarFilled = FALSE;
battleStatus->actionSuccess = 0;
battleStatus->actionQuality = 0;
acs->hudPosX = -48;
acs->hudPosY = 80;

Expand Down Expand Up @@ -73,7 +73,7 @@ API_CALLABLE(N(start)) {
Bytecode* args = script->ptrReadPos;

if (battleStatus->actionCommandMode == AC_MODE_NOT_LEARNED) {
battleStatus->actionSuccess = 0;
battleStatus->actionQuality = 0;
return ApiStatus_DONE2;
}

Expand All @@ -88,9 +88,9 @@ API_CALLABLE(N(start)) {
acs->wrongButtonPressed = FALSE;
acs->barFillLevel = 0;
acs->barFillWidth = 0;
battleStatus->actionSuccess = 0;
battleStatus->actionQuality = 0;
battleStatus->actionResult = ACTION_RESULT_NONE;
battleStatus->maxActionSuccess = acs->mashMeterCutoffs[(acs->mashMeterNumIntervals - 1)];
battleStatus->maxActionQuality = acs->mashMeterCutoffs[(acs->mashMeterNumIntervals - 1)];
battleStatus->flags1 &= ~BS_FLAGS1_FREE_ACTION_COMMAND;
acs->state = AC_STATE_START;

Expand Down Expand Up @@ -190,20 +190,20 @@ void N(update)(void) {

do {
if (acs->escapeThreshold < MAX_MASH_UNITS) {
battleStatus->actionSuccess = AC_ACTION_FAILED;
battleStatus->actionQuality = AC_QUALITY_FAILED;
} else {
s32 window = battleStatus->actionCmdDifficultyTable[acs->difficulty] * METER_FILL_RATE;
// release needs to be within 2 frames + modifier from difficulty table
if (acs->escapeThreshold - window >= MAX_MASH_UNITS + 2 * METER_FILL_RATE + 1) {
battleStatus->actionSuccess = AC_ACTION_FAILED;
battleStatus->actionQuality = AC_QUALITY_FAILED;
} else {
battleStatus->actionSuccess = 1;
battleStatus->actionQuality = 1;
}
}
} while (0); // required to match

battleStatus->actionResult = ACTION_RESULT_FAIL;
if (battleStatus->actionSuccess == 1) {
if (battleStatus->actionQuality == 1) {
increment_action_command_success_count();
}

Expand Down
Loading

0 comments on commit 509d75a

Please sign in to comment.