diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index fbf7df61f..561aa4a1c 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -11224,6 +11224,12 @@ HAZARD_TYPE_LAVA_WALL = 2 --- @type integer HAZARD_TYPE_QUICKSAND = 3 +--- @type integer +HAZARD_TYPE_HORIZONTAL_WIND = 4 + +--- @type integer +HAZARD_TYPE_VERTICAL_WIND = 5 + --- @type integer SURFACE_0004 = 0x0004 diff --git a/docs/lua/constants.md b/docs/lua/constants.md index ddce7e90b..352dac083 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -4705,6 +4705,8 @@ - HAZARD_TYPE_LAVA_FLOOR - HAZARD_TYPE_LAVA_WALL - HAZARD_TYPE_QUICKSAND +- HAZARD_TYPE_HORIZONTAL_WIND +- HAZARD_TYPE_VERTICAL_WIND - SURFACE_0004 - SURFACE_BOSS_FIGHT_CAMERA - SURFACE_BURNING diff --git a/docs/lua/guides/hooks.md b/docs/lua/guides/hooks.md index 020a86c59..750378d1c 100644 --- a/docs/lua/guides/hooks.md +++ b/docs/lua/guides/hooks.md @@ -119,7 +119,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh | HOOK_USE_ACT_SELECT | Called when the level changes, return `true` to show act selection screen and `false` otherwise | `integer` levelNum | | HOOK_ON_CHANGE_CAMERA_ANGLE | Called when the player changes the camera mode to Lakitu cam or Mario cam, return `false` to prevent the change | `integer` mode | | HOOK_ON_SCREEN_TRANSITION | Called when the game is about to play a transition, return `false` to prevent the transition from playing | `integer` type | -| HOOK_ALLOW_HAZARD_SURFACE | Called once per player per frame. Return `false` to prevent the player from being affected by lava or quicksand | [MarioState](../structs.md#MarioState) mario, `integer` hazardType | +| HOOK_ALLOW_HAZARD_SURFACE | Called once per player per frame. Return `false` to prevent the player from being affected by lava, quicksand, or wind | [MarioState](../structs.md#MarioState) mario, `integer` hazardType | | HOOK_ON_CHAT_MESSAGE | Called when a chat message gets sent. Return `false` to prevent the message from being sent | [MarioState](../structs.md#MarioState) messageSender, `string` messageSent | | HOOK_OBJECT_SET_MODEL | Called when a behavior changes models. Also runs when a behavior spawns | [Object](../structs.md#Object) obj, `integer` modelID | | HOOK_CHARACTER_SOUND | Called when mario retrieves a character sound to play, return a character sound or `0` to override it | [MarioState](../structs.md#MarioState) mario, [enum CharacterSound](../constants.md#enum-CharacterSound) characterSound | @@ -429,4 +429,4 @@ local function on_set_network_player_description(index, value) end hook_mod_menu_inputbox("Network Player Description", on_set_network_player_description) -``` \ No newline at end of file +``` diff --git a/include/surface_terrains.h b/include/surface_terrains.h index d54bcfc68..d020cd45c 100644 --- a/include/surface_terrains.h +++ b/include/surface_terrains.h @@ -165,9 +165,11 @@ #define SURFACE_FLAG_NO_CAM_COLLISION (1 << 1) #define SURFACE_FLAG_X_PROJECTION (1 << 3) -#define HAZARD_TYPE_LAVA_FLOOR 1 -#define HAZARD_TYPE_LAVA_WALL 2 -#define HAZARD_TYPE_QUICKSAND 3 +#define HAZARD_TYPE_LAVA_FLOOR 1 +#define HAZARD_TYPE_LAVA_WALL 2 +#define HAZARD_TYPE_QUICKSAND 3 +#define HAZARD_TYPE_HORIZONTAL_WIND 4 +#define HAZARD_TYPE_VERTICAL_WIND 5 // These are effectively unique "surface" types like those defined higher // And they are used as collision commands to load certain functions diff --git a/src/game/mario_actions_airborne.c b/src/game/mario_actions_airborne.c index ea3a194da..706e3e825 100644 --- a/src/game/mario_actions_airborne.c +++ b/src/game/mario_actions_airborne.c @@ -206,8 +206,14 @@ s32 check_horizontal_wind(struct MarioState *m) { struct Surface *floor; f32 speed; s16 pushAngle; + bool allow = true; + smlua_call_event_hooks_mario_param_and_int_ret_bool(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_HORIZONTAL_WIND, &allow); + if (!allow) { + return FALSE; + } floor = m->floor; + if (floor && floor->type == SURFACE_HORIZONTAL_WIND) { pushAngle = floor->force << 8; @@ -2299,7 +2305,9 @@ s32 check_common_airborne_cancels(struct MarioState *m) { return drop_and_set_mario_action(m, ACT_SQUISHED, 0); } - if (m->floor && m->floor->type == SURFACE_VERTICAL_WIND && (m->action & ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION)) { + bool allow = true; + smlua_call_event_hooks_mario_param_and_int_ret_bool(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_VERTICAL_WIND, &allow); + if (allow && m->floor && m->floor->type == SURFACE_VERTICAL_WIND && (m->action & ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION)) { return drop_and_set_mario_action(m, ACT_VERTICAL_WIND, 0); } diff --git a/src/game/mario_step.c b/src/game/mario_step.c index 6ac8d33bb..963e72832 100644 --- a/src/game/mario_step.c +++ b/src/game/mario_step.c @@ -206,7 +206,12 @@ u32 mario_update_windy_ground(struct MarioState *m) { if (!m) { return 0; } struct Surface *floor = m->floor; if (!floor) { return 0; } - + bool allow = true; + smlua_call_event_hooks_mario_param_and_int_ret_bool(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_HORIZONTAL_WIND, &allow); + if (!allow) { + return FALSE; + } + extern bool gDjuiInMainMenu; if (floor->type == SURFACE_HORIZONTAL_WIND && !gDjuiInMainMenu) { f32 pushSpeed; @@ -697,8 +702,9 @@ void apply_vertical_wind(struct MarioState *m) { if (!m) { return; } f32 maxVelY; f32 offsetY; - - if (m->action != ACT_GROUND_POUND) { + bool allow = true; + smlua_call_event_hooks_mario_param_and_int_ret_bool(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_VERTICAL_WIND, &allow); + if (m->action != ACT_GROUND_POUND && allow) { offsetY = m->pos[1] - -1500.0f; if (m->floor && m->floor->type == SURFACE_VERTICAL_WIND && -3000.0f < offsetY && offsetY < 2000.0f) { diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index e262f53ae..a988dcb19 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -4687,6 +4687,8 @@ char gSmluaConstants[] = "" "HAZARD_TYPE_LAVA_FLOOR=1\n" "HAZARD_TYPE_LAVA_WALL=2\n" "HAZARD_TYPE_QUICKSAND=3\n" +"HAZARD_TYPE_HORIZONTAL_WIND=4\n" +"HAZARD_TYPE_VERTICAL_WIND=5\n" "TERRAIN_LOAD_VERTICES=0x0040\n" "TERRAIN_LOAD_CONTINUE=0x0041\n" "TERRAIN_LOAD_END=0x0042\n" @@ -4737,4 +4739,4 @@ char gSmluaConstants[] = "" "VERSION_NUMBER=39\n" "MINOR_VERSION_NUMBER=1\n" "MAX_VERSION_LENGTH=128\n" -; \ No newline at end of file +;