From c32cf2054a79ee68a866589b337135dc97794e35 Mon Sep 17 00:00:00 2001
From: Agent X <44549182+Agent-11@users.noreply.github.com>
Date: Tue, 5 Dec 2023 21:24:42 -0500
Subject: [PATCH] Add mario_is_crouching(m)
---
autogen/lua_definitions/functions.lua | 6 ++++++
docs/lua/functions-3.md | 20 ++++++++++++++++++++
docs/lua/functions.md | 1 +
src/game/first_person_cam.c | 5 ++---
src/game/mario.c | 8 ++++++++
src/game/mario.h | 1 +
src/pc/lua/smlua_functions_autogen.c | 18 ++++++++++++++++++
7 files changed, 56 insertions(+), 3 deletions(-)
diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua
index b75cbdff..c397c95e 100644
--- a/autogen/lua_definitions/functions.lua
+++ b/autogen/lua_definitions/functions.lua
@@ -4404,6 +4404,12 @@ function mario_get_terrain_sound_addend(m)
-- ...
end
+--- @param m MarioState
+--- @return boolean
+function mario_is_crouching(m)
+ -- ...
+end
+
--- @param m MarioState
--- @return nil
function mario_set_bubbled(m)
diff --git a/docs/lua/functions-3.md b/docs/lua/functions-3.md
index b21fea45..7b26dbb5 100644
--- a/docs/lua/functions-3.md
+++ b/docs/lua/functions-3.md
@@ -4547,6 +4547,26 @@
+## [mario_is_crouching](#mario_is_crouching)
+
+### Lua Example
+`local booleanValue = mario_is_crouching(m)`
+
+### Parameters
+| Field | Type |
+| ----- | ---- |
+| m | [MarioState](structs.md#MarioState) |
+
+### Returns
+- `boolean`
+
+### C Prototype
+`bool mario_is_crouching(struct MarioState *m);`
+
+[:arrow_up_small:](#)
+
+
+
## [mario_set_bubbled](#mario_set_bubbled)
### Lua Example
diff --git a/docs/lua/functions.md b/docs/lua/functions.md
index ec99518c..c12f90d7 100644
--- a/docs/lua/functions.md
+++ b/docs/lua/functions.md
@@ -888,6 +888,7 @@
- [mario_floor_is_steep](functions-3.md#mario_floor_is_steep)
- [mario_get_floor_class](functions-3.md#mario_get_floor_class)
- [mario_get_terrain_sound_addend](functions-3.md#mario_get_terrain_sound_addend)
+ - [mario_is_crouching](functions-3.md#mario_is_crouching)
- [mario_set_bubbled](functions-3.md#mario_set_bubbled)
- [mario_set_forward_vel](functions-3.md#mario_set_forward_vel)
- [mario_update_wall](functions-3.md#mario_update_wall)
diff --git a/src/game/first_person_cam.c b/src/game/first_person_cam.c
index 4f3efd0e..3db03546 100644
--- a/src/game/first_person_cam.c
+++ b/src/game/first_person_cam.c
@@ -6,6 +6,7 @@
#include "level_update.h"
#include "object_list_processor.h"
#include "object_helpers.h"
+#include "mario.h"
#include "engine/math_util.h"
@@ -104,9 +105,7 @@ void first_person_camera_update(void) {
m->area->camera->yaw = gFirstPersonCamera.yaw;
// update crouch
- if (m->action == ACT_START_CROUCHING || m->action == ACT_CROUCHING || m->action == ACT_STOP_CROUCHING ||
- m->action == ACT_START_CRAWLING || m->action == ACT_CRAWLING || m->action == ACT_STOP_CRAWLING ||
- m->action == ACT_CROUCH_SLIDE || m->action == ACT_LEDGE_GRAB) {
+ if (mario_is_crouching(m) || m->action == ACT_LEDGE_GRAB) {
f32 inc = 10 * (m->controller->buttonDown & Z_TRIG) != 0 || m->action == ACT_CROUCH_SLIDE || m->action == ACT_LEDGE_GRAB ? 1 : -1;
gFirstPersonCamera.crouch = CLAMP(gFirstPersonCamera.crouch + inc, 0, MARIO_HEAD_POS - MARIO_HEAD_POS_SHORT);
} else {
diff --git a/src/game/mario.c b/src/game/mario.c
index 1eb35f71..a9e05563 100644
--- a/src/game/mario.c
+++ b/src/game/mario.c
@@ -492,6 +492,14 @@ void play_mario_sound(struct MarioState *m, s32 actionSound, s32 marioSound) {
* ACTIONS *
**************************************************/
+bool mario_is_crouching(struct MarioState *m) {
+ if (!m) { return false; }
+
+ return m->action == ACT_START_CROUCHING || m->action == ACT_CROUCHING || m->action == ACT_STOP_CROUCHING ||
+ m->action == ACT_START_CRAWLING || m->action == ACT_CRAWLING || m->action == ACT_STOP_CRAWLING ||
+ m->action == ACT_CROUCH_SLIDE;
+}
+
bool mario_can_bubble(struct MarioState* m) {
if (!m) { return false; }
if (!gServerSettings.bubbleDeath) { return false; }
diff --git a/src/game/mario.h b/src/game/mario.h
index 57ef425e..6cd282ac 100644
--- a/src/game/mario.h
+++ b/src/game/mario.h
@@ -32,6 +32,7 @@ void play_mario_landing_sound_once(struct MarioState *m, u32 soundBits);
void play_mario_heavy_landing_sound(struct MarioState *m, u32 soundBits);
void play_mario_heavy_landing_sound_once(struct MarioState *m, u32 soundBits);
void play_mario_sound(struct MarioState *m, s32 primarySoundBits, s32 scondarySoundBits);
+bool mario_is_crouching(struct MarioState *m);
bool mario_can_bubble(struct MarioState* m);
void mario_set_bubbled(struct MarioState* m);
void mario_set_forward_vel(struct MarioState *m, f32 speed);
diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c
index 6e20a5fd..12d1adb0 100644
--- a/src/pc/lua/smlua_functions_autogen.c
+++ b/src/pc/lua/smlua_functions_autogen.c
@@ -14328,6 +14328,23 @@ int smlua_func_mario_get_terrain_sound_addend(lua_State* L) {
return 1;
}
+int smlua_func_mario_is_crouching(lua_State* L) {
+ if (L == NULL) { return 0; }
+
+ int top = lua_gettop(L);
+ if (top != 1) {
+ LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "mario_is_crouching", 1, top);
+ return 0;
+ }
+
+ struct MarioState* m = (struct MarioState*)smlua_to_cobject(L, 1, LOT_MARIOSTATE);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "mario_is_crouching"); return 0; }
+
+ lua_pushboolean(L, mario_is_crouching(m));
+
+ return 1;
+}
+
int smlua_func_mario_set_bubbled(lua_State* L) {
if (L == NULL) { return 0; }
@@ -32130,6 +32147,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "mario_floor_is_steep", smlua_func_mario_floor_is_steep);
smlua_bind_function(L, "mario_get_floor_class", smlua_func_mario_get_floor_class);
smlua_bind_function(L, "mario_get_terrain_sound_addend", smlua_func_mario_get_terrain_sound_addend);
+ smlua_bind_function(L, "mario_is_crouching", smlua_func_mario_is_crouching);
smlua_bind_function(L, "mario_set_bubbled", smlua_func_mario_set_bubbled);
smlua_bind_function(L, "mario_set_forward_vel", smlua_func_mario_set_forward_vel);
smlua_bind_function(L, "mario_update_wall", smlua_func_mario_update_wall);