From b4507319b971bfac103d5ddb893aa24031868536 Mon Sep 17 00:00:00 2001
From: PeachyPeach <72323920+PeachyPeachSM64@users.noreply.github.com>
Date: Fri, 4 Mar 2022 01:46:01 +0100
Subject: [PATCH] Added functions: find_ceil_height and obj_set_model_extended
(#9)
* Added functions: find_ceil_height and obj_set_model_extended
---
docs/lua/functions.md | 45 ++++++++++++++++++++++++++++
src/engine/surface_collision.c | 8 +++++
src/engine/surface_collision.h | 1 +
src/pc/lua/smlua_functions_autogen.c | 30 +++++++++++++++++++
src/pc/lua/smlua_obj_utils.c | 4 +++
src/pc/lua/smlua_obj_utils.h | 2 ++
6 files changed, 90 insertions(+)
diff --git a/docs/lua/functions.md b/docs/lua/functions.md
index cfb39a42..fa5ff1cf 100644
--- a/docs/lua/functions.md
+++ b/docs/lua/functions.md
@@ -618,6 +618,7 @@
- [obj_get_next_with_same_behavior_id](#obj_get_next_with_same_behavior_id)
- [obj_get_next_with_same_behavior_id_and_field_f32](#obj_get_next_with_same_behavior_id_and_field_f32)
- [obj_get_next_with_same_behavior_id_and_field_s32](#obj_get_next_with_same_behavior_id_and_field_s32)
+ - [obj_set_model_extended](#obj_set_model_extended)
- [spawn_sync_object](#spawn_sync_object)
@@ -644,6 +645,7 @@
- surface_collision.h
+ - [find_ceil_height](#find_ceil_height)
- [find_floor_height](#find_floor_height)
- [find_poison_gas_level](#find_poison_gas_level)
- [find_wall_collisions](#find_wall_collisions)
@@ -11465,6 +11467,27 @@
+## [obj_set_model_extended](#obj_set_model_extended)
+
+### Lua Example
+`obj_set_model_extended(o, modelId)`
+
+### Parameters
+| Field | Type |
+| ----- | ---- |
+| o | [Object](structs.md#Object) |
+| modelId | integer |
+
+### Returns
+- None
+
+### C Prototype
+`void obj_set_model_extended(struct Object *o, enum ModelExtendedId modelId);`
+
+[:arrow_up_small:](#)
+
+
+
## [spawn_sync_object](#spawn_sync_object)
### Lua Example
@@ -11826,6 +11849,28 @@
+## [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:](#)
+
+
+
## [find_floor_height](#find_floor_height)
### Lua Example
diff --git a/src/engine/surface_collision.c b/src/engine/surface_collision.c
index dfc1a646..31238b95 100644
--- a/src/engine/surface_collision.c
+++ b/src/engine/surface_collision.c
@@ -358,6 +358,14 @@ f32 find_ceil(f32 posX, f32 posY, f32 posZ, struct Surface **pceil) {
return height;
}
+f32 find_ceil_height(f32 x, f32 y, f32 z) {
+ struct Surface *ceil;
+
+ f32 ceilHeight = find_ceil(x, y, z, &ceil);
+
+ return ceilHeight;
+}
+
/**************************************************
* FLOORS *
**************************************************/
diff --git a/src/engine/surface_collision.h b/src/engine/surface_collision.h
index b73d780f..5e162e21 100644
--- a/src/engine/surface_collision.h
+++ b/src/engine/surface_collision.h
@@ -33,6 +33,7 @@ struct FloorGeometry
s32 f32_find_wall_collision(f32 *xPtr, f32 *yPtr, f32 *zPtr, f32 offsetY, f32 radius);
s32 find_wall_collisions(struct WallCollisionData *colData);
f32 find_ceil(f32 posX, f32 posY, f32 posZ, struct Surface **pceil);
+f32 find_ceil_height(f32 x, f32 y, f32 z);
f32 find_floor_height_and_data(f32 xPos, f32 yPos, f32 zPos, struct FloorGeometry **floorGeo);
f32 find_floor_height(f32 x, f32 y, f32 z);
f32 find_floor(f32 xPos, f32 yPos, f32 zPos, struct Surface **pfloor);
diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c
index 4b135972..ce0f56a0 100644
--- a/src/pc/lua/smlua_functions_autogen.c
+++ b/src/pc/lua/smlua_functions_autogen.c
@@ -7371,6 +7371,19 @@ int smlua_func_obj_get_next_with_same_behavior_id_and_field_s32(lua_State* L) {
return 1;
}
+int smlua_func_obj_set_model_extended(lua_State* L) {
+ if(!smlua_functions_valid_param_count(L, 2)) { return 0; }
+
+ struct Object* o = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
+ if (!gSmLuaConvertSuccess) { return 0; }
+ int modelId = smlua_to_integer(L, 2);
+ if (!gSmLuaConvertSuccess) { return 0; }
+
+ obj_set_model_extended(o, modelId);
+
+ return 1;
+}
+
int smlua_func_spawn_sync_object(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 6)) { return 0; }
@@ -7592,6 +7605,21 @@ int smlua_func_find_ceil(lua_State* L) {
}
*/
+int smlua_func_find_ceil_height(lua_State* L) {
+ if(!smlua_functions_valid_param_count(L, 3)) { return 0; }
+
+ f32 x = smlua_to_number(L, 1);
+ if (!gSmLuaConvertSuccess) { return 0; }
+ f32 y = smlua_to_number(L, 2);
+ if (!gSmLuaConvertSuccess) { return 0; }
+ f32 z = smlua_to_number(L, 3);
+ if (!gSmLuaConvertSuccess) { return 0; }
+
+ lua_pushnumber(L, find_ceil_height(x, y, z));
+
+ return 1;
+}
+
/*
int smlua_func_find_floor(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 4)) { return 0; }
@@ -8372,6 +8400,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "obj_get_next_with_same_behavior_id", smlua_func_obj_get_next_with_same_behavior_id);
smlua_bind_function(L, "obj_get_next_with_same_behavior_id_and_field_f32", smlua_func_obj_get_next_with_same_behavior_id_and_field_f32);
smlua_bind_function(L, "obj_get_next_with_same_behavior_id_and_field_s32", smlua_func_obj_get_next_with_same_behavior_id_and_field_s32);
+ smlua_bind_function(L, "obj_set_model_extended", smlua_func_obj_set_model_extended);
smlua_bind_function(L, "spawn_sync_object", smlua_func_spawn_sync_object);
// sound_init.h
@@ -8395,6 +8424,7 @@ void smlua_bind_functions_autogen(void) {
// surface_collision.h
//smlua_bind_function(L, "find_ceil", smlua_func_find_ceil); <--- UNIMPLEMENTED
+ smlua_bind_function(L, "find_ceil_height", smlua_func_find_ceil_height);
//smlua_bind_function(L, "find_floor", smlua_func_find_floor); <--- UNIMPLEMENTED
smlua_bind_function(L, "find_floor_height", smlua_func_find_floor_height);
//smlua_bind_function(L, "find_floor_height_and_data", smlua_func_find_floor_height_and_data); <--- UNIMPLEMENTED
diff --git a/src/pc/lua/smlua_obj_utils.c b/src/pc/lua/smlua_obj_utils.c
index ac33e0ae..a2971205 100644
--- a/src/pc/lua/smlua_obj_utils.c
+++ b/src/pc/lua/smlua_obj_utils.c
@@ -78,6 +78,10 @@ struct Object* spawn_non_sync_object(enum BehaviorId behaviorId, enum ModelExten
spawn_object_internal(behaviorId, modelId, x, y, z, 0, false);
}
+void obj_set_model_extended(struct Object *o, enum ModelExtendedId modelId) {
+ o->header.gfx.sharedChild = gLoadedGraphNodes[smlua_model_util_load(modelId)];
+}
+
//
// Helpers to iterate through the object table
//
diff --git a/src/pc/lua/smlua_obj_utils.h b/src/pc/lua/smlua_obj_utils.h
index 6d010d63..8cda418f 100644
--- a/src/pc/lua/smlua_obj_utils.h
+++ b/src/pc/lua/smlua_obj_utils.h
@@ -10,6 +10,8 @@ struct Object* spawn_sync_object(enum BehaviorId behaviorId, enum ModelExtendedI
// this is too dangerous for now
//struct Object* spawn_non_sync_object(enum BehaviorId behaviorId, enum ModelExtendedId modelId, f32 x, f32 y, f32 z);
+void obj_set_model_extended(struct Object *o, enum ModelExtendedId modelId);
+
//
// Helpers to iterate through the object table
//