Add some new LUA helper functions and fix some bugs. (#230)

- Add new functions for objects, Feel free to flesh some out if need be.
- Fix long-standing issue with our LUA garbage collection, It will now run after all our hooks do to prevent buildup which causes lag.
This commit is contained in:
Prince Frizzy 2022-11-12 08:01:50 -05:00 committed by GitHub
parent 962ed5ce23
commit f815a53080
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 1517 additions and 235 deletions

View file

@ -41,6 +41,7 @@ in_files = [
"src/pc/lua/utils/smlua_obj_utils.h",
"src/pc/lua/utils/smlua_misc_utils.h",
"src/pc/lua/utils/smlua_collision_utils.h",
"src/pc/lua/utils/smlua_math_utils.h",
"src/pc/lua/utils/smlua_model_utils.h",
"src/pc/lua/utils/smlua_text_utils.h",
"src/pc/lua/utils/smlua_audio_utils.h",

View file

@ -7056,12 +7056,39 @@ function obj_set_cylboard(obj)
-- ...
end
--- @param obj Object
--- @param pitch integer
--- @param yaw integer
--- @param roll integer
--- @return nil
function obj_set_face_angle(obj, pitch, yaw, roll)
-- ...
end
--- @param obj Object
--- @return nil
function obj_set_face_angle_to_move_angle(obj)
-- ...
end
--- @param obj Object
--- @param pitch integer
--- @param yaw integer
--- @param roll integer
--- @return nil
function obj_set_gfx_angle(obj, pitch, yaw, roll)
-- ...
end
--- @param obj Object
--- @param x number
--- @param y number
--- @param z number
--- @return nil
function obj_set_gfx_pos(obj, x, y, z)
-- ...
end
--- @param obj1 Object
--- @param obj2 Object
--- @return nil
@ -7075,6 +7102,15 @@ function obj_set_gfx_pos_from_pos(obj)
-- ...
end
--- @param obj Object
--- @param x number
--- @param y number
--- @param z number
--- @return nil
function obj_set_gfx_scale(obj, x, y, z)
-- ...
end
--- @param obj Object
--- @param heldBehavior Pointer_BehaviorScript
--- @return nil
@ -7089,6 +7125,31 @@ function obj_set_hitbox(obj, hitbox)
-- ...
end
--- @param o Object
--- @param radius number
--- @param height number
--- @return nil
function obj_set_hitbox_radius_and_height(o, radius, height)
-- ...
end
--- @param o Object
--- @param radius number
--- @param height number
--- @return nil
function obj_set_hurtbox_radius_and_height(o, radius, height)
-- ...
end
--- @param obj Object
--- @param pitch integer
--- @param yaw integer
--- @param roll integer
--- @return nil
function obj_set_move_angle(obj, pitch, yaw, roll)
-- ...
end
--- @param obj Object
--- @param relX integer
--- @param relY integer
@ -7624,6 +7685,62 @@ function warp_to_warpnode(aLevel, aArea, aAct, aWarpId)
-- ...
end
--- @param a integer
--- @param b integer
--- @param c integer
--- @return integer
function clamp(a, b, c)
-- ...
end
--- @param a number
--- @param b number
--- @param c number
--- @return number
function clampf(a, b, c)
-- ...
end
--- @param a integer
--- @param b integer
--- @return integer
function max(a, b)
-- ...
end
--- @param a number
--- @param b number
--- @return number
function maxf(a, b)
-- ...
end
--- @param a integer
--- @param b integer
--- @return integer
function min(a, b)
-- ...
end
--- @param a number
--- @param b number
--- @return number
function minf(a, b)
-- ...
end
--- @param x integer
--- @return integer
function sqr(x)
-- ...
end
--- @param x number
--- @return number
function sqrf(x)
-- ...
end
--- @param index integer
--- @param name string
--- @param offset integer
@ -8047,6 +8164,54 @@ function obj_has_model_extended(o, modelId)
-- ...
end
--- @param o Object
--- @return boolean
function obj_is_attackable(o)
-- ...
end
--- @param o Object
--- @return boolean
function obj_is_breakable_object(o)
-- ...
end
--- @param o Object
--- @return boolean
function obj_is_bully(o)
-- ...
end
--- @param o Object
--- @return boolean
function obj_is_coin(o)
-- ...
end
--- @param o Object
--- @return boolean
function obj_is_exclamation_box(o)
-- ...
end
--- @param o Object
--- @return boolean
function obj_is_grabbable(o)
-- ...
end
--- @param o Object
--- @return boolean
function obj_is_mushroom_1up(o)
-- ...
end
--- @param o Object
--- @return boolean
function obj_is_secret(o)
-- ...
end
--- @param o Object
--- @return boolean
function obj_is_valid_for_interaction(o)

View file

@ -2,7 +2,7 @@
---
[< prev](functions.md) | [1](functions.md) | 2 | [3](functions-3.md) | [4](functions-4.md) | [next >](functions-3.md)]
[< prev](functions.md) | [1](functions.md) | 2 | [3](functions-3.md) | [4](functions-4.md) | [5](functions-5.md) | [next >](functions-3.md)]
---
@ -10330,5 +10330,5 @@
<br />
---
[< prev](functions.md) | [1](functions.md) | 2 | [3](functions-3.md) | [4](functions-4.md) | [next >](functions-3.md)]
[< prev](functions.md) | [1](functions.md) | 2 | [3](functions-3.md) | [4](functions-4.md) | [5](functions-5.md) | [next >](functions-3.md)]

View file

@ -2,7 +2,7 @@
---
[< prev](functions-2.md) | [1](functions.md) | [2](functions-2.md) | 3 | [4](functions-4.md) | [next >](functions-4.md)]
[< prev](functions-2.md) | [1](functions.md) | [2](functions-2.md) | 3 | [4](functions-4.md) | [5](functions-5.md) | [next >](functions-4.md)]
---
@ -8277,5 +8277,5 @@
<br />
---
[< prev](functions-2.md) | [1](functions.md) | [2](functions-2.md) | 3 | [4](functions-4.md) | [next >](functions-4.md)]
[< prev](functions-2.md) | [1](functions.md) | [2](functions-2.md) | 3 | [4](functions-4.md) | [5](functions-5.md) | [next >](functions-4.md)]

View file

