mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-10-30 08:01:01 +00:00
Fix HOOK_ALLOW_HAZARD_SURFACE and expose SURFACE_IS_* macros (#865)
* Fix HOOK_ALLOW_HAZARD_SURFACE * Peachy's suggestions * Exposed `surface_is_*` macros
This commit is contained in:
parent
1ad874a1c5
commit
9acb632b8e
10 changed files with 203 additions and 21 deletions
|
|
@ -10223,6 +10223,27 @@ function smlua_collision_util_find_surface_types(data)
|
||||||
-- ...
|
-- ...
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- @param surf Surface
|
||||||
|
--- @return boolean
|
||||||
|
--- Checks if the surface is quicksand
|
||||||
|
function surface_is_quicksand(surf)
|
||||||
|
-- ...
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @param surf Surface
|
||||||
|
--- @return boolean
|
||||||
|
--- Checks if the surface is not a hard surface
|
||||||
|
function surface_is_not_hard(surf)
|
||||||
|
-- ...
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @param surf Surface
|
||||||
|
--- @return boolean
|
||||||
|
--- Checks if the surface is a painting warp
|
||||||
|
function surface_is_painting_warp(surf)
|
||||||
|
-- ...
|
||||||
|
end
|
||||||
|
|
||||||
--- @param fov number
|
--- @param fov number
|
||||||
--- Sets the override FOV
|
--- Sets the override FOV
|
||||||
function set_override_fov(fov)
|
function set_override_fov(fov)
|
||||||
|
|
|
||||||
|
|
@ -2112,6 +2112,75 @@ Gets a table of the surface types from `data`
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
|
## [surface_is_quicksand](#surface_is_quicksand)
|
||||||
|
|
||||||
|
### Description
|
||||||
|
Checks if the surface is quicksand
|
||||||
|
|
||||||
|
### Lua Example
|
||||||
|
`local booleanValue = surface_is_quicksand(surf)`
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
| Field | Type |
|
||||||
|
| ----- | ---- |
|
||||||
|
| surf | [Surface](structs.md#Surface) |
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
- `boolean`
|
||||||
|
|
||||||
|
### C Prototype
|
||||||
|
`bool surface_is_quicksand(struct Surface* surf);`
|
||||||
|
|
||||||
|
[:arrow_up_small:](#)
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
## [surface_is_not_hard](#surface_is_not_hard)
|
||||||
|
|
||||||
|
### Description
|
||||||
|
Checks if the surface is not a hard surface
|
||||||
|
|
||||||
|
### Lua Example
|
||||||
|
`local booleanValue = surface_is_not_hard(surf)`
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
| Field | Type |
|
||||||
|
| ----- | ---- |
|
||||||
|
| surf | [Surface](structs.md#Surface) |
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
- `boolean`
|
||||||
|
|
||||||
|
### C Prototype
|
||||||
|
`bool surface_is_not_hard(struct Surface* surf);`
|
||||||
|
|
||||||
|
[:arrow_up_small:](#)
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
## [surface_is_painting_warp](#surface_is_painting_warp)
|
||||||
|
|
||||||
|
### Description
|
||||||
|
Checks if the surface is a painting warp
|
||||||
|
|
||||||
|
### Lua Example
|
||||||
|
`local booleanValue = surface_is_painting_warp(surf)`
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
| Field | Type |
|
||||||
|
| ----- | ---- |
|
||||||
|
| surf | [Surface](structs.md#Surface) |
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
- `boolean`
|
||||||
|
|
||||||
|
### C Prototype
|
||||||
|
`bool surface_is_painting_warp(struct Surface* surf);`
|
||||||
|
|
||||||
|
[:arrow_up_small:](#)
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
---
|
---
|
||||||
# functions from smlua_deprecated.h
|
# functions from smlua_deprecated.h
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1843,6 +1843,9 @@
|
||||||
- [smlua_collision_util_get_current_terrain_collision](functions-6.md#smlua_collision_util_get_current_terrain_collision)
|
- [smlua_collision_util_get_current_terrain_collision](functions-6.md#smlua_collision_util_get_current_terrain_collision)
|
||||||
- [smlua_collision_util_get_level_collision](functions-6.md#smlua_collision_util_get_level_collision)
|
- [smlua_collision_util_get_level_collision](functions-6.md#smlua_collision_util_get_level_collision)
|
||||||
- [smlua_collision_util_find_surface_types](functions-6.md#smlua_collision_util_find_surface_types)
|
- [smlua_collision_util_find_surface_types](functions-6.md#smlua_collision_util_find_surface_types)
|
||||||
|
- [surface_is_quicksand](functions-6.md#surface_is_quicksand)
|
||||||
|
- [surface_is_not_hard](functions-6.md#surface_is_not_hard)
|
||||||
|
- [surface_is_painting_warp](functions-6.md#surface_is_painting_warp)
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@
|
||||||
#define SURFACE_WOBBLING_WARP 0x00FD // Pool warp (HMC & DDD)
|
#define SURFACE_WOBBLING_WARP 0x00FD // Pool warp (HMC & DDD)
|
||||||
#define SURFACE_TRAPDOOR 0x00FF // Bowser Left trapdoor, has no action defined
|
#define SURFACE_TRAPDOOR 0x00FF // Bowser Left trapdoor, has no action defined
|
||||||
|
|
||||||
#define SURFACE_IS_QUICKSAND(cmd) (cmd >= 0x21 && cmd < 0x28) // Doesn't include SURFACE_INSTANT_MOVING_QUICKSAND
|
#define SURFACE_IS_QUICKSAND(cmd) ((cmd >= 0x21 && cmd < 0x28) || cmd == SURFACE_INSTANT_MOVING_QUICKSAND)
|
||||||
#define SURFACE_IS_NOT_HARD(cmd) (cmd != SURFACE_HARD && \
|
#define SURFACE_IS_NOT_HARD(cmd) (cmd != SURFACE_HARD && \
|
||||||
!(cmd >= 0x35 && cmd <= 0x37))
|
!(cmd >= 0x35 && cmd <= 0x37))
|
||||||
#define SURFACE_IS_PAINTING_WARP(cmd) (cmd >= 0xD3 && cmd < 0xFD)
|
#define SURFACE_IS_PAINTING_WARP(cmd) (cmd >= 0xD3 && cmd < 0xFD)
|
||||||
|
|
|
||||||
|
|
@ -2460,10 +2460,12 @@ void check_death_barrier(struct MarioState *m) {
|
||||||
|
|
||||||
void check_lava_boost(struct MarioState *m) {
|
void check_lava_boost(struct MarioState *m) {
|
||||||
if (!m) { return; }
|
if (!m) { return; }
|
||||||
|
if (m->action == ACT_BUBBLED) { return; }
|
||||||
|
if (!(m->action & ACT_FLAG_RIDING_SHELL) && m->pos[1] < m->floorHeight + 10.0f) {
|
||||||
bool allowHazard = true;
|
bool allowHazard = true;
|
||||||
smlua_call_event_hooks(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_LAVA_FLOOR, &allowHazard);
|
smlua_call_event_hooks(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_LAVA_FLOOR, &allowHazard);
|
||||||
if (m->action == ACT_BUBBLED || (!allowHazard)) { return; }
|
if (!allowHazard) { return; }
|
||||||
if (!(m->action & ACT_FLAG_RIDING_SHELL) && m->pos[1] < m->floorHeight + 10.0f) {
|
|
||||||
if (!(m->flags & MARIO_METAL_CAP)) {
|
if (!(m->flags & MARIO_METAL_CAP)) {
|
||||||
m->hurtCounter += (m->flags & MARIO_CAP_ON_HEAD) ? 12 : 18;
|
m->hurtCounter += (m->flags & MARIO_CAP_ON_HEAD) ? 12 : 18;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -206,16 +206,16 @@ s32 check_horizontal_wind(struct MarioState *m) {
|
||||||
struct Surface *floor;
|
struct Surface *floor;
|
||||||
f32 speed;
|
f32 speed;
|
||||||
s16 pushAngle;
|
s16 pushAngle;
|
||||||
|
|
||||||
|
floor = m->floor;
|
||||||
|
|
||||||
|
if (floor && floor->type == SURFACE_HORIZONTAL_WIND) {
|
||||||
bool allowHazard = true;
|
bool allowHazard = true;
|
||||||
smlua_call_event_hooks(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_HORIZONTAL_WIND, &allowHazard);
|
smlua_call_event_hooks(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_HORIZONTAL_WIND, &allowHazard);
|
||||||
if (!allowHazard) {
|
if (!allowHazard) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
floor = m->floor;
|
|
||||||
|
|
||||||
|
|
||||||
if (floor && floor->type == SURFACE_HORIZONTAL_WIND) {
|
|
||||||
pushAngle = floor->force << 8;
|
pushAngle = floor->force << 8;
|
||||||
|
|
||||||
m->slideVelX += 1.2f * sins(pushAngle);
|
m->slideVelX += 1.2f * sins(pushAngle);
|
||||||
|
|
|
||||||
|
|
@ -123,10 +123,8 @@ void mario_bonk_reflection(struct MarioState *m, u8 negateSpeed) {
|
||||||
|
|
||||||
u32 mario_update_quicksand(struct MarioState *m, f32 sinkingSpeed) {
|
u32 mario_update_quicksand(struct MarioState *m, f32 sinkingSpeed) {
|
||||||
if (!m) { return 0; }
|
if (!m) { return 0; }
|
||||||
bool allowHazard = true;
|
|
||||||
smlua_call_event_hooks(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_QUICKSAND, &allowHazard);
|
|
||||||
extern bool gDjuiInMainMenu;
|
extern bool gDjuiInMainMenu;
|
||||||
if (m->action & ACT_FLAG_RIDING_SHELL || (!allowHazard) || gDjuiInMainMenu) {
|
if (m->action & ACT_FLAG_RIDING_SHELL || gDjuiInMainMenu) {
|
||||||
m->quicksandDepth = 0.0f;
|
m->quicksandDepth = 0.0f;
|
||||||
} else {
|
} else {
|
||||||
if (m->quicksandDepth < 1.1f) {
|
if (m->quicksandDepth < 1.1f) {
|
||||||
|
|
@ -135,6 +133,16 @@ u32 mario_update_quicksand(struct MarioState *m, f32 sinkingSpeed) {
|
||||||
|
|
||||||
u32 floorType = m->floor ? m->floor->type : SURFACE_DEFAULT;
|
u32 floorType = m->floor ? m->floor->type : SURFACE_DEFAULT;
|
||||||
|
|
||||||
|
// Only run the hook if the player is actually on quicksand
|
||||||
|
if (SURFACE_IS_QUICKSAND(floorType)) {
|
||||||
|
bool allowHazard = true;
|
||||||
|
smlua_call_event_hooks(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_QUICKSAND, &allowHazard);
|
||||||
|
if (!allowHazard) {
|
||||||
|
m->quicksandDepth = 0;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (floorType) {
|
switch (floorType) {
|
||||||
case SURFACE_SHALLOW_QUICKSAND:
|
case SURFACE_SHALLOW_QUICKSAND:
|
||||||
if ((m->quicksandDepth += sinkingSpeed) >= 10.0f) {
|
if ((m->quicksandDepth += sinkingSpeed) >= 10.0f) {
|
||||||
|
|
@ -217,14 +225,15 @@ u32 mario_update_windy_ground(struct MarioState *m) {
|
||||||
if (!m) { return 0; }
|
if (!m) { return 0; }
|
||||||
struct Surface *floor = m->floor;
|
struct Surface *floor = m->floor;
|
||||||
if (!floor) { return 0; }
|
if (!floor) { return 0; }
|
||||||
|
|
||||||
|
extern bool gDjuiInMainMenu;
|
||||||
|
if (floor->type == SURFACE_HORIZONTAL_WIND && !gDjuiInMainMenu) {
|
||||||
bool allowHazard = true;
|
bool allowHazard = true;
|
||||||
smlua_call_event_hooks(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_HORIZONTAL_WIND, &allowHazard);
|
smlua_call_event_hooks(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_HORIZONTAL_WIND, &allowHazard);
|
||||||
if (!allowHazard) {
|
if (!allowHazard) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern bool gDjuiInMainMenu;
|
|
||||||
if (floor->type == SURFACE_HORIZONTAL_WIND && !gDjuiInMainMenu) {
|
|
||||||
f32 pushSpeed;
|
f32 pushSpeed;
|
||||||
s16 pushAngle = floor->force << 8;
|
s16 pushAngle = floor->force << 8;
|
||||||
|
|
||||||
|
|
@ -721,12 +730,14 @@ void apply_vertical_wind(struct MarioState *m) {
|
||||||
if (!m) { return; }
|
if (!m) { return; }
|
||||||
f32 maxVelY;
|
f32 maxVelY;
|
||||||
f32 offsetY;
|
f32 offsetY;
|
||||||
bool allowHazard = true;
|
if (m->action != ACT_GROUND_POUND) {
|
||||||
smlua_call_event_hooks(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_VERTICAL_WIND, &allowHazard);
|
|
||||||
if (m->action != ACT_GROUND_POUND && allowHazard) {
|
|
||||||
offsetY = m->pos[1] - -1500.0f;
|
offsetY = m->pos[1] - -1500.0f;
|
||||||
|
|
||||||
if (m->floor && m->floor->type == SURFACE_VERTICAL_WIND && -3000.0f < offsetY && offsetY < 2000.0f) {
|
if (m->floor && m->floor->type == SURFACE_VERTICAL_WIND && -3000.0f < offsetY && offsetY < 2000.0f) {
|
||||||
|
bool allowHazard = true;
|
||||||
|
smlua_call_event_hooks(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_VERTICAL_WIND, &allowHazard);
|
||||||
|
if (!allowHazard) { return; }
|
||||||
|
|
||||||
if (offsetY >= 0.0f) {
|
if (offsetY >= 0.0f) {
|
||||||
maxVelY = 10000.0f / (offsetY + 200.0f);
|
maxVelY = 10000.0f / (offsetY + 200.0f);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -30898,6 +30898,57 @@ int smlua_func_smlua_collision_util_find_surface_types(lua_State* L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int smlua_func_surface_is_quicksand(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", "surface_is_quicksand", 1, top);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Surface* surf = (struct Surface*)smlua_to_cobject(L, 1, LOT_SURFACE);
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "surface_is_quicksand"); return 0; }
|
||||||
|
|
||||||
|
lua_pushboolean(L, surface_is_quicksand(surf));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int smlua_func_surface_is_not_hard(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", "surface_is_not_hard", 1, top);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Surface* surf = (struct Surface*)smlua_to_cobject(L, 1, LOT_SURFACE);
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "surface_is_not_hard"); return 0; }
|
||||||
|
|
||||||
|
lua_pushboolean(L, surface_is_not_hard(surf));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int smlua_func_surface_is_painting_warp(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", "surface_is_painting_warp", 1, top);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Surface* surf = (struct Surface*)smlua_to_cobject(L, 1, LOT_SURFACE);
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "surface_is_painting_warp"); return 0; }
|
||||||
|
|
||||||
|
lua_pushboolean(L, surface_is_painting_warp(surf));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////
|
////////////////////////
|
||||||
// smlua_deprecated.h //
|
// smlua_deprecated.h //
|
||||||
////////////////////////
|
////////////////////////
|
||||||
|
|
@ -37033,6 +37084,9 @@ void smlua_bind_functions_autogen(void) {
|
||||||
smlua_bind_function(L, "smlua_collision_util_get_current_terrain_collision", smlua_func_smlua_collision_util_get_current_terrain_collision);
|
smlua_bind_function(L, "smlua_collision_util_get_current_terrain_collision", smlua_func_smlua_collision_util_get_current_terrain_collision);
|
||||||
smlua_bind_function(L, "smlua_collision_util_get_level_collision", smlua_func_smlua_collision_util_get_level_collision);
|
smlua_bind_function(L, "smlua_collision_util_get_level_collision", smlua_func_smlua_collision_util_get_level_collision);
|
||||||
smlua_bind_function(L, "smlua_collision_util_find_surface_types", smlua_func_smlua_collision_util_find_surface_types);
|
smlua_bind_function(L, "smlua_collision_util_find_surface_types", smlua_func_smlua_collision_util_find_surface_types);
|
||||||
|
smlua_bind_function(L, "surface_is_quicksand", smlua_func_surface_is_quicksand);
|
||||||
|
smlua_bind_function(L, "surface_is_not_hard", smlua_func_surface_is_not_hard);
|
||||||
|
smlua_bind_function(L, "surface_is_painting_warp", smlua_func_surface_is_painting_warp);
|
||||||
|
|
||||||
// smlua_deprecated.h
|
// smlua_deprecated.h
|
||||||
smlua_bind_function(L, "djui_hud_set_render_behind_hud", smlua_func_djui_hud_set_render_behind_hud);
|
smlua_bind_function(L, "djui_hud_set_render_behind_hud", smlua_func_djui_hud_set_render_behind_hud);
|
||||||
|
|
|
||||||
|
|
@ -237,3 +237,18 @@ void smlua_collision_util_find_surface_types(Collision* data) {
|
||||||
// Couldn't find anything
|
// Couldn't find anything
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool surface_is_quicksand(struct Surface* surf) {
|
||||||
|
if (surf == NULL) { return FALSE; }
|
||||||
|
return SURFACE_IS_QUICKSAND(surf->type);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool surface_is_not_hard(struct Surface* surf) {
|
||||||
|
if (surf == NULL) { return FALSE; }
|
||||||
|
return SURFACE_IS_NOT_HARD(surf->type);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool surface_is_painting_warp(struct Surface* surf) {
|
||||||
|
if (surf == NULL) { return FALSE; }
|
||||||
|
return SURFACE_IS_PAINTING_WARP(surf->type);
|
||||||
|
}
|
||||||
|
|
@ -142,4 +142,11 @@ Collision *smlua_collision_util_get_level_collision(u32 level, u16 area);
|
||||||
/* |description|Gets a table of the surface types from `data`|descriptionEnd| */
|
/* |description|Gets a table of the surface types from `data`|descriptionEnd| */
|
||||||
void smlua_collision_util_find_surface_types(Collision* data);
|
void smlua_collision_util_find_surface_types(Collision* data);
|
||||||
|
|
||||||
|
/* |description|Checks if the surface is quicksand|descriptionEnd| */
|
||||||
|
bool surface_is_quicksand(struct Surface* surf);
|
||||||
|
/* |description|Checks if the surface is not a hard surface|descriptionEnd| */
|
||||||
|
bool surface_is_not_hard(struct Surface* surf);
|
||||||
|
/* |description|Checks if the surface is a painting warp|descriptionEnd| */
|
||||||
|
bool surface_is_painting_warp(struct Surface* surf);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue