Super Mario 64 Source
A Super Mario 64 decompilation, brought to you by a bunch of clever folks.
Functions | Variables
mario.c File Reference
#include <ultra64.h>
#include "sm64.h"
#include "mario.h"
#include "area.h"
#include "audio/external.h"
#include "behavior_actions.h"
#include "behavior_data.h"
#include "camera.h"
#include "mario_misc.h"
#include "display.h"
#include "game.h"
#include "engine/graph_node.h"
#include "interaction.h"
#include "level_update.h"
#include "memory.h"
#include "main.h"
#include "mario_actions_object.h"
#include "mario_actions_automatic.h"
#include "mario_actions_cutscene.h"
#include "mario_actions_submerged.h"
#include "mario_actions_airborne.h"
#include "mario_actions_moving.h"
#include "mario_actions_stationary.h"
#include "mario_step.h"
#include "engine/math_util.h"
#include "object_fields.h"
#include "object_helpers.h"
#include "print.h"
#include "save_file.h"
#include "sound_init.h"
#include "engine/surface_collision.h"

Functions

s32 is_anim_at_end (struct MarioState *m)
 Checks if Mario's animation has reached its end point. More...
 
s32 is_anim_past_end (struct MarioState *m)
 Checks if Mario's animation has surpassed 2 frames before its end point. More...
 
s16 set_mario_animation (struct MarioState *m, s32 targetAnimID)
 Sets Mario's animation without any acceleration, running at its default rate. More...
 
s16 set_mario_anim_with_accel (struct MarioState *m, s32 targetAnimID, s32 accel)
 Sets Mario's animation where the animation is sped up or slowed down via acceleration. More...
 
void set_anim_to_frame (struct MarioState *m, s16 animFrame)
 Sets the animation to a specific "next" frame from the frame given. More...
 
s32 is_anim_past_frame (struct MarioState *m, s16 animFrame)
 
s16 find_mario_anim_flags_and_translation (struct Object *obj, s32 yaw, Vec3s translation)
 Rotates the animation's translation into the global coordinate system and returns the animation's flags. More...
 
void update_mario_pos_for_anim (struct MarioState *m)
 Updates Mario's position from his animation's translation. More...
 
s16 return_mario_anim_y_translation (struct MarioState *m)
 Finds the vertical translation from Mario's animation. More...
 
void play_sound_if_no_flag (struct MarioState *m, u32 soundBits, u32 flags)
 Plays a sound if if Mario doesn't have the flag being checked. More...
 
void play_mario_action_sound (struct MarioState *m)
 Plays an action sound if one has not been played since the last action change. More...
 
void adjust_sound_for_speed (struct MarioState *m)
 Adjusts the volume/pitch of sounds from Mario's speed. More...
 
void play_sound_and_spawn_particles (struct MarioState *m, u32 soundBits, u32 waveParticleType)
 Spawns particles if the step sound says to, then either plays a step sound or relevant other sound. More...
 
void play_mario_environment_sound (struct MarioState *m, u32 soundBits, u32 waveParticleType)
 Plays an environmental sound if one has not been played since the last action change. More...
 
void play_mario_step_sound (struct MarioState *m, u32 soundBits)
 Plays a step sound, accounting for metal cap. More...
 
void play_mario_landing_sound (struct MarioState *m, u32 soundBits)
 Plays a landing sound, accounting for metal cap. More...
 
void play_mario_heavy_landing_sound (struct MarioState *m, u32 soundBits)
 Plays a heavy landing (ground pound, etc.) sound, accounting for metal cap. More...
 
void play_mario_knockback_sound (struct MarioState *m, u32 soundBits)
 Plays a knockback sound, accounting for metal cap. More...
 
void play_mario_sound (struct MarioState *m, s32 primarySoundBits, s32 scondarySoundBits)
 Plays an environment and action noise relevant to what was passed into the function. More...
 
void mario_set_forward_vel (struct MarioState *m, f32 forwardVel)
 Sets Mario's other velocities from his forward speed. More...
 
s32 mario_get_floor_class (struct MarioState *m)
 Returns the slipperines class of Mario's floor. More...
 
u32 mario_get_step_noise (struct MarioState *m)
 Finds and returns Mario's step noise/type. More...
 
struct Surfaceresolve_and_return_wall_collisions (Vec3f pos, f32 offset, f32 radius)
 Collides with walls and returns the most recent wall. More...
 
f32 vec3f_find_ceil (Vec3f pos, f32 height, struct Surface **ceil)
 Finds the ceiling from a vec3f horizontally and a height (with 80 vertical buffer). More...
 
s32 mario_facing_downhill (struct MarioState *m, s32 turnYaw)
 Determines if Mario is facing "downhill.". More...
 
u32 mario_floor_is_slippery (struct MarioState *m)
 Determines if a surface is slippery based on the surface class. More...
 
s32 mario_floor_is_slope (struct MarioState *m)
 Determines if a surface is a slope based on the surface class. More...
 
s32 mario_floor_is_steep (struct MarioState *m)
 Determines if a surface is steep based on the surface class. More...
 
f32 find_floor_height_relative_polar (struct MarioState *m, s16 angleFromMario, f32 distFromMario)
 Finds the floor height relative from Mario given polar displacement. More...
 
s16 find_floor_slope (struct MarioState *m, s16 yawOffset)
 Returns the slope of the floor based off points around Mario. More...
 
void update_mario_sound_and_camera (struct MarioState *m)
 Adjusts Mario's camera and sound based on his action status. More...
 
void set_steep_jump_action (struct MarioState *m)
 Transitions Mario to a steep jump action. More...
 
static void set_mario_y_vel_based_on_fspeed (struct MarioState *m, f32 initialVelY, f32 multiplier)
 Set's Marios vertical speed from his forward speed. More...
 
static u32 set_mario_action_airborne (struct MarioState *m, u32 action, u32 actionArg)
 Transitions for a variety of airborne actions. More...
 
static u32 set_mario_action_moving (struct MarioState *m, u32 action, UNUSED u32 actionArg)
 Transitions for a variety of moving actions. More...
 
static u32 set_mario_action_submerged (struct MarioState *m, u32 action, UNUSED u32 actionArg)
 Transition for certain submerged actions, which is actually just the metal jump actions. More...
 
static u32 set_mario_action_cutscene (struct MarioState *m, u32 action, UNUSED u32 actionArg)
 Transitions for a variety of cutscene actions. More...
 
u32 set_mario_action (struct MarioState *m, u32 action, u32 actionArg)
 Puts Mario into a given action, putting Mario through the appropriate specific function if needed. More...
 
s32 set_jump_from_landing (struct MarioState *m)
 Puts Mario into a specific jumping action from a landing action. More...
 
s32 set_jumping_action (struct MarioState *m, u32 action, u32 actionArg)
 Puts Mario in a given action, as long as it is not overruled by either a quicksand or steep jump. More...
 
s32 drop_and_set_mario_action (struct MarioState *m, u32 action, u32 actionArg)
 Drop anything Mario is holding and set a new action. More...
 
s32 hurt_and_set_mario_action (struct MarioState *m, u32 action, u32 actionArg, s16 hurtCounter)
 Increment Mario's hurt counter and set a new action. More...
 
s32 check_common_action_exits (struct MarioState *m)
 Checks a variety of inputs for common transitions between many different actions. More...
 
s32 check_common_hold_action_exits (struct MarioState *m)
 Checks a variety of inputs for common transitions between many different object holding actions. More...
 
s32 transition_submerged_to_walking (struct MarioState *m)
 Transitions Mario from a submerged action to a walking action. More...
 
s32 set_water_plunge_action (struct MarioState *m)
 This is the transition function typically for entering a submerged action for a non-submerged action. More...
 
void squish_mario_model (struct MarioState *m)
 Applies the squish to Mario's model via scaling. More...
 
void debug_print_speed_action_normal (struct MarioState *m)
 Debug function that prints floor normal, velocity, and action information. More...
 
void update_mario_button_inputs (struct MarioState *m)
 Update the button inputs for Mario. More...
 
void update_mario_joystick_inputs (struct MarioState *m)
 Updates the joystick intended magnitude. More...
 
void update_mario_geometry_inputs (struct MarioState *m)
 Resolves wall collisions, and updates a variety of inputs. More...
 
void update_mario_inputs (struct MarioState *m)
 Handles Mario's input flags as well as a couple timers. More...
 
void set_submerged_cam_preset_and_spawn_bubbles (struct MarioState *m)
 Set's the camera preset for submerged action behaviors. More...
 
void update_mario_health (struct MarioState *m)
 Both increments and decrements Mario's HP. More...
 
void update_mario_info_for_cam (struct MarioState *m)
 Updates some basic info for camera usage. More...
 
void mario_reset_bodystate (struct MarioState *m)
 Resets Mario's model, done every time an action is executed. More...
 
void sink_mario_in_quicksand (struct MarioState *m)
 Adjusts Mario's graphical height for quicksand. More...
 