@ -2,7 +2,7 @@
---
[< prev](functions-3.md) | [1](functions.md) | [2](functions-2.md) | [3](functions-3.md) | 4]
[< prev](functions-3.md) | [1](functions.md) | [2](functions-2.md) | [3](functions-3.md) | 4 | [5](functions-5.md) | [next >](functions-5.md)]
---
@ -4592,6 +4592,29 @@
<br />
## [obj_set_face_angle](#obj_set_face_angle)
### Lua Example
`obj_set_face_angle(obj, pitch, yaw, roll)`
### Parameters
| Field | Type |
| ----- | ---- |
| obj | [Object](structs.md#Object) |
| pitch | `integer` |
| yaw | `integer` |
| roll | `integer` |
### Returns
- None
### C Prototype
`void obj_set_face_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll);`
[:arrow_up_small:](#)
<br />
## [obj_set_face_angle_to_move_angle](#obj_set_face_angle_to_move_angle)
### Lua Example
@ -4612,6 +4635,52 @@
<br />
## [obj_set_gfx_angle](#obj_set_gfx_angle)
### Lua Example
`obj_set_gfx_angle(obj, pitch, yaw, roll)`
### Parameters
| Field | Type |
| ----- | ---- |
| obj | [Object](structs.md#Object) |
| pitch | `integer` |
| yaw | `integer` |
| roll | `integer` |
### Returns
- None
### C Prototype
`void obj_set_gfx_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll);`
[:arrow_up_small:](#)
<br />
## [obj_set_gfx_pos](#obj_set_gfx_pos)
### Lua Example
`obj_set_gfx_pos(obj, x, y, z)`
### Parameters
| Field | Type |
| ----- | ---- |
| obj | [Object](structs.md#Object) |
| x | `number` |
| y | `number` |
| z | `number` |
### Returns
- None
### C Prototype
`void obj_set_gfx_pos(struct Object *obj, f32 x, f32 y, f32 z);`
[:arrow_up_small:](#)
<br />
## [obj_set_gfx_pos_at_obj_pos](#obj_set_gfx_pos_at_obj_pos)
### Lua Example
@ -4653,6 +4722,29 @@
<br />
## [obj_set_gfx_scale](#obj_set_gfx_scale)
### Lua Example
`obj_set_gfx_scale(obj, x, y, z)`
### Parameters
| Field | Type |
| ----- | ---- |
| obj | [Object](structs.md#Object) |
| x | `number` |
| y | `number` |
| z | `number` |
### Returns
- None
### C Prototype
`void obj_set_gfx_scale(struct Object *obj, f32 x, f32 y, f32 z);`
[:arrow_up_small:](#)
<br />
## [obj_set_held_state](#obj_set_held_state)
### Lua Example
@ -4695,6 +4787,73 @@
<br />
## [obj_set_hitbox_radius_and_height](#obj_set_hitbox_radius_and_height)
### Lua Example
`obj_set_hitbox_radius_and_height(o, radius, height)`
### Parameters
| Field | Type |
| ----- | ---- |
| o | [Object](structs.md#Object) |
| radius | `number` |
| height | `number` |
### Returns
- None
### C Prototype
`void obj_set_hitbox_radius_and_height(struct Object *o, f32 radius, f32 height);`
[:arrow_up_small:](#)
<br />
## [obj_set_hurtbox_radius_and_height](#obj_set_hurtbox_radius_and_height)
### Lua Example
`obj_set_hurtbox_radius_and_height(o, radius, height)`
### Parameters
| Field | Type |
| ----- | ---- |
| o | [Object](structs.md#Object) |
| radius | `number` |
| height | `number` |
### Returns
- None
### C Prototype
`void obj_set_hurtbox_radius_and_height(struct Object *o, f32 radius, f32 height);`
[:arrow_up_small:](#)
<br />
## [obj_set_move_angle](#obj_set_move_angle)
### Lua Example
`obj_set_move_angle(obj, pitch, yaw, roll)`
### Parameters
| Field | Type |
| ----- | ---- |
| obj | [Object](structs.md#Object) |
| pitch | `integer` |
| yaw | `integer` |
| roll | `integer` |
### Returns
- None
### C Prototype
`void obj_set_move_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll);`
[:arrow_up_small:](#)
<br />
## [obj_set_parent_relative_pos](#obj_set_parent_relative_pos)
### Lua Example
@ -6347,6 +6506,180 @@
<br />
---
# functions from smlua_math_utils.h
<br />
## [clamp](#clamp)
### Lua Example
`local integerValue = clamp(a, b, c)`
### Parameters
| Field | Type |
| ----- | ---- |
| a | `integer` |
| b | `integer` |
| c | `integer` |
### Returns
- `integer`
### C Prototype
`s32 clamp(s32 a, s32 b, s32 c);`
[:arrow_up_small:](#)
<br />
## [clampf](#clampf)
### Lua Example
`local numberValue = clampf(a, b, c)`
### Parameters
| Field | Type |
| ----- | ---- |
| a | `number` |
| b | `number` |
| c | `number` |
### Returns
- `number`
### C Prototype
`f32 clampf(f32 a, f32 b, f32 c);`
[:arrow_up_small:](#)
<br />
## [max](#max)
### Lua Example
`local integerValue = max(a, b)`
### Parameters
| Field | Type |
| ----- | ---- |
| a | `integer` |
| b | `integer` |
### Returns
- `integer`
### C Prototype
`s32 max(s32 a, s32 b);`
[:arrow_up_small:](#)
<br />
## [maxf](#maxf)
### Lua Example
`local numberValue = maxf(a, b)`
### Parameters
| Field | Type |
| ----- | ---- |
| a | `number` |
| b | `number` |
### Returns
- `number`
### C Prototype
`f32 maxf(f32 a, f32 b);`
[:arrow_up_small:](#)
<br />
## [min](#min)
### Lua Example
`local integerValue = min(a, b)`
### Parameters
| Field | Type |
| ----- | ---- |
| a | `integer` |
| b | `integer` |
### Returns
- `integer`
### C Prototype
`s32 min(s32 a, s32 b);`
[:arrow_up_small:](#)
<br />
## [minf](#minf)
### Lua Example
`local numberValue = minf(a, b)`
### Parameters
| Field | Type |
| ----- | ---- |
| a | `number` |
| b | `number` |
### Returns
- `number`
### C Prototype
`f32 minf(f32 a, f32 b);`
[:arrow_up_small:](#)
<br />
## [sqr](#sqr)
### Lua Example
`local integerValue = sqr(x)`
### Parameters
| Field | Type |
| ----- | ---- |
| x | `integer` |
### Returns
- `integer`
### C Prototype
`s32 sqr(s32 x);`
[:arrow_up_small:](#)
<br />
## [sqrf](#sqrf)
### Lua Example
`local numberValue = sqrf(x)`
### Parameters
| Field | Type |
| ----- | ---- |
| x | `number` |
### Returns
- `number`
### C Prototype
`f32 sqrf(f32 x);`
[:arrow_up_small:](#)
<br />
---
# functions from smlua_misc_utils.h
@ -7718,6 +8051,166 @@
<br />
## [obj_is_attackable](#obj_is_attackable)
### Lua Example
`local booleanValue = obj_is_attackable(o)`
### Parameters
| Field | Type |
| ----- | ---- |
| o | [Object](structs.md#Object) |
### Returns
- `boolean`
### C Prototype
`bool obj_is_attackable(struct Object *o);`
[:arrow_up_small:](#)
<br />
## [obj_is_breakable_object](#obj_is_breakable_object)
### Lua Example
`local booleanValue = obj_is_breakable_object(o)`
### Parameters
| Field | Type |
| ----- | ---- |
| o | [Object](structs.md#Object) |
### Returns
- `boolean`
### C Prototype
`bool obj_is_breakable_object(struct Object *o);`
[:arrow_up_small:](#)
<br />
## [obj_is_bully](#obj_is_bully)
### Lua Example
`local booleanValue = obj_is_bully(o)`
### Parameters
| Field | Type |
| ----- | ---- |
| o | [Object](structs.md#Object) |
### Returns
- `boolean`
### C Prototype
`bool obj_is_bully(struct Object *o);`
[:arrow_up_small:](#)
<br />
## [obj_is_coin](#obj_is_coin)
### Lua Example
`local booleanValue = obj_is_coin(o)`
### Parameters
| Field | Type |
| ----- | ---- |
| o | [Object](structs.md#Object) |
### Returns
- `boolean`
### C Prototype
`bool obj_is_coin(struct Object *o);`
[:arrow_up_small:](#)
<br />
## [obj_is_exclamation_box](#obj_is_exclamation_box)
### Lua Example
`local booleanValue = obj_is_exclamation_box(o)`
### Parameters
| Field | Type |
| ----- | ---- |
| o | [Object](structs.md#Object) |
### Returns
- `boolean`
### C Prototype
`bool obj_is_exclamation_box(struct Object *o);`
[:arrow_up_small:](#)
<br />
## [obj_is_grabbable](#obj_is_grabbable)
### Lua Example
`local booleanValue = obj_is_grabbable(o)`
### Parameters
| Field | Type |
| ----- | ---- |
| o | [Object](structs.md#Object) |
### Returns
- `boolean`
### C Prototype
`bool obj_is_grabbable(struct Object *o) ;`
[:arrow_up_small:](#)
<br />
## [obj_is_mushroom_1up](#obj_is_mushroom_1up)
### Lua Example
`local booleanValue = obj_is_mushroom_1up(o)`
### Parameters
| Field | Type |
| ----- | ---- |
| o | [Object](structs.md#Object) |
### Returns
- `boolean`
### C Prototype
`bool obj_is_mushroom_1up(struct Object *o);`
[:arrow_up_small:](#)
<br />
## [obj_is_secret](#obj_is_secret)
### Lua Example
`local booleanValue = obj_is_secret(o)`
### Parameters
| Field | Type |
| ----- | ---- |
| o | [Object](structs.md#Object) |
### Returns
- `boolean`
### C Prototype
`bool obj_is_secret(struct Object *o);`
[:arrow_up_small:](#)
<br />
## [obj_is_valid_for_interaction](#obj_is_valid_for_interaction)
### Lua Example
@ -8428,223 +8921,7 @@
[:arrow_up_small:](#)
<br />
---
# functions from surface_collision.h
<br />
## [find_ceil_height](#find_ceil_height)
### Lua Example
`local numberValue = find_ceil_height(x, y, z)`
### Parameters
| Field | Type |
| ----- | ---- |
| x | `number` |
| y | `number` |
| z | `number` |
### Returns
- `number`
### C Prototype
`f32 find_ceil_height(f32 x, f32 y, f32 z);`
[:arrow_up_small:](#)
<br />
## [find_floor_height](#find_floor_height)
### Lua Example
`local numberValue = find_floor_height(x, y, z)`
### Parameters
| Field | Type |
| ----- | ---- |
| x | `number` |
| y | `number` |
| z | `number` |
### Returns
- `number`
### C Prototype
`f32 find_floor_height(f32 x, f32 y, f32 z);`
[:arrow_up_small:](#)
<br />
## [find_poison_gas_level](#find_poison_gas_level)
### Lua Example
`local numberValue = find_poison_gas_level(x, z)`
### Parameters
| Field | Type |
| ----- | ---- |
| x | `number` |
| z | `number` |
### Returns
- `number`
### C Prototype
`f32 find_poison_gas_level(f32 x, f32 z);`
[:arrow_up_small:](#)
<br />
## [find_wall_collisions](#find_wall_collisions)
### Lua Example
`local integerValue = find_wall_collisions(colData)`
### Parameters
| Field | Type |
| ----- | ---- |
| colData | [WallCollisionData](structs.md#WallCollisionData) |
### Returns
- `integer`
### C Prototype
`s32 find_wall_collisions(struct WallCollisionData *colData);`
[:arrow_up_small:](#)
<br />
## [find_water_level](#find_water_level)
### Lua Example
`local numberValue = find_water_level(x, z)`
### Parameters
| Field | Type |
| ----- | ---- |
| x | `number` |
| z | `number` |
### Returns
- `number`
### C Prototype
`f32 find_water_level(f32 x, f32 z);`
[:arrow_up_small:](#)
<br />
---
# functions from surface_load.h
<br />
## [alloc_surface_pools](#alloc_surface_pools)
### Lua Example
`alloc_surface_pools()`
### Parameters
- None
### Returns
- None
### C Prototype
`void alloc_surface_pools(void);`
[:arrow_up_small:](#)
<br />
## [clear_dynamic_surfaces](#clear_dynamic_surfaces)
### Lua Example
`clear_dynamic_surfaces()`
### Parameters
- None
### Returns
- None
### C Prototype
`void clear_dynamic_surfaces(void);`
[:arrow_up_small:](#)
<br />
## [get_area_terrain_size](#get_area_terrain_size)
### Lua Example
`local integerValue = get_area_terrain_size(data)`
### Parameters
| Field | Type |
| ----- | ---- |
| data | `Pointer` <`integer`> |
### Returns
- `integer`
### C Prototype
`u32 get_area_terrain_size(s16 *data);`
[:arrow_up_small:](#)
<br />
## [load_area_terrain](#load_area_terrain)
### Lua Example
`load_area_terrain(index, data, surfaceRooms, macroObjects)`
### Parameters
| Field | Type |
| ----- | ---- |
| index | `integer` |
| data | `Pointer` <`integer`> |
| surfaceRooms | `Pointer` <`integer`> |
| macroObjects | `Pointer` <`integer`> |
### Returns
- None
### C Prototype
`void load_area_terrain(s16 index, s16 *data, s8 *surfaceRooms, s16 *macroObjects);`
[:arrow_up_small:](#)
<br />
## [load_object_collision_model](#load_object_collision_model)
### Lua Example
`load_object_collision_model()`
### Parameters
- None
### Returns
- None
### C Prototype
`void load_object_collision_model(void);`
[:arrow_up_small:](#)
<br />
---
[< prev](functions-3.md) | [1](functions.md) | [2](functions-2.md) | [3](functions-3.md) | 4]
[< prev](functions-3.md) | [1](functions.md) | [2](functions-2.md) | [3](functions-3.md) | 4 | [5](functions-5.md) | [next >](functions-5.md)]

226
docs/lua/functions-5.md Normal file
View file

@ -0,0 +1,226 @@
## [:rewind: Lua Functions](functions.md)
---
[< prev](functions-4.md) | [1](functions.md) | [2](functions-2.md) | [3](functions-3.md) | [4](functions-4.md) | 5]
---
# functions from surface_collision.h
<br />
## [find_ceil_height](#find_ceil_height)
### Lua Example
`local numberValue = find_ceil_height(x, y, z)`
### Parameters
| Field | Type |
| ----- | ---- |
| x | `number` |
| y | `number` |
| z | `number` |
### Returns
- `number`
### C Prototype
`f32 find_ceil_height(f32 x, f32 y, f32 z);`
[:arrow_up_small:](#)
<br />
## [find_floor_height](#find_floor_height)
### Lua Example
`local numberValue = find_floor_height(x, y, z)`
### Parameters
| Field | Type |
| ----- | ---- |
| x | `number` |
| y | `number` |
| z | `number` |
### Returns
- `number`
### C Prototype
`f32 find_floor_height(f32 x, f32 y, f32 z);`
[:arrow_up_small:](#)
<br />
## [find_poison_gas_level](#find_poison_gas_level)
### Lua Example
`local numberValue = find_poison_gas_level(x, z)`
### Parameters
| Field | Type |
| ----- | ---- |
| x | `number` |
| z | `number` |
### Returns
- `number`
### C Prototype
`f32 find_poison_gas_level(f32 x, f32 z);`
[:arrow_up_small:](#)
<br />
## [find_wall_collisions](#find_wall_collisions)
### Lua Example
`local integerValue = find_wall_collisions(colData)`
### Parameters
| Field | Type |
| ----- | ---- |
| colData | [WallCollisionData](structs.md#WallCollisionData) |
### Returns
- `integer`
### C Prototype
`s32 find_wall_collisions(struct WallCollisionData *colData);`
[:arrow_up_small:](#)
<br />
## [find_water_level](#find_water_level)
### Lua Example
`local numberValue = find_water_level(x, z)`
### Parameters
| Field | Type |
| ----- | ---- |
| x | `number` |
| z | `number` |
### Returns
- `number`
### C Prototype
`f32 find_water_level(f32 x, f32 z);`
[:arrow_up_small:](#)
<br />
---
# functions from surface_load.h
<br />
## [alloc_surface_pools](#alloc_surface_pools)
### Lua Example
`alloc_surface_pools()`
### Parameters
- None
### Returns
- None
### C Prototype
`void alloc_surface_pools(void);`
[:arrow_up_small:](#)
<br />
## [clear_dynamic_surfaces](#clear_dynamic_surfaces)
### Lua Example
`clear_dynamic_surfaces()`
### Parameters
- None
### Returns
- None
### C Prototype
`void clear_dynamic_surfaces(void);`
[:arrow_up_small:](#)
<br />
## [get_area_terrain_size](#get_area_terrain_size)
### Lua Example
`local integerValue = get_area_terrain_size(data)`
### Parameters
| Field | Type |
| ----- | ---- |
| data | `Pointer` <`integer`> |
### Returns
- `integer`
### C Prototype
`u32 get_area_terrain_size(s16 *data);`
[:arrow_up_small:](#)
<br />
## [load_area_terrain](#load_area_terrain)
### Lua Example
`load_area_terrain(index, data, surfaceRooms, macroObjects)`
### Parameters
| Field | Type |
| ----- | ---- |
| index | `integer` |
| data | `Pointer` <`integer`> |
| surfaceRooms | `Pointer` <`integer`> |
| macroObjects | `Pointer` <`integer`> |
### Returns
- None
### C Prototype
`void load_area_terrain(s16 index, s16 *data, s8 *surfaceRooms, s16 *macroObjects);`
[:arrow_up_small:](#)
<br />
## [load_object_collision_model](#load_object_collision_model)
### Lua Example
`load_object_collision_model()`
### Parameters
- None
### Returns
- None
### C Prototype
`void load_object_collision_model(void);`
[:arrow_up_small:](#)
<br />
---
[< prev](functions-4.md) | [1](functions.md) | [2](functions-2.md) | [3](functions-3.md) | [4](functions-4.md) | 5]

View file

@ -2,7 +2,7 @@
---
1 | [2](functions-2.md) | [3](functions-3.md) | [4](functions-4.md) | [next >](functions-2.md)]
1 | [2](functions-2.md) | [3](functions-3.md) | [4](functions-4.md) | [5](functions-5.md) | [next >](functions-2.md)]
---
@ -1320,11 +1320,18 @@
- [obj_set_behavior](functions-4.md#obj_set_behavior)
- [obj_set_billboard](functions-4.md#obj_set_billboard)
- [obj_set_cylboard](functions-4.md#obj_set_cylboard)
- [obj_set_face_angle](functions-4.md#obj_set_face_angle)
- [obj_set_face_angle_to_move_angle](functions-4.md#obj_set_face_angle_to_move_angle)
- [obj_set_gfx_angle](functions-4.md#obj_set_gfx_angle)
- [obj_set_gfx_pos](functions-4.md#obj_set_gfx_pos)
- [obj_set_gfx_pos_at_obj_pos](functions-4.md#obj_set_gfx_pos_at_obj_pos)
- [obj_set_gfx_pos_from_pos](functions-4.md#obj_set_gfx_pos_from_pos)
- [obj_set_gfx_scale](functions-4.md#obj_set_gfx_scale)
- [obj_set_held_state](functions-4.md#obj_set_held_state)
- [obj_set_hitbox](functions-4.md#obj_set_hitbox)
- [obj_set_hitbox_radius_and_height](functions-4.md#obj_set_hitbox_radius_and_height)
- [obj_set_hurtbox_radius_and_height](functions-4.md#obj_set_hurtbox_radius_and_height)
- [obj_set_move_angle](functions-4.md#obj_set_move_angle)
- [obj_set_parent_relative_pos](functions-4.md#obj_set_parent_relative_pos)
- [obj_set_pos](functions-4.md#obj_set_pos)
- [obj_set_pos_relative](functions-4.md#obj_set_pos_relative)
@ -1430,6 +1437,18 @@
<br />
- smlua_math_utils.h
- [clamp](functions-4.md#clamp)
- [clampf](functions-4.md#clampf)
- [max](functions-4.md#max)
- [maxf](functions-4.md#maxf)
- [min](functions-4.md#min)
- [minf](functions-4.md#minf)
- [sqr](functions-4.md#sqr)
- [sqrf](functions-4.md#sqrf)
<br />
- smlua_misc_utils.h
- [add_scroll_target](functions-4.md#add_scroll_target)
- [allocate_mario_action](functions-4.md#allocate_mario_action)
@ -1507,6 +1526,14 @@
- [obj_get_temp_spawn_particles_info](functions-4.md#obj_get_temp_spawn_particles_info)
- [obj_has_behavior_id](functions-4.md#obj_has_behavior_id)
- [obj_has_model_extended](functions-4.md#obj_has_model_extended)
- [obj_is_attackable](functions-4.md#obj_is_attackable)
- [obj_is_breakable_object](functions-4.md#obj_is_breakable_object)
- [obj_is_bully](functions-4.md#obj_is_bully)
- [obj_is_coin](functions-4.md#obj_is_coin)
- [obj_is_exclamation_box](functions-4.md#obj_is_exclamation_box)
- [obj_is_grabbable](functions-4.md#obj_is_grabbable)
- [obj_is_mushroom_1up](functions-4.md#obj_is_mushroom_1up)
- [obj_is_secret](functions-4.md#obj_is_secret)
- [obj_is_valid_for_interaction](functions-4.md#obj_is_valid_for_interaction)
- [obj_move_xyz](functions-4.md#obj_move_xyz)
- [obj_set_model_extended](functions-4.md#obj_set_model_extended)
@ -1557,20 +1584,20 @@
<br />
- surface_collision.h
- [find_ceil_height](functions-4.md#find_ceil_height)
- [find_floor_height](functions-4.md#find_floor_height)
- [find_poison_gas_level](functions-4.md#find_poison_gas_level)
- [find_wall_collisions](functions-4.md#find_wall_collisions)
- [find_water_level](functions-4.md#find_water_level)
- [find_ceil_height](functions-5.md#find_ceil_height)
- [find_floor_height](functions-5.md#find_floor_height)
- [find_poison_gas_level](functions-5.md#find_poison_gas_level)
- [find_wall_collisions](functions-5.md#find_wall_collisions)
- [find_water_level](functions-5.md#find_water_level)
<br />
- surface_load.h
- [alloc_surface_pools](functions-4.md#alloc_surface_pools)
- [clear_dynamic_surfaces](functions-4.md#clear_dynamic_surfaces)
- [get_area_terrain_size](functions-4.md#get_area_terrain_size)
- [load_area_terrain](functions-4.md#load_area_terrain)
- [load_object_collision_model](functions-4.md#load_object_collision_model)
- [alloc_surface_pools](functions-5.md#alloc_surface_pools)
- [clear_dynamic_surfaces](functions-5.md#clear_dynamic_surfaces)
- [get_area_terrain_size](functions-5.md#get_area_terrain_size)
- [load_area_terrain](functions-5.md#load_area_terrain)
- [load_object_collision_model](functions-5.md#load_object_collision_model)
<br />
@ -1774,5 +1801,5 @@ Retrieves a texture by name.
---
1 | [2](functions-2.md) | [3](functions-3.md) | [4](functions-4.md) | [next >](functions-2.md)]
1 | [2](functions-2.md) | [3](functions-3.md) | [4](functions-4.md) | [5](functions-5.md) | [next >](functions-2.md)]

View file

@ -517,6 +517,7 @@ s16 obj_turn_toward_object(struct Object *obj, struct Object *target, s16 angleI
void obj_set_parent_relative_pos(struct Object *obj, s16 relX, s16 relY, s16 relZ) {
if (obj == NULL) { return; }
obj->oParentRelativePosX = relX;
obj->oParentRelativePosY = relY;
obj->oParentRelativePosZ = relZ;
@ -524,6 +525,7 @@ void obj_set_parent_relative_pos(struct Object *obj, s16 relX, s16 relY, s16 rel
void obj_set_pos(struct Object *obj, s16 x, s16 y, s16 z) {
if (obj == NULL) { return; }
obj->oPosX = x;
obj->oPosY = y;
obj->oPosZ = z;
@ -531,6 +533,7 @@ void obj_set_pos(struct Object *obj, s16 x, s16 y, s16 z) {
void obj_set_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll) {
if (obj == NULL) { return; }
obj->oFaceAnglePitch = pitch;
obj->oFaceAngleYaw = yaw;
obj->oFaceAngleRoll = roll;
@ -540,6 +543,46 @@ void obj_set_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll) {
obj->oMoveAngleRoll = roll;
}
void obj_set_move_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll) {
if (obj == NULL) { return; }
obj->oMoveAnglePitch = pitch;
obj->oMoveAngleYaw = yaw;
obj->oMoveAngleRoll = roll;
}
void obj_set_face_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll) {
if (obj == NULL) { return; }
obj->oFaceAnglePitch = pitch;
obj->oFaceAngleYaw = yaw;
obj->oFaceAngleRoll = roll;
}
void obj_set_gfx_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll) {
if (obj == NULL) { return; }
obj->header.gfx.angle[0] = pitch;
obj->header.gfx.angle[1] = yaw;
obj->header.gfx.angle[2] = roll;
}
void obj_set_gfx_pos(struct Object *obj, f32 x, f32 y, f32 z) {
if (obj == NULL) { return; }
obj->header.gfx.pos[0] = x;
obj->header.gfx.pos[1] = y;
obj->header.gfx.pos[2] = z;
}
void obj_set_gfx_scale(struct Object *obj, f32 x, f32 y, f32 z) {
if (obj == NULL) { return; }
obj->header.gfx.scale[0] = x;
obj->header.gfx.scale[1] = y;
obj->header.gfx.scale[2] = z;
}
/*
* Spawns an object at an absolute location with a specified angle.
*/
@ -1795,6 +1838,20 @@ void obj_set_cylboard(struct Object *obj) {
obj->header.gfx.node.flags |= GRAPH_RENDER_CYLBOARD;
}
void obj_set_hitbox_radius_and_height(struct Object *o, f32 radius, f32 height) {
if (o == NULL) { return; }
o->hitboxRadius = radius;
o->hitboxHeight = height;
}
void obj_set_hurtbox_radius_and_height(struct Object *o, f32 radius, f32 height) {
if (o == NULL) { return; }
o->hurtboxRadius = radius;
o->hurtboxHeight = height;
}
void cur_obj_set_hitbox_radius_and_height(f32 radius, f32 height) {
o->hitboxRadius = radius;
o->hitboxHeight = height;

View file

@ -99,6 +99,11 @@ s16 obj_turn_toward_object(struct Object *obj, struct Object *target, s16 angleI
void obj_set_parent_relative_pos(struct Object *obj, s16 relX, s16 relY, s16 relZ);
void obj_set_pos(struct Object *obj, s16 x, s16 y, s16 z);
void obj_set_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll);
void obj_set_move_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll);
void obj_set_face_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll);
void obj_set_gfx_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll);
void obj_set_gfx_pos(struct Object *obj, f32 x, f32 y, f32 z);
void obj_set_gfx_scale(struct Object *obj, f32 x, f32 y, f32 z);
struct Object *spawn_object_abs_with_rot(struct Object *parent, s16 uselessArg, u32 model,
const BehaviorScript *behavior,
s16 x, s16 y, s16 z, s16 rx, s16 ry, s16 rz);
@ -199,6 +204,8 @@ void cur_obj_shake_y(f32 amount);
void cur_obj_start_cam_event(UNUSED struct Object *obj, s32 cameraEvent);
void set_mario_interact_hoot_if_in_range(UNUSED s32 sp0, UNUSED s32 sp4, f32 sp8);
void obj_set_billboard(struct Object *obj);
void obj_set_hitbox_radius_and_height(struct Object *o, f32 radius, f32 height);
void obj_set_hurtbox_radius_and_height(struct Object *o, f32 radius, f32 height);
void cur_obj_set_hitbox_radius_and_height(f32 radius, f32 height);
void cur_obj_set_hurtbox_radius_and_height(f32 radius, f32 height);
void obj_spawn_loot_blue_coins(struct Object *obj, s32 numCoins, f32 sp28, s16 posJitter);

View file

@ -136,9 +136,9 @@ void smlua_init(void) {
luaL_requiref(L, "debug", luaopen_debug, 1);
luaL_requiref(L, "io", luaopen_io, 1);
luaL_requiref(L, "os", luaopen_os, 1);
luaL_requiref(L, "package ", luaopen_package, 1);
#endif
luaL_requiref(L, "math", luaopen_math, 1);
//luaopen_package(L);
luaL_requiref(L, "string", luaopen_string, 1);
luaL_requiref(L, "table", luaopen_table, 1);
//luaopen_utf8(L);
@ -179,7 +179,11 @@ void smlua_init(void) {
void smlua_update(void) {
lua_State* L = gLuaState;
if (L == NULL) { return; }
smlua_call_event_hooks(HOOK_UPDATE);
// Collect our garbage after calling our hooks.
// If we don't, Lag can quickly build up from our mods.
lua_gc(L, LUA_GCCOLLECT, 0);
}
void smlua_shutdown(void) {

View file

@ -10,6 +10,7 @@ char gSmluaConstants[] = ""
" return a['_pointer'] == b['_pointer'] and a['_lot'] == b['_lot'] and a['_pointer'] ~= nil and a['_lot'] ~= nil\n"
" end\n"
"}\n"
"\n"
"_CPointer = {\n"
" __index = function (t,k)\n"
" return nil\n"
@ -23,6 +24,7 @@ char gSmluaConstants[] = ""
" return a['_pointer'] == b['_pointer'] and a['_pointer'] ~= nil and a['_lvt'] ~= nil\n"
" end\n"
"}\n"
"\n"
"_SyncTable = {\n"
" __index = function (t,k)\n"
" local _table = rawget(t, '_table')\n"
@ -34,6 +36,7 @@ char gSmluaConstants[] = ""
" _set_sync_table_field(t, k, v)\n"
" end\n"
"}\n"
"\n"
"_ReadOnlyTable = {\n"
" __index = function (t,k)\n"
" local _table = rawget(t, '_table')\n"
@ -42,6 +45,7 @@ char gSmluaConstants[] = ""
" __newindex = function (t,k,v)\n"
" end\n"
"}\n"
"\n"
"--- @param dest Vec3f\n"
"--- @param src Vec3f\n"
"--- @return Vec3f\n"
@ -51,6 +55,7 @@ char gSmluaConstants[] = ""
" dest.z = src.z\n"
" return dest\n"
"end\n"
"\n"
"--- @param dest Vec3f\n"
"--- @param x number\n"
"--- @param y number\n"
@ -62,6 +67,7 @@ char gSmluaConstants[] = ""
" dest.z = z\n"
" return dest\n"
"end\n"
"\n"
"--- @param dest Vec3f\n"
"--- @param a Vec3f\n"
"--- @return Vec3f\n"
@ -71,6 +77,7 @@ char gSmluaConstants[] = ""
" dest.z = dest.z + a.z\n"
" return dest\n"
"end\n"
"\n"
"--- @param dest Vec3f\n"
"--- @param a Vec3f\n"
"--- @param b Vec3f\n"
@ -81,6 +88,7 @@ char gSmluaConstants[] = ""
" dest.z = a.z + b.z\n"
" return dest\n"
"end\n"
"\n"
"--- @param dest Vec3f\n"
"--- @param a number\n"
"--- @return Vec3f\n"
@ -90,6 +98,7 @@ char gSmluaConstants[] = ""
" dest.z = dest.z * a\n"
" return dest\n"
"end\n"
"\n"
"--- @param dest Vec3f\n"
"--- @return Vec3f\n"
"function vec3f_normalize(dest)\n"
@ -97,23 +106,28 @@ char gSmluaConstants[] = ""
" if divisor == 0 then\n"
" return dest\n"
" end\n"
"\n"
" local invsqrt = 1.0 / divisor\n"
" dest.x = dest.x * invsqrt\n"
" dest.y = dest.y * invsqrt\n"
" dest.z = dest.z * invsqrt\n"
"\n"
" return dest\n"
"end\n"
"\n"
"--- @param a Vec3f\n"
"--- @return number\n"
"function vec3f_length(a)\n"
" return math.sqrt(a.x * a.x + a.y * a.y + a.z * a.z)\n"
"end\n"
"\n"
"--- @param a Vec3f\n"
"--- @param b Vec3f\n"
"--- @return number\n"
"function vec3f_dot(a, b)\n"
" return a.x * b.x + a.y * b.y + a.z * b.z\n"
"end\n"
"\n"
"--- @param vec Vec3f\n"
"--- @param onto Vec3f\n"
"--- @return Vec3f\n"
@ -125,6 +139,7 @@ char gSmluaConstants[] = ""
" vec3f_mul(out, numerator / denominator)\n"
" return out\n"
"end\n"
"\n"
"--- @param v1 Vec3f\n"
"--- @param v2 Vec3f\n"
"--- @return number\n"
@ -134,6 +149,7 @@ char gSmluaConstants[] = ""
" dz = v1.z - v2.z\n"
" return math.sqrt(dx * dx + dy * dy + dz * dz)\n"
"end\n"
"\n"
"--- @param dest Vec3s\n"
"--- @param src Vec3s\n"
"--- @return Vec3s\n"
@ -143,6 +159,7 @@ char gSmluaConstants[] = ""
" dest.z = src.z\n"
" return dest\n"
"end\n"
"\n"
"--- @param dest Vec3s\n"
"--- @param x number\n"
"--- @param y number\n"
@ -154,6 +171,7 @@ char gSmluaConstants[] = ""
" dest.z = z\n"
" return dest\n"
"end\n"
"\n"
"--- @param dest Vec3s\n"
"--- @param a Vec3s\n"
"--- @return Vec3s\n"
@ -163,6 +181,7 @@ char gSmluaConstants[] = ""
" dest.z = dest.z + a.z\n"
" return dest\n"
"end\n"
"\n"
"--- @param dest Vec3s\n"
"--- @param a Vec3s\n"
"--- @param b Vec3s\n"
@ -173,6 +192,7 @@ char gSmluaConstants[] = ""
" dest.z = a.z + b.z\n"
" return dest\n"
"end\n"
"\n"
"--- @param dest Vec3s\n"
"--- @param a number\n"
"--- @return Vec3s\n"
@ -182,6 +202,7 @@ char gSmluaConstants[] = ""
" dest.z = dest.z * a\n"
" return dest\n"
"end\n"
"\n"
"--- @param v1 Vec3s\n"
"--- @param v2 Vec3s\n"
"--- @return number\n"
@ -191,6 +212,7 @@ char gSmluaConstants[] = ""
" dz = v1.z - v2.z\n"
" return math.sqrt(dx * dx + dy * dy + dz * dz)\n"
"end\n"
"\n"
"--- @param current number\n"
"--- @param target number\n"
"--- @param inc number\n"
@ -210,6 +232,7 @@ char gSmluaConstants[] = ""
" end\n"
" return current;\n"
"end\n"
"\n"
"--- @param current number\n"
"--- @param target number\n"
"--- @param inc number\n"
@ -227,6 +250,7 @@ char gSmluaConstants[] = ""
" current = target\n"
" end\n"
" end\n"
"\n"
" -- keep within 32 bits\n"
" if current > 2147483647 then\n"
" current = -2147483648 + (current - 2147483647)\n"
@ -235,6 +259,7 @@ char gSmluaConstants[] = ""
" end\n"
" return current;\n"
"end\n"
"\n"
"--- @param bank number\n"
"--- @param soundID number\n"
"--- @param priority number\n"
@ -244,9 +269,11 @@ char gSmluaConstants[] = ""
" if flags == nil then flags = 0 end\n"
" return (bank << 28) | (soundID << 16) | (priority << 8) | flags | SOUND_STATUS_WAITING\n"
"end\n"
"\n"
"-------------\n"
"-- courses --\n"
"-------------\n"
"\n"
"--- @type integer\n"
"COURSE_NONE = 0\n"
"--- @type integer\n"

View file

@ -24,6 +24,7 @@
#include "src/pc/lua/utils/smlua_obj_utils.h"
#include "src/pc/lua/utils/smlua_misc_utils.h"
#include "src/pc/lua/utils/smlua_collision_utils.h"
#include "src/pc/lua/utils/smlua_math_utils.h"
#include "src/pc/lua/utils/smlua_model_utils.h"
#include "src/pc/lua/utils/smlua_text_utils.h"
#include "src/pc/lua/utils/smlua_audio_utils.h"
@ -15704,6 +15705,24 @@ int smlua_func_obj_set_cylboard(lua_State* L) {
return 1;
}
int smlua_func_obj_set_face_angle(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 4)) { return 0; }
struct Object* obj = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'obj_set_face_angle'"); return 0; }
s16 pitch = smlua_to_integer(L, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 2 for function 'obj_set_face_angle'"); return 0; }
s16 yaw = smlua_to_integer(L, 3);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 3 for function 'obj_set_face_angle'"); return 0; }
s16 roll = smlua_to_integer(L, 4);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 4 for function 'obj_set_face_angle'"); return 0; }
extern void obj_set_face_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll);
obj_set_face_angle(obj, pitch, yaw, roll);
return 1;
}
int smlua_func_obj_set_face_angle_to_move_angle(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
@ -15716,6 +15735,42 @@ int smlua_func_obj_set_face_angle_to_move_angle(lua_State* L) {
return 1;
}
int smlua_func_obj_set_gfx_angle(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 4)) { return 0; }
struct Object* obj = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'obj_set_gfx_angle'"); return 0; }
s16 pitch = smlua_to_integer(L, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 2 for function 'obj_set_gfx_angle'"); return 0; }
s16 yaw = smlua_to_integer(L, 3);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 3 for function 'obj_set_gfx_angle'"); return 0; }
s16 roll = smlua_to_integer(L, 4);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 4 for function 'obj_set_gfx_angle'"); return 0; }
extern void obj_set_gfx_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll);
obj_set_gfx_angle(obj, pitch, yaw, roll);
return 1;
}
int smlua_func_obj_set_gfx_pos(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 4)) { return 0; }
struct Object* obj = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'obj_set_gfx_pos'"); return 0; }
f32 x = smlua_to_number(L, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 2 for function 'obj_set_gfx_pos'"); return 0; }
f32 y = smlua_to_number(L, 3);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 3 for function 'obj_set_gfx_pos'"); return 0; }
f32 z = smlua_to_number(L, 4);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 4 for function 'obj_set_gfx_pos'"); return 0; }
extern void obj_set_gfx_pos(struct Object *obj, f32 x, f32 y, f32 z);
obj_set_gfx_pos(obj, x, y, z);
return 1;
}
int smlua_func_obj_set_gfx_pos_at_obj_pos(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 2)) { return 0; }
@ -15742,6 +15797,24 @@ int smlua_func_obj_set_gfx_pos_from_pos(lua_State* L) {
return 1;
}
int smlua_func_obj_set_gfx_scale(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 4)) { return 0; }
struct Object* obj = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'obj_set_gfx_scale'"); return 0; }
f32 x = smlua_to_number(L, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 2 for function 'obj_set_gfx_scale'"); return 0; }
f32 y = smlua_to_number(L, 3);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 3 for function 'obj_set_gfx_scale'"); return 0; }
f32 z = smlua_to_number(L, 4);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 4 for function 'obj_set_gfx_scale'"); return 0; }
extern void obj_set_gfx_scale(struct Object *obj, f32 x, f32 y, f32 z);
obj_set_gfx_scale(obj, x, y, z);
return 1;
}
int smlua_func_obj_set_held_state(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 2)) { return 0; }
@ -15770,6 +15843,56 @@ int smlua_func_obj_set_hitbox(lua_State* L) {
return 1;
}
int smlua_func_obj_set_hitbox_radius_and_height(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 3)) { return 0; }
struct Object* o = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'obj_set_hitbox_radius_and_height'"); return 0; }
f32 radius = smlua_to_number(L, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 2 for function 'obj_set_hitbox_radius_and_height'"); return 0; }
f32 height = smlua_to_number(L, 3);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 3 for function 'obj_set_hitbox_radius_and_height'"); return 0; }
extern void obj_set_hitbox_radius_and_height(struct Object *o, f32 radius, f32 height);
obj_set_hitbox_radius_and_height(o, radius, height);
return 1;
}
int smlua_func_obj_set_hurtbox_radius_and_height(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 3)) { return 0; }
struct Object* o = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'obj_set_hurtbox_radius_and_height'"); return 0; }
f32 radius = smlua_to_number(L, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 2 for function 'obj_set_hurtbox_radius_and_height'"); return 0; }
f32 height = smlua_to_number(L, 3);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 3 for function 'obj_set_hurtbox_radius_and_height'"); return 0; }
extern void obj_set_hurtbox_radius_and_height(struct Object *o, f32 radius, f32 height);
obj_set_hurtbox_radius_and_height(o, radius, height);
return 1;
}
int smlua_func_obj_set_move_angle(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 4)) { return 0; }
struct Object* obj = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'obj_set_move_angle'"); return 0; }
s16 pitch = smlua_to_integer(L, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 2 for function 'obj_set_move_angle'"); return 0; }
s16 yaw = smlua_to_integer(L, 3);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 3 for function 'obj_set_move_angle'"); return 0; }
s16 roll = smlua_to_integer(L, 4);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 4 for function 'obj_set_move_angle'"); return 0; }
extern void obj_set_move_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll);
obj_set_move_angle(obj, pitch, yaw, roll);
return 1;
}
int smlua_func_obj_set_parent_relative_pos(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 4)) { return 0; }
@ -16847,6 +16970,114 @@ int smlua_func_warp_to_warpnode(lua_State* L) {
return 1;
}
////////////////////////
// smlua_math_utils.h //
////////////////////////
int smlua_func_clamp(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 3)) { return 0; }
s32 a = smlua_to_integer(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'clamp'"); return 0; }
s32 b = smlua_to_integer(L, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 2 for function 'clamp'"); return 0; }
s32 c = smlua_to_integer(L, 3);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 3 for function 'clamp'"); return 0; }
lua_pushinteger(L, clamp(a, b, c));
return 1;
}
int smlua_func_clampf(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 3)) { return 0; }
f32 a = smlua_to_number(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'clampf'"); return 0; }
f32 b = smlua_to_number(L, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 2 for function 'clampf'"); return 0; }
f32 c = smlua_to_number(L, 3);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 3 for function 'clampf'"); return 0; }
lua_pushnumber(L, clampf(a, b, c));
return 1;
}
int smlua_func_max(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 2)) { return 0; }
s32 a = smlua_to_integer(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'max'"); return 0; }
s32 b = smlua_to_integer(L, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 2 for function 'max'"); return 0; }
lua_pushinteger(L, max(a, b));
return 1;
}
int smlua_func_maxf(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 2)) { return 0; }
f32 a = smlua_to_number(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'maxf'"); return 0; }
f32 b = smlua_to_number(L, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 2 for function 'maxf'"); return 0; }
lua_pushnumber(L, maxf(a, b));
return 1;
}
int smlua_func_min(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 2)) { return 0; }
s32 a = smlua_to_integer(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'min'"); return 0; }
s32 b = smlua_to_integer(L, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 2 for function 'min'"); return 0; }
lua_pushinteger(L, min(a, b));
return 1;
}
int smlua_func_minf(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 2)) { return 0; }
f32 a = smlua_to_number(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'minf'"); return 0; }
f32 b = smlua_to_number(L, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 2 for function 'minf'"); return 0; }
lua_pushnumber(L, minf(a, b));
return 1;
}
int smlua_func_sqr(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
s32 x = smlua_to_integer(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'sqr'"); return 0; }
lua_pushinteger(L, sqr(x));
return 1;
}
int smlua_func_sqrf(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
f32 x = smlua_to_number(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'sqrf'"); return 0; }
lua_pushnumber(L, sqrf(x));
return 1;
}
////////////////////////
// smlua_misc_utils.h //
////////////////////////
@ -17637,6 +17868,94 @@ int smlua_func_obj_has_model_extended(lua_State* L) {
return 1;
}
int smlua_func_obj_is_attackable(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
struct Object* o = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'obj_is_attackable'"); return 0; }
lua_pushboolean(L, obj_is_attackable(o));
return 1;
}
int smlua_func_obj_is_breakable_object(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
struct Object* o = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'obj_is_breakable_object'"); return 0; }
lua_pushboolean(L, obj_is_breakable_object(o));
return 1;
}
int smlua_func_obj_is_bully(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
struct Object* o = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'obj_is_bully'"); return 0; }
lua_pushboolean(L, obj_is_bully(o));
return 1;
}
int smlua_func_obj_is_coin(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
struct Object* o = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'obj_is_coin'"); return 0; }
lua_pushboolean(L, obj_is_coin(o));
return 1;
}
int smlua_func_obj_is_exclamation_box(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
struct Object* o = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'obj_is_exclamation_box'"); return 0; }
lua_pushboolean(L, obj_is_exclamation_box(o));
return 1;
}
int smlua_func_obj_is_grabbable(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
struct Object* o = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'obj_is_grabbable'"); return 0; }
lua_pushboolean(L, obj_is_grabbable(o));
return 1;
}
int smlua_func_obj_is_mushroom_1up(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
struct Object* o = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'obj_is_mushroom_1up'"); return 0; }
lua_pushboolean(L, obj_is_mushroom_1up(o));
return 1;
}
int smlua_func_obj_is_secret(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
struct Object* o = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1 for function 'obj_is_secret'"); return 0; }
lua_pushboolean(L, obj_is_secret(o));
return 1;
}
int smlua_func_obj_is_valid_for_interaction(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
@ -19618,11 +19937,18 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "obj_set_billboard", smlua_func_obj_set_billboard);
//smlua_bind_function(L, "obj_set_collision_data", smlua_func_obj_set_collision_data); <--- UNIMPLEMENTED
smlua_bind_function(L, "obj_set_cylboard", smlua_func_obj_set_cylboard);
smlua_bind_function(L, "obj_set_face_angle", smlua_func_obj_set_face_angle);
smlua_bind_function(L, "obj_set_face_angle_to_move_angle", smlua_func_obj_set_face_angle_to_move_angle);
smlua_bind_function(L, "obj_set_gfx_angle", smlua_func_obj_set_gfx_angle);
smlua_bind_function(L, "obj_set_gfx_pos", smlua_func_obj_set_gfx_pos);
smlua_bind_function(L, "obj_set_gfx_pos_at_obj_pos", smlua_func_obj_set_gfx_pos_at_obj_pos);
smlua_bind_function(L, "obj_set_gfx_pos_from_pos", smlua_func_obj_set_gfx_pos_from_pos);
smlua_bind_function(L, "obj_set_gfx_scale", smlua_func_obj_set_gfx_scale);
smlua_bind_function(L, "obj_set_held_state", smlua_func_obj_set_held_state);
smlua_bind_function(L, "obj_set_hitbox", smlua_func_obj_set_hitbox);
smlua_bind_function(L, "obj_set_hitbox_radius_and_height", smlua_func_obj_set_hitbox_radius_and_height);
smlua_bind_function(L, "obj_set_hurtbox_radius_and_height", smlua_func_obj_set_hurtbox_radius_and_height);
smlua_bind_function(L, "obj_set_move_angle", smlua_func_obj_set_move_angle);
smlua_bind_function(L, "obj_set_parent_relative_pos", smlua_func_obj_set_parent_relative_pos);
smlua_bind_function(L, "obj_set_pos", smlua_func_obj_set_pos);
smlua_bind_function(L, "obj_set_pos_relative", smlua_func_obj_set_pos_relative);
@ -19715,6 +20041,16 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "warp_to_start_level", smlua_func_warp_to_start_level);
smlua_bind_function(L, "warp_to_warpnode", smlua_func_warp_to_warpnode);
// smlua_math_utils.h
smlua_bind_function(L, "clamp", smlua_func_clamp);
smlua_bind_function(L, "clampf", smlua_func_clampf);
smlua_bind_function(L, "max", smlua_func_max);
smlua_bind_function(L, "maxf", smlua_func_maxf);
smlua_bind_function(L, "min", smlua_func_min);
smlua_bind_function(L, "minf", smlua_func_minf);
smlua_bind_function(L, "sqr", smlua_func_sqr);
smlua_bind_function(L, "sqrf", smlua_func_sqrf);
// smlua_misc_utils.h
smlua_bind_function(L, "add_scroll_target", smlua_func_add_scroll_target);
smlua_bind_function(L, "allocate_mario_action", smlua_func_allocate_mario_action);
@ -19788,6 +20124,14 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "obj_get_temp_spawn_particles_info", smlua_func_obj_get_temp_spawn_particles_info);
smlua_bind_function(L, "obj_has_behavior_id", smlua_func_obj_has_behavior_id);
smlua_bind_function(L, "obj_has_model_extended", smlua_func_obj_has_model_extended);
smlua_bind_function(L, "obj_is_attackable", smlua_func_obj_is_attackable);
smlua_bind_function(L, "obj_is_breakable_object", smlua_func_obj_is_breakable_object);
smlua_bind_function(L, "obj_is_bully", smlua_func_obj_is_bully);
smlua_bind_function(L, "obj_is_coin", smlua_func_obj_is_coin);
smlua_bind_function(L, "obj_is_exclamation_box", smlua_func_obj_is_exclamation_box);
smlua_bind_function(L, "obj_is_grabbable", smlua_func_obj_is_grabbable);
smlua_bind_function(L, "obj_is_mushroom_1up", smlua_func_obj_is_mushroom_1up);
smlua_bind_function(L, "obj_is_secret", smlua_func_obj_is_secret);
smlua_bind_function(L, "obj_is_valid_for_interaction", smlua_func_obj_is_valid_for_interaction);
smlua_bind_function(L, "obj_move_xyz", smlua_func_obj_move_xyz);
smlua_bind_function(L, "obj_set_model_extended", smlua_func_obj_set_model_extended);

View file

@ -0,0 +1,38 @@
#include "sm64.h"
#include "types.h"
s32 min(s32 a, s32 b) {
return ((a) <= (b) ? (a) : (b));
}
f32 minf(f32 a, f32 b) {
return ((a) <= (b) ? (a) : (b));
}
s32 max(s32 a, s32 b) {
return ((a) > (b) ? (a) : (b));
}
f32 maxf(f32 a, f32 b) {
return ((a) > (b) ? (a) : (b));
}
s32 sqr(s32 x) {
return x * x;
}
f32 sqrf(f32 x) {
return x * x;
}
s32 clamp(s32 a, s32 b, s32 c) {
if (a < b) { return b; }
if (a > c) { return c; }
return a;
}
f32 clampf(f32 a, f32 b, f32 c) {
if (a < b) { return b; }
if (a > c) { return c; }
return a;
}

View file

@ -0,0 +1,28 @@
#ifndef SMLUA_MATH_UTILS_H
#define SMLUA_MATH_UTILS_H
#if defined(min)
#undef min
#endif
#if defined(max)
#undef max
#endif
#if defined(sqr)
#undef sqr
#endif
s32 min(s32 a, s32 b);
f32 minf(f32 a, f32 b);
s32 max(s32 a, s32 b);
f32 maxf(f32 a, f32 b);
s32 sqr(s32 x);
f32 sqrf(f32 x);
s32 clamp(s32 a, s32 b, s32 c);
f32 clampf(f32 a, f32 b, f32 c);
#endif

View file

@ -260,7 +260,73 @@ struct ObjectHitbox* get_temp_object_hitbox(void) {
return &sTmpHitbox;
}
bool obj_is_attackable(struct Object *o) {
if (o == NULL) { return FALSE; }
return ((o->oInteractType & INTERACT_KOOPA) != 0 ||
(o->oInteractType & INTERACT_BOUNCE_TOP) != 0 ||
(o->oInteractType & INTERACT_BOUNCE_TOP2) != 0 ||
(o->oInteractType & INTERACT_HIT_FROM_BELOW) != 0);
}
bool obj_is_breakable_object(struct Object *o) {
if (o == NULL) { return FALSE; }
return (obj_has_behavior_id(o, id_bhvBreakableBox) == 1 ||
obj_has_behavior_id(o, id_bhvBreakableBoxSmall) == 1 ||
obj_has_behavior_id(o, id_bhvHiddenObject) == 1 ||
obj_has_behavior_id(o, id_bhvJumpingBox) == 1);
}
bool obj_is_bully(struct Object *o) {
if (o == NULL) { return FALSE; }
return (o->oInteractType & INTERACT_BULLY) != 0;
}
bool obj_is_coin(struct Object *o) {
if (o == NULL) { return FALSE; }
return (o->oInteractType & INTERACT_COIN) != 0;
}
bool obj_is_exclamation_box(struct Object *o) {
if (o == NULL) { return FALSE; }
return obj_has_behavior_id(o, id_bhvExclamationBox) == 1 && o->oAction == 2;
}
bool obj_is_grabbable(struct Object *o) {
if (o == NULL) { return FALSE; }
return (o->oInteractType & INTERACT_GRABBABLE) != 0 && (o->oInteractionSubtype & INT_SUBTYPE_NOT_GRABBABLE) == 0;
}
bool obj_is_mushroom_1up(struct Object *o) {
if (o == NULL) { return FALSE; }
return (o->header.gfx.node.flags & GRAPH_RENDER_INVISIBLE) == 0 && (
obj_has_behavior_id(o, id_bhv1Up) == 1 ||
obj_has_behavior_id(o, id_bhv1upJumpOnApproach) == 1 ||
obj_has_behavior_id(o, id_bhv1upRunningAway) == 1 ||
obj_has_behavior_id(o, id_bhv1upSliding) == 1 ||
obj_has_behavior_id(o, id_bhv1upWalking) == 1 ||
obj_has_behavior_id(o, id_bhvHidden1up) == 1 ||
obj_has_behavior_id(o, id_bhvHidden1upInPole) == 1 ||
obj_has_behavior_id(o, id_bhvHidden1upInPoleSpawner) == 1 ||
obj_has_behavior_id(o, id_bhvHidden1upInPoleTrigger) == 1 ||
obj_has_behavior_id(o, id_bhvHidden1upTrigger) == 1);
}
bool obj_is_secret(struct Object *o) {
if (o == NULL) { return FALSE; }
return obj_has_behavior_id(o, id_bhvHiddenStarTrigger) == 1;
}
bool obj_is_valid_for_interaction(struct Object *o) {
if (o == NULL) { return FALSE; }
return o->activeFlags != ACTIVE_FLAG_DEACTIVATED && o->oIntangibleTimer == 0 && (o->oInteractStatus & INT_STATUS_INTERACTED) == 0;
}
@ -303,12 +369,16 @@ bool obj_check_overlap_with_hitbox_params(struct Object *o, f32 x, f32 y, f32 z,
}
void obj_set_vel(struct Object *o, f32 vx, f32 vy, f32 vz) {
if (o == NULL) { return; }
o->oVelX = vx;
o->oVelY = vy;
o->oVelZ = vz;
}
void obj_move_xyz(struct Object *o, f32 dx, f32 dy, f32 dz) {
if (o == NULL) { return; }
o->oPosX += dx;
o->oPosY += dy;
o->oPosZ += dz;

View file

@ -37,10 +37,21 @@ s32 obj_count_objects_with_behavior_id(enum BehaviorId behaviorId);
struct SpawnParticlesInfo* obj_get_temp_spawn_particles_info(enum ModelExtendedId modelId);
struct ObjectHitbox* get_temp_object_hitbox(void);
bool obj_is_attackable(struct Object *o);
bool obj_is_breakable_object(struct Object *o);
bool obj_is_bully(struct Object *o);
bool obj_is_coin(struct Object *o);
bool obj_is_exclamation_box(struct Object *o);
bool obj_is_grabbable(struct Object *o) ;
bool obj_is_mushroom_1up(struct Object *o);
bool obj_is_secret(struct Object *o);
bool obj_is_valid_for_interaction(struct Object *o);
bool obj_check_hitbox_overlap(struct Object *o1, struct Object *o2);
bool obj_check_overlap_with_hitbox_params(struct Object *o, f32 x, f32 y, f32 z, f32 h, f32 r, f32 d);
void obj_set_vel(struct Object *o, f32 vx, f32 vy, f32 vz);
void obj_move_xyz(struct Object *o, f32 dx, f32 dy, f32 dz);
#endif