Path: blob/master/src/game/mario_actions_stationary.c
7858 views
#include <PR/ultratypes.h>12#include "sm64.h"3#include "area.h"4#include "audio/external.h"5#include "behavior_data.h"6#include "camera.h"7#include "engine/math_util.h"8#include "interaction.h"9#include "level_update.h"10#include "mario.h"11#include "mario_actions_stationary.h"12#include "mario_step.h"13#include "memory.h"14#include "save_file.h"15#include "sound_init.h"16#include "surface_terrains.h"17#include "game_init.h"18#include "rumble_init.h"1920#include "settings.h"2122s32 check_common_idle_cancels(struct MarioState *m) {23mario_drop_held_object(m);24if (m->floor->normal.y < 0.29237169f) {25return mario_push_off_steep_floor(m, ACT_FREEFALL, 0);26}2728if (m->input & INPUT_STOMPED) {29return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);30}3132if (m->input & INPUT_A_PRESSED) {33return set_jumping_action(m, ACT_JUMP, 0);34}3536if (m->input & INPUT_OFF_FLOOR) {37return set_mario_action(m, ACT_FREEFALL, 0);38}3940if (m->input & INPUT_ABOVE_SLIDE) {41return set_mario_action(m, ACT_BEGIN_SLIDING, 0);42}4344if (m->input & INPUT_FIRST_PERSON) {45return set_mario_action(m, ACT_FIRST_PERSON, 0);46}4748if (m->input & INPUT_NONZERO_ANALOG) {49m->faceAngle[1] = (s16) m->intendedYaw;50return set_mario_action(m, ACT_WALKING, 0);51}5253if (m->input & INPUT_B_PRESSED) {54return set_mario_action(m, ACT_PUNCHING, 0);55}5657if (m->input & INPUT_Z_DOWN) {58return set_mario_action(m, ACT_START_CROUCHING, 0);59}6061return FALSE;62}6364s32 check_common_hold_idle_cancels(struct MarioState *m) {65if (m->floor->normal.y < 0.29237169f) {66return mario_push_off_steep_floor(m, ACT_HOLD_FREEFALL, 0);67}6869if (m->heldObj->oInteractionSubtype & INT_SUBTYPE_DROP_IMMEDIATELY) {70m->heldObj->oInteractionSubtype =71(s32)(m->heldObj->oInteractionSubtype & ~INT_SUBTYPE_DROP_IMMEDIATELY);72return set_mario_action(m, ACT_PLACING_DOWN, 0);73}7475if (m->input & INPUT_STOMPED) {76return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);77}7879if (m->input & INPUT_A_PRESSED) {80return set_jumping_action(m, ACT_HOLD_JUMP, 0);81}8283if (m->input & INPUT_OFF_FLOOR) {84return set_mario_action(m, ACT_HOLD_FREEFALL, 0);85}8687if (m->input & INPUT_ABOVE_SLIDE) {88return set_mario_action(m, ACT_HOLD_BEGIN_SLIDING, 0);89}9091if (m->input & INPUT_NONZERO_ANALOG) {92m->faceAngle[1] = (s16) m->intendedYaw;93return set_mario_action(m, ACT_HOLD_WALKING, 0);94}9596if (m->input & INPUT_B_PRESSED) {97return set_mario_action(m, ACT_THROWING, 0);98}99100if (m->input & INPUT_Z_DOWN) {101return drop_and_set_mario_action(m, ACT_START_CROUCHING, 0);102}103104return FALSE;105}106107s32 act_idle(struct MarioState *m) {108if (m->quicksandDepth > 30.0f) {109return set_mario_action(m, ACT_IN_QUICKSAND, 0);110}111112if ((m->input & INPUT_IN_POISON_GAS) && (!mario_has_improved_metal_cap(m))){113return set_mario_action(m, ACT_COUGHING, 0);114}115116if (!(m->actionArg & 1) && m->health < 0x300) {117return set_mario_action(m, ACT_PANTING, 0);118}119120if (check_common_idle_cancels(m)) {121return TRUE;122}123124if (m->actionState == 3) {125if ((m->area->terrainType & TERRAIN_MASK) == TERRAIN_SNOW) {126return set_mario_action(m, ACT_SHIVERING, 0);127} else {128return set_mario_action(m, ACT_START_SLEEPING, 0);129}130}131132if (m->actionArg & 1) {133set_mario_animation(m, MARIO_ANIM_STAND_AGAINST_WALL);134} else {135switch (m->actionState) {136case 0:137set_mario_animation(m, MARIO_ANIM_IDLE_HEAD_LEFT);138break;139140case 1:141set_mario_animation(m, MARIO_ANIM_IDLE_HEAD_RIGHT);142break;143144case 2:145set_mario_animation(m, MARIO_ANIM_IDLE_HEAD_CENTER);146break;147}148149if (is_anim_at_end(m)) {150// Fall asleep after 10 head turning cycles.151// act_start_sleeping is triggered earlier in the function152// when actionState == 3. This happens when Mario's done153// turning his head back and forth. However, we do some checks154// here to make sure that Mario would be able to sleep here,155// and that he's gone through 10 cycles before sleeping.156// actionTimer is used to track how many cycles have passed.157if (++m->actionState == 3) {158f32 deltaYOfFloorBehindMario = m->pos[1] - find_floor_height_relative_polar(m, -0x8000, 60.0f);159if (deltaYOfFloorBehindMario < -24.0f || 24.0f < deltaYOfFloorBehindMario || m->floor->flags & SURFACE_FLAG_DYNAMIC) {160m->actionState = 0;161} else {162// If Mario hasn't turned his head 10 times yet, stay idle instead of going to sleep.163m->actionTimer++;164if (m->actionTimer < 10) {165m->actionState = 0;166}167}168}169}170}171172stationary_ground_step(m);173174return FALSE;175}176177void play_anim_sound(struct MarioState *m, u32 actionState, s32 animFrame, u32 sound) {178if (m->actionState == actionState && m->marioObj->header.gfx.animInfo.animFrame == animFrame) {179play_sound(sound, m->marioObj->header.gfx.cameraToObject);180}181}182183s32 act_start_sleeping(struct MarioState *m) {184#ifndef VERSION_JP185s32 animFrame;186#endif187188if (check_common_idle_cancels(m)) {189return TRUE;190}191192if (m->quicksandDepth > 30.0f) {193return set_mario_action(m, ACT_IN_QUICKSAND, 0);194}195196if (m->actionState == 4) {197return set_mario_action(m, ACT_SLEEPING, 0);198}199200switch (m->actionState) {201case 0:202#ifndef VERSION_JP203animFrame =204#endif205set_mario_animation(m, MARIO_ANIM_START_SLEEP_IDLE);206break;207208case 1:209#ifndef VERSION_JP210animFrame =211#endif212set_mario_animation(m, MARIO_ANIM_START_SLEEP_SCRATCH);213break;214215case 2:216#ifndef VERSION_JP217animFrame =218#endif219set_mario_animation(m, MARIO_ANIM_START_SLEEP_YAWN);220m->marioBodyState->eyeState = MARIO_EYES_HALF_CLOSED;221break;222223case 3:224#ifndef VERSION_JP225animFrame =226#endif227set_mario_animation(m, MARIO_ANIM_START_SLEEP_SITTING);228m->marioBodyState->eyeState = MARIO_EYES_HALF_CLOSED;229break;230}231232play_anim_sound(m, 1, 41, SOUND_ACTION_PAT_BACK);233play_anim_sound(m, 1, 49, SOUND_ACTION_PAT_BACK);234play_anim_sound(m, 3, 15, m->terrainSoundAddend + SOUND_ACTION_TERRAIN_BODY_HIT_GROUND);235236if (is_anim_at_end(m)) {237m->actionState++;238}239240#ifndef VERSION_JP241if (m->actionState == 2 && animFrame == -1) {242play_sound(SOUND_MARIO_YAWNING, m->marioObj->header.gfx.cameraToObject);243}244245if (m->actionState == 1 && animFrame == -1) {246play_sound(SOUND_MARIO_IMA_TIRED, m->marioObj->header.gfx.cameraToObject);247}248#else249if (m->actionState == 2) {250play_sound_if_no_flag(m, SOUND_MARIO_YAWNING, MARIO_MARIO_SOUND_PLAYED);251}252#endif253254stationary_ground_step(m);255return FALSE;256}257258s32 act_sleeping(struct MarioState *m) {259s32 animFrame;260if (m->input261& (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE262| INPUT_FIRST_PERSON | INPUT_STOMPED | INPUT_B_PRESSED | INPUT_Z_PRESSED)) {263return set_mario_action(m, ACT_WAKING_UP, m->actionState);264}265266if (m->quicksandDepth > 30.0f) {267return set_mario_action(m, ACT_WAKING_UP, m->actionState);268}269270if (m->pos[1] - find_floor_height_relative_polar(m, -0x8000, 60.0f) > 24.0f) {271return set_mario_action(m, ACT_WAKING_UP, m->actionState);272}273274m->marioBodyState->eyeState = MARIO_EYES_CLOSED;275stationary_ground_step(m);276switch (m->actionState) {277case 0:278animFrame = set_mario_animation(m, MARIO_ANIM_SLEEP_IDLE);279280if (animFrame == -1 && !m->actionTimer) {281lower_background_noise(2);282}283284if (animFrame == 2) {285play_sound(SOUND_MARIO_SNORING1, m->marioObj->header.gfx.cameraToObject);286}287288if (animFrame == 20) {289play_sound(SOUND_MARIO_SNORING2, m->marioObj->header.gfx.cameraToObject);290}291292if (is_anim_at_end(m)) {293m->actionTimer++;294if (m->actionTimer > 45) {295m->actionState++;296}297}298break;299300case 1:301if (set_mario_animation(m, MARIO_ANIM_SLEEP_START_LYING) == 18) {302play_mario_heavy_landing_sound(m, SOUND_ACTION_TERRAIN_BODY_HIT_GROUND);303}304305if (is_anim_at_end(m)) {306m->actionState++;307}308break;309310case 2:311animFrame = set_mario_animation(m, MARIO_ANIM_SLEEP_LYING);312#ifndef VERSION_JP313play_sound_if_no_flag(m, SOUND_MARIO_SNORING3, MARIO_ACTION_SOUND_PLAYED);314#else315if (animFrame == 2) {316play_sound(SOUND_MARIO_SNORING2, m->marioObj->header.gfx.cameraToObject);317}318319if (animFrame == 25) {320play_sound(SOUND_MARIO_SNORING1, m->marioObj->header.gfx.cameraToObject);321}322#endif323break;324}325return FALSE;326}327328s32 act_waking_up(struct MarioState *m) {329if (!m->actionTimer) {330stop_sound(SOUND_MARIO_SNORING1, m->marioObj->header.gfx.cameraToObject);331stop_sound(SOUND_MARIO_SNORING2, m->marioObj->header.gfx.cameraToObject);332#ifndef VERSION_JP333stop_sound(SOUND_MARIO_SNORING3, m->marioObj->header.gfx.cameraToObject);334#endif335raise_background_noise(2);336}337338if (m->input & INPUT_STOMPED) {339return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);340}341342if (m->input & INPUT_OFF_FLOOR) {343return set_mario_action(m, ACT_FREEFALL, 0);344}345346if (m->input & INPUT_ABOVE_SLIDE) {347return set_mario_action(m, ACT_BEGIN_SLIDING, 0);348}349350m->actionTimer++;351352if (m->actionTimer > 20) {353return set_mario_action(m, ACT_IDLE, 0);354}355356stationary_ground_step(m);357358set_mario_animation(m, !m->actionArg ? MARIO_ANIM_WAKE_FROM_SLEEP : MARIO_ANIM_WAKE_FROM_LYING);359360return FALSE;361}362363s32 act_shivering(struct MarioState *m) {364s32 animFrame;365366if (m->input & INPUT_STOMPED) {367return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);368}369370if (m->input & INPUT_OFF_FLOOR) {371return set_mario_action(m, ACT_FREEFALL, 0);372}373374if (m->input & INPUT_ABOVE_SLIDE) {375return set_mario_action(m, ACT_BEGIN_SLIDING, 0);376}377378if (m->input379& (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE380| INPUT_FIRST_PERSON | INPUT_STOMPED | INPUT_B_PRESSED | INPUT_Z_PRESSED)) {381m->actionState = 2;382}383384stationary_ground_step(m);385switch (m->actionState) {386case 0:387animFrame = set_mario_animation(m, MARIO_ANIM_SHIVERING_WARMING_HAND);388if (animFrame == 49) {389m->particleFlags |= PARTICLE_BREATH;390play_sound(SOUND_MARIO_PANTING_COLD, m->marioObj->header.gfx.cameraToObject);391}392if (animFrame == 7 || animFrame == 81) {393play_sound(SOUND_ACTION_CLAP_HANDS_COLD, m->marioObj->header.gfx.cameraToObject);394}395if (is_anim_past_end(m)) {396m->actionState = 1;397}398break;399400case 1:401animFrame = set_mario_animation(m, MARIO_ANIM_SHIVERING);402if (animFrame == 9 || animFrame == 25 || animFrame == 44) {403play_sound(SOUND_ACTION_CLAP_HANDS_COLD, m->marioObj->header.gfx.cameraToObject);404}405break;406407case 2:408set_mario_animation(m, MARIO_ANIM_SHIVERING_RETURN_TO_IDLE);409if (is_anim_past_end(m)) {410set_mario_action(m, ACT_IDLE, 0);411}412break;413}414return FALSE;415}416417s32 act_coughing(struct MarioState *m) {418s32 animFrame;419420if (check_common_idle_cancels(m)) {421return TRUE;422}423424stationary_ground_step(m);425animFrame = set_mario_animation(m, MARIO_ANIM_COUGHING);426if (animFrame == 25 || animFrame == 35) {427play_sound(SOUND_MARIO_COUGHING3, m->marioObj->header.gfx.cameraToObject);428}429430if (animFrame == 50 || animFrame == 58) {431play_sound(SOUND_MARIO_COUGHING2, m->marioObj->header.gfx.cameraToObject);432}433434if (animFrame == 71 || animFrame == 80) {435play_sound(SOUND_MARIO_COUGHING1, m->marioObj->header.gfx.cameraToObject);436}437438return FALSE;439}440441s32 act_hold_idle(struct MarioState *m) {442if (segmented_to_virtual(&bhvJumpingBox) == m->heldObj->behavior) {443return set_mario_action(m, ACT_CRAZY_BOX_BOUNCE, 0);444}445446if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {447return drop_and_set_mario_action(m, ACT_IDLE, 0);448}449450if (m->quicksandDepth > 30.0f) {451return drop_and_set_mario_action(m, ACT_IN_QUICKSAND, 0);452}453454if (check_common_hold_idle_cancels(m)) {455return TRUE;456}457458stationary_ground_step(m);459set_mario_animation(m, MARIO_ANIM_IDLE_WITH_LIGHT_OBJ);460return FALSE;461}462463s32 act_hold_heavy_idle(struct MarioState *m) {464if (m->input & INPUT_STOMPED) {465return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);466}467468if (m->input & INPUT_OFF_FLOOR) {469return drop_and_set_mario_action(m, ACT_FREEFALL, 0);470}471472if (m->input & INPUT_ABOVE_SLIDE) {473return drop_and_set_mario_action(m, ACT_BEGIN_SLIDING, 0);474}475476if (m->input & INPUT_NONZERO_ANALOG) {477return set_mario_action(m, ACT_HOLD_HEAVY_WALKING, 0);478}479480if (m->input & INPUT_B_PRESSED) {481return set_mario_action(m, ACT_HEAVY_THROW, 0);482}483484stationary_ground_step(m);485set_mario_animation(m, MARIO_ANIM_IDLE_HEAVY_OBJ);486return FALSE;487}488489s32 act_standing_against_wall(struct MarioState *m) {490if (m->input & INPUT_STOMPED) {491return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);492}493494if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE)) {495return check_common_action_exits(m);496}497498if (m->input & INPUT_FIRST_PERSON) {499return set_mario_action(m, ACT_FIRST_PERSON, 0);500}501502if (m->input & INPUT_B_PRESSED) {503return set_mario_action(m, ACT_PUNCHING, 0);504}505506set_mario_animation(m, MARIO_ANIM_STAND_AGAINST_WALL);507stationary_ground_step(m);508return FALSE;509}510511s32 act_in_quicksand(struct MarioState *m) {512if (m->quicksandDepth < 30.0f) {513return set_mario_action(m, ACT_IDLE, 0);514}515516if (check_common_idle_cancels(m)) {517return TRUE;518}519520if (m->quicksandDepth > 70.0f) {521set_mario_animation(m, MARIO_ANIM_DYING_IN_QUICKSAND);522} else {523set_mario_animation(m, MARIO_ANIM_IDLE_IN_QUICKSAND);524}525526stationary_ground_step(m);527return FALSE;528}529530s32 act_crouching(struct MarioState *m) {531if (m->input & INPUT_STOMPED) {532return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);533}534535if (m->input & INPUT_A_PRESSED) {536return set_jumping_action(m, ACT_BACKFLIP, 0);537}538539if (m->input & INPUT_OFF_FLOOR) {540return set_mario_action(m, ACT_FREEFALL, 0);541}542543if (m->input & INPUT_ABOVE_SLIDE) {544return set_mario_action(m, ACT_BEGIN_SLIDING, 0);545}546547if (m->input & INPUT_FIRST_PERSON) {548return set_mario_action(m, ACT_STOP_CROUCHING, 0);549}550551if (!(m->input & INPUT_Z_DOWN)) {552return set_mario_action(m, ACT_STOP_CROUCHING, 0);553}554555if (m->input & INPUT_NONZERO_ANALOG) {556return set_mario_action(m, ACT_START_CRAWLING, 0);557}558559if (m->input & INPUT_B_PRESSED) {560return set_mario_action(m, configRolling ? ACT_ROLL : ACT_PUNCHING, configRolling ? 0 : 9);561}562563stationary_ground_step(m);564set_mario_animation(m, MARIO_ANIM_CROUCHING);565return FALSE;566}567568s32 act_panting(struct MarioState *m) {569if (m->input & INPUT_STOMPED) {570return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);571}572573if (m->health >= 0x500) {574return set_mario_action(m, ACT_IDLE, 0);575}576577if (check_common_idle_cancels(m)) {578return TRUE;579}580581if (set_mario_animation(m, MARIO_ANIM_WALK_PANTING) == 1) {582play_sound(SOUND_MARIO_PANTING + ((gAudioRandom % 3U) << 0x10),583m->marioObj->header.gfx.cameraToObject);584}585586stationary_ground_step(m);587m->marioBodyState->eyeState = MARIO_EYES_HALF_CLOSED;588return FALSE;589}590591s32 act_hold_panting_unused(struct MarioState *m) {592if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {593return drop_and_set_mario_action(m, ACT_PANTING, 0);594}595596if (m->input & INPUT_STOMPED) {597return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);598}599600if (m->health >= 0x500) {601return set_mario_action(m, ACT_HOLD_IDLE, 0);602}603604if (check_common_hold_idle_cancels(m)) {605return TRUE;606}607608set_mario_animation(m, MARIO_ANIM_WALK_PANTING);609stationary_ground_step(m);610m->marioBodyState->eyeState = MARIO_EYES_HALF_CLOSED;611return FALSE;612}613614void stopping_step(struct MarioState *m, s32 animID, u32 action) {615stationary_ground_step(m);616set_mario_animation(m, animID);617if (is_anim_at_end(m)) {618set_mario_action(m, action, 0);619}620}621622s32 act_braking_stop(struct MarioState *m) {623if (m->input & INPUT_STOMPED) {624return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);625}626627if (m->input & INPUT_OFF_FLOOR) {628return set_mario_action(m, ACT_FREEFALL, 0);629}630631if (m->input & INPUT_B_PRESSED) {632return set_mario_action(m, ACT_PUNCHING, 0);633}634635if (!(m->input & INPUT_FIRST_PERSON)636&& m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE)) {637return check_common_action_exits(m);638}639640stopping_step(m, MARIO_ANIM_STOP_SKID, ACT_IDLE);641return FALSE;642}643644s32 act_butt_slide_stop(struct MarioState *m) {645if (m->input & INPUT_STOMPED) {646return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);647}648649if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE)) {650return check_common_action_exits(m);651}652653stopping_step(m, MARIO_ANIM_STOP_SLIDE, ACT_IDLE);654if (m->marioObj->header.gfx.animInfo.animFrame == 6) {655play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING);656}657658return FALSE;659}660661s32 act_hold_butt_slide_stop(struct MarioState *m) {662if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {663return drop_and_set_mario_action(m, ACT_IDLE, 0);664}665666if (m->input & INPUT_STOMPED) {667return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);668}669670if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE)) {671return check_common_hold_action_exits(m);672}673674if (m->input & INPUT_B_PRESSED) {675return set_mario_action(m, ACT_THROWING, 0);676}677678stopping_step(m, MARIO_ANIM_STAND_UP_FROM_SLIDING_WITH_LIGHT_OBJ, ACT_HOLD_IDLE);679return FALSE;680}681682s32 act_slide_kick_slide_stop(struct MarioState *m) {683if (m->input & INPUT_STOMPED) {684return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);685}686687if (m->input & INPUT_OFF_FLOOR) {688return drop_and_set_mario_action(m, ACT_FREEFALL, 0);689}690691stopping_step(m, MARIO_ANIM_CROUCH_FROM_SLIDE_KICK, ACT_CROUCHING);692return FALSE;693}694695s32 act_start_crouching(struct MarioState *m) {696if (m->input & INPUT_STOMPED) {697return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);698}699700if (m->input & INPUT_OFF_FLOOR) {701return set_mario_action(m, ACT_FREEFALL, 0);702}703704if (m->input & INPUT_A_PRESSED) {705return set_jumping_action(m, ACT_BACKFLIP, 0);706}707708if (m->input & INPUT_ABOVE_SLIDE) {709return set_mario_action(m, ACT_BEGIN_SLIDING, 0);710}711712stationary_ground_step(m);713if (configImprovedControls)714set_mario_anim_with_accel(m, MARIO_ANIM_START_CROUCHING, 0x26000);715else716set_mario_animation(m, MARIO_ANIM_START_CROUCHING);717718if (is_anim_past_end(m)) {719set_mario_action(m, ACT_CROUCHING, 0);720}721return FALSE;722}723724s32 act_stop_crouching(struct MarioState *m) {725if (m->input & INPUT_STOMPED) {726return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);727}728729if (m->input & INPUT_OFF_FLOOR) {730return set_mario_action(m, ACT_FREEFALL, 0);731}732733if (m->input & INPUT_A_PRESSED) {734return set_jumping_action(m, ACT_BACKFLIP, 0);735}736737if (m->input & INPUT_ABOVE_SLIDE) {738return set_mario_action(m, ACT_BEGIN_SLIDING, 0);739}740741stationary_ground_step(m);742if (configImprovedControls)743set_mario_anim_with_accel(m, MARIO_ANIM_STOP_CROUCHING, 0x26000);744else745set_mario_animation(m, MARIO_ANIM_STOP_CROUCHING);746if (is_anim_past_end(m)) {747set_mario_action(m, ACT_IDLE, 0);748}749return FALSE;750}751752s32 act_start_crawling(struct MarioState *m) {753if (m->input & INPUT_FIRST_PERSON) {754return set_mario_action(m, ACT_STOP_CROUCHING, 0);755}756757if (m->input & INPUT_OFF_FLOOR) {758return set_mario_action(m, ACT_FREEFALL, 0);759}760761if (m->input & INPUT_STOMPED) {762return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);763}764765if (m->input & INPUT_ABOVE_SLIDE) {766return set_mario_action(m, ACT_BEGIN_SLIDING, 0);767}768769stationary_ground_step(m);770set_mario_animation(m, MARIO_ANIM_START_CRAWLING);771if (is_anim_past_end(m)) {772set_mario_action(m, ACT_CRAWLING, 0);773}774775return FALSE;776}777778s32 act_stop_crawling(struct MarioState *m) {779if (m->input & INPUT_STOMPED) {780return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);781}782783if (m->input & INPUT_OFF_FLOOR) {784return set_mario_action(m, ACT_FREEFALL, 0);785}786787if (m->input & INPUT_ABOVE_SLIDE) {788return set_mario_action(m, ACT_BEGIN_SLIDING, 0);789}790791stationary_ground_step(m);792set_mario_animation(m, MARIO_ANIM_STOP_CRAWLING);793if (is_anim_past_end(m)) {794set_mario_action(m, ACT_CROUCHING, 0);795}796return FALSE;797}798799s32 act_shockwave_bounce(struct MarioState *m) {800s16 sp1E;801f32 sp18;802803if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_SHOCKWAVE) {804#if ENABLE_RUMBLE805queue_rumble_data(70, 40);806#endif807return hurt_and_set_mario_action(m, ACT_SHOCKED, 0, 4);808}809810if (m->actionTimer == 0) {811#if ENABLE_RUMBLE812queue_rumble_data(70, 40);813#endif814if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_KNOCKBACK_DMG) {815return hurt_and_set_mario_action(m, ACT_BACKWARD_GROUND_KB, 0, 0xc);816}817}818819if (++m->actionTimer == 48) {820return set_mario_action(m, ACT_IDLE, 0);821}822823sp1E = (m->actionTimer % 16) << 12;824sp18 = (f32)(((f32)(6 - m->actionTimer / 8) * 8.0f) + 4.0f);825mario_set_forward_vel(m, 0);826vec3f_set(m->vel, 0.0f, 0.0f, 0.0f);827if (sins(sp1E) >= 0.0f) {828m->pos[1] = sins(sp1E) * sp18 + m->floorHeight;829} else {830m->pos[1] = m->floorHeight - sins(sp1E) * sp18;831}832833vec3f_copy(m->marioObj->header.gfx.pos, m->pos);834vec3s_set(m->marioObj->header.gfx.angle, 0, m->faceAngle[1], 0);835set_mario_animation(m, MARIO_ANIM_A_POSE);836return FALSE;837}838839s32 landing_step(struct MarioState *m, s32 arg1, u32 action) {840stationary_ground_step(m);841set_mario_animation(m, arg1);842if (is_anim_at_end(m)) {843return set_mario_action(m, action, 0);844}845return FALSE;846}847848s32 check_common_landing_cancels(struct MarioState *m, u32 action) {849if (m->input & INPUT_STOMPED) {850return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);851}852853if (m->input & INPUT_FIRST_PERSON) {854return set_mario_action(m, ACT_IDLE, 0);855}856857if (m->input & INPUT_A_PRESSED) {858if (!action) {859return set_jump_from_landing(m);860} else {861return set_jumping_action(m, action, 0);862}863}864865if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE)) {866return check_common_action_exits(m);867}868869if (m->input & INPUT_B_PRESSED) {870return set_mario_action(m, ACT_PUNCHING, 0);871}872873return FALSE;874}875876s32 act_jump_land_stop(struct MarioState *m) {877if (check_common_landing_cancels(m, 0)) {878return TRUE;879}880881landing_step(m, MARIO_ANIM_LAND_FROM_SINGLE_JUMP, ACT_IDLE);882return FALSE;883}884885s32 act_double_jump_land_stop(struct MarioState *m) {886if (check_common_landing_cancels(m, 0)) {887return TRUE;888}889890landing_step(m, MARIO_ANIM_LAND_FROM_DOUBLE_JUMP, ACT_IDLE);891return FALSE;892}893894s32 act_side_flip_land_stop(struct MarioState *m) {895if (check_common_landing_cancels(m, 0)) {896return TRUE;897}898899landing_step(m, MARIO_ANIM_SLIDEFLIP_LAND, ACT_IDLE);900m->marioObj->header.gfx.angle[1] += 0x8000;901return FALSE;902}903904s32 act_freefall_land_stop(struct MarioState *m) {905if (check_common_landing_cancels(m, 0)) {906return TRUE;907}908909landing_step(m, MARIO_ANIM_GENERAL_LAND, ACT_IDLE);910return FALSE;911}912913s32 act_triple_jump_land_stop(struct MarioState *m) {914if (check_common_landing_cancels(m, ACT_JUMP)) {915return TRUE;916}917918landing_step(m, MARIO_ANIM_TRIPLE_JUMP_LAND, ACT_IDLE);919return FALSE;920}921922s32 act_backflip_land_stop(struct MarioState *m) {923if (!(m->input & INPUT_Z_DOWN) || m->marioObj->header.gfx.animInfo.animFrame >= 6) {924m->input &= ~INPUT_A_PRESSED;925}926927if (check_common_landing_cancels(m, ACT_BACKFLIP)) {928return TRUE;929}930931landing_step(m, MARIO_ANIM_TRIPLE_JUMP_LAND, ACT_IDLE);932return FALSE;933}934935s32 act_lava_boost_land(struct MarioState *m) {936m->input &= ~(INPUT_FIRST_PERSON | INPUT_B_PRESSED);937938if (check_common_landing_cancels(m, 0)) {939return TRUE;940}941942landing_step(m, MARIO_ANIM_STAND_UP_FROM_LAVA_BOOST, ACT_IDLE);943return FALSE;944}945946s32 act_long_jump_land_stop(struct MarioState *m) {947m->input &= ~INPUT_B_PRESSED;948if (check_common_landing_cancels(m, ACT_JUMP)) {949return TRUE;950}951952landing_step(m, !m->marioObj->oMarioLongJumpIsSlow ? MARIO_ANIM_CROUCH_FROM_FAST_LONGJUMP953: MARIO_ANIM_CROUCH_FROM_SLOW_LONGJUMP,954ACT_CROUCHING);955return FALSE;956}957958s32 act_hold_jump_land_stop(struct MarioState *m) {959if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {960return drop_and_set_mario_action(m, ACT_IDLE, 0);961}962963if (m->input & INPUT_STOMPED) {964return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);965}966967if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE)) {968return check_common_hold_action_exits(m);969}970971if (m->input & INPUT_B_PRESSED) {972return set_mario_action(m, ACT_THROWING, 0);973}974975landing_step(m, MARIO_ANIM_JUMP_LAND_WITH_LIGHT_OBJ, ACT_HOLD_IDLE);976return FALSE;977}978979s32 act_hold_freefall_land_stop(struct MarioState *m) {980if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_DROP_OBJECT) {981return drop_and_set_mario_action(m, ACT_IDLE, 0);982}983984if (m->input & INPUT_STOMPED) {985return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);986}987988if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE)) {989return check_common_hold_action_exits(m);990}991992if (m->input & INPUT_B_PRESSED) {993return set_mario_action(m, ACT_THROWING, 0);994}995landing_step(m, MARIO_ANIM_FALL_LAND_WITH_LIGHT_OBJ, ACT_HOLD_IDLE);996return FALSE;997}998999s32 act_air_throw_land(struct MarioState *m) {1000if (m->input & INPUT_STOMPED) {1001return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);1002}10031004if (m->input & INPUT_OFF_FLOOR) {1005return set_mario_action(m, ACT_FREEFALL, 0);1006}10071008if (++m->actionTimer == 4) {1009mario_throw_held_object(m);1010}10111012landing_step(m, MARIO_ANIM_THROW_LIGHT_OBJECT, ACT_IDLE);1013return FALSE;1014}10151016s32 act_twirl_land(struct MarioState *m) {1017m->actionState = 1;1018if (m->input & INPUT_STOMPED) {1019return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);1020}10211022if (m->input & INPUT_OFF_FLOOR) {1023return set_mario_action(m, ACT_FREEFALL, 0);1024}10251026stationary_ground_step(m);1027set_mario_animation(m, MARIO_ANIM_TWIRL_LAND);1028if (m->angleVel[1] > 0) {1029m->angleVel[1] -= 0x400;1030if (m->angleVel[1] < 0) {1031m->angleVel[1] = 0;1032}10331034m->twirlYaw += m->angleVel[1];1035}10361037m->marioObj->header.gfx.angle[1] += m->twirlYaw;1038if (is_anim_at_end(m) && m->angleVel[1] == 0) {1039m->faceAngle[1] += m->twirlYaw;1040set_mario_action(m, ACT_IDLE, 0);1041}10421043return FALSE;1044}10451046s32 act_ground_pound_land(struct MarioState *m) {1047m->actionState = 1;1048if (configFlashbackGroundPound) {1049if (m->input & INPUT_OFF_FLOOR) {1050return set_mario_action(m, ACT_FREEFALL, 0);1051}1052else if (m->input & INPUT_ABOVE_SLIDE) {1053return set_mario_action(m, ACT_BUTT_SLIDE, 0);1054}1055if (m->input & INPUT_Z_DOWN) {1056if (gPlayer1Controller->stickX != 0 || gPlayer1Controller->stickY != 0) {1057m->vel[1] = 2.0f;1058mario_set_forward_vel(m, 56.0f);1059m->faceAngle[1] = m->intendedYaw;1060return set_mario_action(m, ACT_SLIDE_KICK, 0);1061}1062else {1063return set_mario_action(m, ACT_CROUCHING, 0);1064}1065}1066else if ((configGroundPoundJump) && (gPlayer1Controller->buttonDown & A_BUTTON)) {1067set_mario_action(m, ACT_DOUBLE_JUMP, 0);1068m->vel[1] = 60.0f;1069play_mario_sound(m, SOUND_ACTION_TERRAIN_HEAVY_LANDING, SOUND_MARIO_YAHOO);1070return TRUE;1071}1072else {1073set_mario_action(m, ACT_BACKWARD_ROLLOUT, 0);1074m->actionState = 1;1075m->vel[1] = 40.0f;1076mario_set_forward_vel(m, 0.0f);1077return TRUE;1078}1079}1080else {1081if ((configGroundPoundJump) && (gPlayer1Controller->buttonPressed & A_BUTTON)) {1082set_mario_action(m, ACT_DOUBLE_JUMP, 0);1083m->vel[1] = 60.0f;1084play_mario_sound(m, SOUND_ACTION_TERRAIN_HEAVY_LANDING, SOUND_MARIO_YAHOO);1085return TRUE;1086}10871088if (m->input & INPUT_STOMPED) {1089return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0);1090}10911092if (m->input & INPUT_OFF_FLOOR) {1093return set_mario_action(m, ACT_FREEFALL, 0);1094}10951096if (m->input & INPUT_ABOVE_SLIDE) {1097return set_mario_action(m, ACT_BUTT_SLIDE, 0);1098}1099}11001101landing_step(m, MARIO_ANIM_GROUND_POUND_LANDING, ACT_BUTT_SLIDE_STOP);1102return FALSE;1103}11041105s32 act_first_person(struct MarioState *m) {1106s32 sp1C = (m->input & (INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE | INPUT_STOMPED)) != 0;11071108if (m->actionState == 0) {1109lower_background_noise(2);1110set_camera_mode(m->area->camera, CAMERA_MODE_C_UP, 0x10);1111m->actionState = 1;1112} else if (!(m->input & INPUT_FIRST_PERSON) || sp1C) {1113raise_background_noise(2);1114// Go back to the last camera mode1115set_camera_mode(m->area->camera, -1, 1);1116return set_mario_action(m, ACT_IDLE, 0);1117}11181119if (m->floor->type == SURFACE_LOOK_UP_WARP1120&& save_file_get_total_star_count(gCurrSaveFileNum - 1, COURSE_MIN - 1, COURSE_MAX - 1) >= 10) {1121s16 sp1A = m->statusForCamera->headRotation[0];1122s16 sp18 = ((m->statusForCamera->headRotation[1] * 4) / 3) + m->faceAngle[1];1123if (sp1A == -0x1800 && (sp18 < -0x6FFF || sp18 >= 0x7000)) {1124level_trigger_warp(m, WARP_OP_UNKNOWN_01);1125}1126}11271128stationary_ground_step(m);1129set_mario_animation(m, MARIO_ANIM_FIRST_PERSON);1130return FALSE;1131}11321133s32 check_common_stationary_cancels(struct MarioState *m) {1134if (m->pos[1] < m->waterLevel - 100) {1135if (m->action == ACT_SPAWN_SPIN_LANDING) {1136load_level_init_text(0);1137}1138update_mario_sound_and_camera(m);1139return set_water_plunge_action(m);1140}11411142if (m->input & INPUT_SQUISHED) {1143update_mario_sound_and_camera(m);1144return drop_and_set_mario_action(m, ACT_SQUISHED, 0);1145}11461147if (m->action != ACT_UNKNOWN_0002020E) {1148if (m->health < 0x100) {1149update_mario_sound_and_camera(m);1150return drop_and_set_mario_action(m, ACT_STANDING_DEATH, 0);1151}1152}1153return FALSE;1154}11551156s32 mario_execute_stationary_action(struct MarioState *m) {1157s32 cancel;11581159if (check_common_stationary_cancels(m)) {1160return TRUE;1161}11621163if (mario_update_quicksand(m, 0.5f)) {1164return TRUE;1165}11661167/* clang-format off */1168switch (m->action) {1169case ACT_IDLE: cancel = act_idle(m); break;1170case ACT_START_SLEEPING: cancel = act_start_sleeping(m); break;1171case ACT_SLEEPING: cancel = act_sleeping(m); break;1172case ACT_WAKING_UP: cancel = act_waking_up(m); break;1173case ACT_PANTING: cancel = act_panting(m); break;1174case ACT_HOLD_PANTING_UNUSED: cancel = act_hold_panting_unused(m); break;1175case ACT_HOLD_IDLE: cancel = act_hold_idle(m); break;1176case ACT_HOLD_HEAVY_IDLE: cancel = act_hold_heavy_idle(m); break;1177case ACT_IN_QUICKSAND: cancel = act_in_quicksand(m); break;1178case ACT_STANDING_AGAINST_WALL: cancel = act_standing_against_wall(m); break;1179case ACT_COUGHING: cancel = act_coughing(m); break;1180case ACT_SHIVERING: cancel = act_shivering(m); break;1181case ACT_CROUCHING: cancel = act_crouching(m); break;1182case ACT_START_CROUCHING: cancel = act_start_crouching(m); break;1183case ACT_STOP_CROUCHING: cancel = act_stop_crouching(m); break;1184case ACT_START_CRAWLING: cancel = act_start_crawling(m); break;1185case ACT_STOP_CRAWLING: cancel = act_stop_crawling(m); break;1186case ACT_SLIDE_KICK_SLIDE_STOP: cancel = act_slide_kick_slide_stop(m); break;1187case ACT_SHOCKWAVE_BOUNCE: cancel = act_shockwave_bounce(m); break;1188case ACT_FIRST_PERSON: cancel = act_first_person(m); break;1189case ACT_JUMP_LAND_STOP: cancel = act_jump_land_stop(m); break;1190case ACT_DOUBLE_JUMP_LAND_STOP: cancel = act_double_jump_land_stop(m); break;1191case ACT_FREEFALL_LAND_STOP: cancel = act_freefall_land_stop(m); break;1192case ACT_SIDE_FLIP_LAND_STOP: cancel = act_side_flip_land_stop(m); break;1193case ACT_HOLD_JUMP_LAND_STOP: cancel = act_hold_jump_land_stop(m); break;1194case ACT_HOLD_FREEFALL_LAND_STOP: cancel = act_hold_freefall_land_stop(m); break;1195case ACT_AIR_THROW_LAND: cancel = act_air_throw_land(m); break;1196case ACT_LAVA_BOOST_LAND: cancel = act_lava_boost_land(m); break;1197case ACT_TWIRL_LAND: cancel = act_twirl_land(m); break;1198case ACT_TRIPLE_JUMP_LAND_STOP: cancel = act_triple_jump_land_stop(m); break;1199case ACT_BACKFLIP_LAND_STOP: cancel = act_backflip_land_stop(m); break;1200case ACT_LONG_JUMP_LAND_STOP: cancel = act_long_jump_land_stop(m); break;1201case ACT_GROUND_POUND_LAND: cancel = act_ground_pound_land(m); break;1202case ACT_BRAKING_STOP: cancel = act_braking_stop(m); break;1203case ACT_BUTT_SLIDE_STOP: cancel = act_butt_slide_stop(m); break;1204case ACT_HOLD_BUTT_SLIDE_STOP: cancel = act_hold_butt_slide_stop(m); break;1205}1206/* clang-format on */12071208if (!cancel && (m->input & INPUT_IN_WATER)) {1209m->particleFlags |= PARTICLE_IDLE_WATER_WAVE;1210}12111212return cancel;1213}121412151216