u32 update_and_return_cap_flags (struct MarioState *m)
 Updates the cap flags mainly based on the cap timer. More...
 
void mario_update_hitbox_and_cap_model (struct MarioState *m)
 Updates the Mario's cap, rendering, and hitbox. More...
 
static void debug_update_mario_cap (u16 button, s32 flags, u16 capTimer, u16 capMusic)
 An unused and possibly a debug function. More...
 
s32 execute_mario_action (UNUSED struct Object *o)
 Main function for executing Mario's behavior. More...
 
void init_mario (void)
 
void init_mario_from_save_file (void)
 

Variables

u32 unused80339F10
 
s8 filler80339F1C [20]
 
s8 sTerrainStepNoises [7][6]
 The step noises organized by terrain types by surface classes. More...
 
u8 sSquishScaleOverTime [16]
 These are the scaling values for the x and z axis for Mario when he is close to unsquishing. More...
 
u64 sCapFlickerFrames = 0x4444449249255555
 Is a binary representation of the frames to flicker Mario's cap when the timer is running out. More...
 

Function Documentation

◆ adjust_sound_for_speed()

void adjust_sound_for_speed ( struct MarioState m)

Adjusts the volume/pitch of sounds from Mario's speed.

◆ check_common_action_exits()

s32 check_common_action_exits ( struct MarioState m)

Checks a variety of inputs for common transitions between many different actions.

A common variant of the below function.

◆ check_common_hold_action_exits()

s32 check_common_hold_action_exits ( struct MarioState m)

Checks a variety of inputs for common transitions between many different object holding actions.

A holding variant of the above function.

◆ debug_print_speed_action_normal()

void debug_print_speed_action_normal ( struct MarioState m)

Debug function that prints floor normal, velocity, and action information.

◆ debug_update_mario_cap()

static void debug_update_mario_cap ( u16  button,
s32  flags,
u16  capTimer,
u16  capMusic 
)
static

An unused and possibly a debug function.

Z + another button input sets Mario with a different cap.

◆ drop_and_set_mario_action()

s32 drop_and_set_mario_action ( struct MarioState m,
u32  action,
u32  actionArg 
)

Drop anything Mario is holding and set a new action.

◆ execute_mario_action()

s32 execute_mario_action ( UNUSED struct Object o)

Main function for executing Mario's behavior.

◆ find_floor_height_relative_polar()

f32 find_floor_height_relative_polar ( struct MarioState m,
s16  angleFromMario,
f32  distFromMario 
)

Finds the floor height relative from Mario given polar displacement.

◆ find_floor_slope()

s16 find_floor_slope ( struct MarioState m,
s16  yawOffset 
)

Returns the slope of the floor based off points around Mario.

If Mario is near OOB, these floorY's can sometimes be -11000.

◆ find_mario_anim_flags_and_translation()

s16 find_mario_anim_flags_and_translation ( struct Object obj,
s32  yaw,
Vec3s  translation 
)

Rotates the animation's translation into the global coordinate system and returns the animation's flags.

◆ hurt_and_set_mario_action()

s32 hurt_and_set_mario_action ( struct MarioState m,
u32  action,
u32  actionArg,
s16  hurtCounter 
)

Increment Mario's hurt counter and set a new action.

◆ init_mario()

void init_mario ( void  )

◆ init_mario_from_save_file()

void init_mario_from_save_file ( void  )

◆ is_anim_at_end()

s32 is_anim_at_end ( struct MarioState m)

Checks if Mario's animation has reached its end point.

◆ is_anim_past_end()

s32 is_anim_past_end ( struct MarioState m)

Checks if Mario's animation has surpassed 2 frames before its end point.

◆ is_anim_past_frame()

s32 is_anim_past_frame ( struct MarioState m,
s16  animFrame 
)

◆ mario_facing_downhill()

s32 mario_facing_downhill ( struct MarioState m,
s32  turnYaw 
)

Determines if Mario is facing "downhill.".

◆ mario_floor_is_slippery()

u32 mario_floor_is_slippery ( struct MarioState m)

Determines if a surface is slippery based on the surface class.

◆ mario_floor_is_slope()

s32 mario_floor_is_slope ( struct MarioState m)

Determines if a surface is a slope based on the surface class.

◆ mario_floor_is_steep()

s32 mario_floor_is_steep ( struct MarioState m)

Determines if a surface is steep based on the surface class.

◆ mario_get_floor_class()

s32 mario_get_floor_class ( struct MarioState m)

Returns the slipperines class of Mario's floor.

◆ mario_get_step_noise()

u32 mario_get_step_noise ( struct MarioState m)

Finds and returns Mario's step noise/type.

Depends on surfaces and terrain.

◆ mario_reset_bodystate()

void mario_reset_bodystate ( struct MarioState m)

Resets Mario's model, done every time an action is executed.

◆ mario_set_forward_vel()

void mario_set_forward_vel ( struct MarioState m,
f32  forwardVel 
)

Sets Mario's other velocities from his forward speed.

◆ mario_update_hitbox_and_cap_model()

void mario_update_hitbox_and_cap_model ( struct MarioState m)

Updates the Mario's cap, rendering, and hitbox.

(Pause buffered hitstun) Since the global timer increments while paused,

◆ play_mario_action_sound()

void play_mario_action_sound ( struct MarioState m)

Plays an action sound if one has not been played since the last action change.

◆ play_mario_environment_sound()

void play_mario_environment_sound ( struct MarioState m,
u32  soundBits,
u32  waveParticleType 
)

Plays an environmental sound if one has not been played since the last action change.

◆ play_mario_heavy_landing_sound()

void play_mario_heavy_landing_sound ( struct MarioState m,
u32  soundBits 
)

Plays a heavy landing (ground pound, etc.) sound, accounting for metal cap.

◆ play_mario_knockback_sound()

void play_mario_knockback_sound ( struct MarioState m,
u32  soundBits 
)

Plays a knockback sound, accounting for metal cap.

◆ play_mario_landing_sound()

void play_mario_landing_sound ( struct MarioState m,
u32  soundBits 
)

Plays a landing sound, accounting for metal cap.

◆ play_mario_sound()

void play_mario_sound ( struct MarioState m,
s32  primarySoundBits,
s32  scondarySoundBits 
)

Plays an environment and action noise relevant to what was passed into the function.

◆ play_mario_step_sound()

void play_mario_step_sound ( struct MarioState m,
u32  soundBits 
)

Plays a step sound, accounting for metal cap.

◆ play_sound_and_spawn_particles()

void play_sound_and_spawn_particles ( struct MarioState m,
u32  soundBits,
u32  waveParticleType 
)

Spawns particles if the step sound says to, then either plays a step sound or relevant other sound.

◆ play_sound_if_no_flag()

void play_sound_if_no_flag ( struct MarioState m,
u32  soundBits,
u32  flags 
)

Plays a sound if if Mario doesn't have the flag being checked.

◆ resolve_and_return_wall_collisions()

struct Surface* resolve_and_return_wall_collisions ( Vec3f  pos,
f32  offset,
f32  radius 
)

Collides with walls and returns the most recent wall.

◆ return_mario_anim_y_translation()

s16 return_mario_anim_y_translation ( struct MarioState m)

Finds the vertical translation from Mario's animation.

◆ set_anim_to_frame()

void set_anim_to_frame ( struct MarioState m,
s16  animFrame 
)

Sets the animation to a specific "next" frame from the frame given.

◆ set_jump_from_landing()

s32 set_jump_from_landing ( struct MarioState m)

Puts Mario into a specific jumping action from a landing action.

◆ set_jumping_action()

s32 set_jumping_action ( struct MarioState m,
u32  action,
u32  actionArg 
)

Puts Mario in a given action, as long as it is not overruled by either a quicksand or steep jump.

◆ set_mario_action()

u32 set_mario_action ( struct MarioState m,
u32  action,
u32  actionArg 
)

Puts Mario into a given action, putting Mario through the appropriate specific function if needed.

◆ set_mario_action_airborne()

static u32 set_mario_action_airborne ( struct MarioState m,
u32  action,
u32  actionArg 
)
static

Transitions for a variety of airborne actions.

(BLJ's) This properly handles long jumps from getting forward speed with

◆ set_mario_action_cutscene()

static u32 set_mario_action_cutscene ( struct MarioState m,
u32  action,
UNUSED u32  actionArg 
)
static

Transitions for a variety of cutscene actions.

◆ set_mario_action_moving()

static u32 set_mario_action_moving ( struct MarioState m,
u32  action,
UNUSED u32  actionArg 
)
static

Transitions for a variety of moving actions.

◆ set_mario_action_submerged()

static u32 set_mario_action_submerged ( struct MarioState m,
u32  action,
UNUSED u32  actionArg 
)
static

Transition for certain submerged actions, which is actually just the metal jump actions.

◆ set_mario_anim_with_accel()

s16 set_mario_anim_with_accel ( struct MarioState m,
s32  targetAnimID,
s32  accel 
)

Sets Mario's animation where the animation is sped up or slowed down via acceleration.

◆ set_mario_animation()

s16 set_mario_animation ( struct MarioState m,
s32  targetAnimID 
)

Sets Mario's animation without any acceleration, running at its default rate.

◆ set_mario_y_vel_based_on_fspeed()

static void set_mario_y_vel_based_on_fspeed ( struct MarioState m,
f32  initialVelY,
f32  multiplier 
)
static

Set's Marios vertical speed from his forward speed.

◆ set_steep_jump_action()

void set_steep_jump_action ( struct MarioState m)

Transitions Mario to a steep jump action.

((s16)0x8000) has undefined behavior. Therefore, this downcast has

◆ set_submerged_cam_preset_and_spawn_bubbles()

void set_submerged_cam_preset_and_spawn_bubbles ( struct MarioState m)

Set's the camera preset for submerged action behaviors.

◆ set_water_plunge_action()

s32 set_water_plunge_action ( struct MarioState m)

This is the transition function typically for entering a submerged action for a non-submerged action.

This also applies the water surface camera preset.

◆ sink_mario_in_quicksand()

void sink_mario_in_quicksand ( struct MarioState m)

Adjusts Mario's graphical height for quicksand.

◆ squish_mario_model()

void squish_mario_model ( struct MarioState m)

Applies the squish to Mario's model via scaling.

◆ transition_submerged_to_walking()

s32 transition_submerged_to_walking ( struct MarioState m)

Transitions Mario from a submerged action to a walking action.

◆ update_and_return_cap_flags()

u32 update_and_return_cap_flags ( struct MarioState m)

Updates the cap flags mainly based on the cap timer.

◆ update_mario_button_inputs()

void update_mario_button_inputs ( struct MarioState m)

Update the button inputs for Mario.

◆ update_mario_geometry_inputs()

void update_mario_geometry_inputs ( struct MarioState m)

Resolves wall collisions, and updates a variety of inputs.

◆ update_mario_health()

void update_mario_health ( struct MarioState m)

Both increments and decrements Mario's HP.

◆ update_mario_info_for_cam()

void update_mario_info_for_cam ( struct MarioState m)

Updates some basic info for camera usage.

◆ update_mario_inputs()

void update_mario_inputs ( struct MarioState m)

Handles Mario's input flags as well as a couple timers.

◆ update_mario_joystick_inputs()

void update_mario_joystick_inputs ( struct MarioState m)

Updates the joystick intended magnitude.

◆ update_mario_pos_for_anim()

void update_mario_pos_for_anim ( struct MarioState m)

Updates Mario's position from his animation's translation.

◆ update_mario_sound_and_camera()

void update_mario_sound_and_camera ( struct MarioState m)

Adjusts Mario's camera and sound based on his action status.

◆ vec3f_find_ceil()

f32 vec3f_find_ceil ( Vec3f  pos,
f32  height,
struct Surface **  ceil 
)

Finds the ceiling from a vec3f horizontally and a height (with 80 vertical buffer).

Variable Documentation

◆ filler80339F1C

s8 filler80339F1C[20]

◆ sCapFlickerFrames

u64 sCapFlickerFrames = 0x4444449249255555

Is a binary representation of the frames to flicker Mario's cap when the timer is running out.

Equals [1000]^5 . [100]^8 . [10]^9 . [1] in binary, which is 100010001000100010001001001001001001001001001010101010101010101.

◆ sSquishScaleOverTime

u8 sSquishScaleOverTime[16]
Initial value:
= { 0x46, 0x32, 0x32, 0x3C, 0x46, 0x50, 0x50, 0x3C,
0x28, 0x14, 0x14, 0x1E, 0x32, 0x3C, 0x3C, 0x28 }

These are the scaling values for the x and z axis for Mario when he is close to unsquishing.

◆ sTerrainStepNoises

s8 sTerrainStepNoises[7][6]
Initial value:
= { { 0, 3, 1, 1, 1, 0 }, { 3, 3, 3, 3, 1, 1 }, { 5, 6, 5, 6, 3, 3 },
{ 7, 3, 7, 7, 3, 3 }, { 4, 4, 4, 4, 3, 3 }, { 0, 3, 1, 6, 3, 6 },
{ 3, 3, 3, 3, 6, 6 } }

The step noises organized by terrain types by surface classes.

See audio_defines.h for more information.

◆ unused80339F10

u32 unused80339F10