mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2026-04-28 04:51:40 +00:00
Add two new LUA util functions. (#72)
This commit is contained in:
parent
da79a14cec
commit
2a405b3233
6 changed files with 120 additions and 0 deletions
|
|
@ -7262,6 +7262,12 @@ function obj_check_hitbox_overlap(o1, o2)
|
||||||
-- ...
|
-- ...
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- @param behaviorId BehaviorId
|
||||||
|
--- @return integer
|
||||||
|
function obj_count_objects_with_behavior_id(behaviorId)
|
||||||
|
-- ...
|
||||||
|
end
|
||||||
|
|
||||||
--- @param objList ObjectList
|
--- @param objList ObjectList
|
||||||
--- @return Object
|
--- @return Object
|
||||||
function obj_get_first(objList)
|
function obj_get_first(objList)
|
||||||
|
|
@ -7290,6 +7296,13 @@ function obj_get_first_with_behavior_id_and_field_s32(behaviorId, fieldIndex, va
|
||||||
-- ...
|
-- ...
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- @param o Object
|
||||||
|
--- @param behaviorId BehaviorId
|
||||||
|
--- @return Object
|
||||||
|
function obj_get_nearest_object_with_behavior_id(o, behaviorId)
|
||||||
|
-- ...
|
||||||
|
end
|
||||||
|
|
||||||
--- @param o Object
|
--- @param o Object
|
||||||
--- @return Object
|
--- @return Object
|
||||||
function obj_get_next(o)
|
function obj_get_next(o)
|
||||||
|
|
|
||||||
|
|
@ -5155,6 +5155,26 @@
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
|
## [obj_count_objects_with_behavior_id](#obj_count_objects_with_behavior_id)
|
||||||
|
|
||||||
|
### Lua Example
|
||||||
|
`local integerValue = obj_count_objects_with_behavior_id(behaviorId)`
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
| Field | Type |
|
||||||
|
| ----- | ---- |
|
||||||
|
| behaviorId | [enum BehaviorId](constants.md#enum-BehaviorId) |
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
- `integer`
|
||||||
|
|
||||||
|
### C Prototype
|
||||||
|
`s32 obj_count_objects_with_behavior_id(enum BehaviorId behaviorId);`
|
||||||
|
|
||||||
|
[:arrow_up_small:](#)
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
## [obj_get_first](#obj_get_first)
|
## [obj_get_first](#obj_get_first)
|
||||||
|
|
||||||
### Lua Example
|
### Lua Example
|
||||||
|
|
@ -5239,6 +5259,27 @@
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
|
## [obj_get_nearest_object_with_behavior_id](#obj_get_nearest_object_with_behavior_id)
|
||||||
|
|
||||||
|
### Lua Example
|
||||||
|
`local ObjectValue = obj_get_nearest_object_with_behavior_id(o, behaviorId)`
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
| Field | Type |
|
||||||
|
| ----- | ---- |
|
||||||
|
| o | [Object](structs.md#Object) |
|
||||||
|
| behaviorId | [enum BehaviorId](constants.md#enum-BehaviorId) |
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
[Object](structs.md#Object)
|
||||||
|
|
||||||
|
### C Prototype
|
||||||
|
`struct Object *obj_get_nearest_object_with_behavior_id(struct Object *o, enum BehaviorId behaviorId);`
|
||||||
|
|
||||||
|
[:arrow_up_small:](#)
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
## [obj_get_next](#obj_get_next)
|
## [obj_get_next](#obj_get_next)
|
||||||
|
|
||||||
### Lua Example
|
### Lua Example
|
||||||
|
|
|
||||||
|
|
@ -1363,10 +1363,12 @@
|
||||||
- [get_temp_object_hitbox](functions-4.md#get_temp_object_hitbox)
|
- [get_temp_object_hitbox](functions-4.md#get_temp_object_hitbox)
|
||||||
- [get_trajectory](functions-4.md#get_trajectory)
|
- [get_trajectory](functions-4.md#get_trajectory)
|
||||||
- [obj_check_hitbox_overlap](functions-4.md#obj_check_hitbox_overlap)
|
- [obj_check_hitbox_overlap](functions-4.md#obj_check_hitbox_overlap)
|
||||||
|
- [obj_count_objects_with_behavior_id](functions-4.md#obj_count_objects_with_behavior_id)
|
||||||
- [obj_get_first](functions-4.md#obj_get_first)
|
- [obj_get_first](functions-4.md#obj_get_first)
|
||||||
- [obj_get_first_with_behavior_id](functions-4.md#obj_get_first_with_behavior_id)
|
- [obj_get_first_with_behavior_id](functions-4.md#obj_get_first_with_behavior_id)
|
||||||
- [obj_get_first_with_behavior_id_and_field_f32](functions-4.md#obj_get_first_with_behavior_id_and_field_f32)
|
- [obj_get_first_with_behavior_id_and_field_f32](functions-4.md#obj_get_first_with_behavior_id_and_field_f32)
|
||||||
- [obj_get_first_with_behavior_id_and_field_s32](functions-4.md#obj_get_first_with_behavior_id_and_field_s32)
|
- [obj_get_first_with_behavior_id_and_field_s32](functions-4.md#obj_get_first_with_behavior_id_and_field_s32)
|
||||||
|
- [obj_get_nearest_object_with_behavior_id](functions-4.md#obj_get_nearest_object_with_behavior_id)
|
||||||
- [obj_get_next](functions-4.md#obj_get_next)
|
- [obj_get_next](functions-4.md#obj_get_next)
|
||||||
- [obj_get_next_with_same_behavior_id](functions-4.md#obj_get_next_with_same_behavior_id)
|
- [obj_get_next_with_same_behavior_id](functions-4.md#obj_get_next_with_same_behavior_id)
|
||||||
- [obj_get_next_with_same_behavior_id_and_field_f32](functions-4.md#obj_get_next_with_same_behavior_id_and_field_f32)
|
- [obj_get_next_with_same_behavior_id_and_field_f32](functions-4.md#obj_get_next_with_same_behavior_id_and_field_f32)
|
||||||
|
|
|
||||||
|
|
@ -14945,6 +14945,17 @@ int smlua_func_obj_check_hitbox_overlap(lua_State* L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int smlua_func_obj_count_objects_with_behavior_id(lua_State* L) {
|
||||||
|
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
|
||||||
|
|
||||||
|
int behaviorId = smlua_to_integer(L, 1);
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1"); return 0; }
|
||||||
|
|
||||||
|
lua_pushinteger(L, obj_count_objects_with_behavior_id(behaviorId));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int smlua_func_obj_get_first(lua_State* L) {
|
int smlua_func_obj_get_first(lua_State* L) {
|
||||||
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
|
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
|
||||||
|
|
||||||
|
|
@ -14997,6 +15008,19 @@ int smlua_func_obj_get_first_with_behavior_id_and_field_s32(lua_State* L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int smlua_func_obj_get_nearest_object_with_behavior_id(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) { LOG_LUA("Failed to convert parameter 1"); return 0; }
|
||||||
|
int behaviorId = smlua_to_integer(L, 2);
|
||||||
|
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 2"); return 0; }
|
||||||
|
|
||||||
|
smlua_push_object(L, LOT_OBJECT, obj_get_nearest_object_with_behavior_id(o, behaviorId));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int smlua_func_obj_get_next(lua_State* L) {
|
int smlua_func_obj_get_next(lua_State* L) {
|
||||||
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
|
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
|
||||||
|
|
||||||
|
|
@ -17069,10 +17093,12 @@ void smlua_bind_functions_autogen(void) {
|
||||||
smlua_bind_function(L, "get_temp_object_hitbox", smlua_func_get_temp_object_hitbox);
|
smlua_bind_function(L, "get_temp_object_hitbox", smlua_func_get_temp_object_hitbox);
|
||||||
smlua_bind_function(L, "get_trajectory", smlua_func_get_trajectory);
|
smlua_bind_function(L, "get_trajectory", smlua_func_get_trajectory);
|
||||||
smlua_bind_function(L, "obj_check_hitbox_overlap", smlua_func_obj_check_hitbox_overlap);
|
smlua_bind_function(L, "obj_check_hitbox_overlap", smlua_func_obj_check_hitbox_overlap);
|
||||||
|
smlua_bind_function(L, "obj_count_objects_with_behavior_id", smlua_func_obj_count_objects_with_behavior_id);
|
||||||
smlua_bind_function(L, "obj_get_first", smlua_func_obj_get_first);
|
smlua_bind_function(L, "obj_get_first", smlua_func_obj_get_first);
|
||||||
smlua_bind_function(L, "obj_get_first_with_behavior_id", smlua_func_obj_get_first_with_behavior_id);
|
smlua_bind_function(L, "obj_get_first_with_behavior_id", smlua_func_obj_get_first_with_behavior_id);
|
||||||
smlua_bind_function(L, "obj_get_first_with_behavior_id_and_field_f32", smlua_func_obj_get_first_with_behavior_id_and_field_f32);
|
smlua_bind_function(L, "obj_get_first_with_behavior_id_and_field_f32", smlua_func_obj_get_first_with_behavior_id_and_field_f32);
|
||||||
smlua_bind_function(L, "obj_get_first_with_behavior_id_and_field_s32", smlua_func_obj_get_first_with_behavior_id_and_field_s32);
|
smlua_bind_function(L, "obj_get_first_with_behavior_id_and_field_s32", smlua_func_obj_get_first_with_behavior_id_and_field_s32);
|
||||||
|
smlua_bind_function(L, "obj_get_nearest_object_with_behavior_id", smlua_func_obj_get_nearest_object_with_behavior_id);
|
||||||
smlua_bind_function(L, "obj_get_next", smlua_func_obj_get_next);
|
smlua_bind_function(L, "obj_get_next", smlua_func_obj_get_next);
|
||||||
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", 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_f32", smlua_func_obj_get_next_with_same_behavior_id_and_field_f32);
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,40 @@ struct Object *obj_get_first_with_behavior_id_and_field_f32(enum BehaviorId beha
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Object *obj_get_nearest_object_with_behavior_id(struct Object *o, enum BehaviorId behaviorId) {
|
||||||
|
f32 minDist = 0x20000;
|
||||||
|
const BehaviorScript *behavior = get_behavior_from_id(behaviorId);
|
||||||
|
struct Object *closestObj = NULL;
|
||||||
|
|
||||||
|
if (behavior) {
|
||||||
|
enum ObjectList objList = get_object_list_from_behavior(behavior);
|
||||||
|
for (struct Object *obj = obj_get_first(objList); obj != NULL; obj = obj_get_next(obj)) {
|
||||||
|
if (obj->behavior == behavior && obj->activeFlags != ACTIVE_FLAG_DEACTIVATED) {
|
||||||
|
f32 objDist = dist_between_objects(o, obj);
|
||||||
|
if (objDist < minDist) {
|
||||||
|
closestObj = obj;
|
||||||
|
minDist = objDist;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return closestObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
s32 obj_count_objects_with_behavior_id(enum BehaviorId behaviorId) {
|
||||||
|
const BehaviorScript *behavior = get_behavior_from_id(behaviorId);
|
||||||
|
s32 count = 0;
|
||||||
|
|
||||||
|
if (behavior) {
|
||||||
|
enum ObjectList objList = get_object_list_from_behavior(behavior);
|
||||||
|
for (struct Object *obj = obj_get_first(objList); obj != NULL; obj = obj_get_next(obj)) {
|
||||||
|
if (obj->behavior == behavior) { count++; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
struct Object *obj_get_next(struct Object *o) {
|
struct Object *obj_get_next(struct Object *o) {
|
||||||
if (gObjectLists && o) {
|
if (gObjectLists && o) {
|
||||||
enum ObjectList objList = get_object_list_from_behavior(o->behavior);
|
enum ObjectList objList = get_object_list_from_behavior(o->behavior);
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,10 @@ struct Object *obj_get_next_with_same_behavior_id(struct Object *o);
|
||||||
struct Object *obj_get_next_with_same_behavior_id_and_field_s32(struct Object *o, s32 fieldIndex, s32 value);
|
struct Object *obj_get_next_with_same_behavior_id_and_field_s32(struct Object *o, s32 fieldIndex, s32 value);
|
||||||
struct Object *obj_get_next_with_same_behavior_id_and_field_f32(struct Object *o, s32 fieldIndex, f32 value);
|
struct Object *obj_get_next_with_same_behavior_id_and_field_f32(struct Object *o, s32 fieldIndex, f32 value);
|
||||||
|
|
||||||
|
struct Object *obj_get_nearest_object_with_behavior_id(struct Object *o, enum BehaviorId behaviorId);
|
||||||
|
|
||||||
|
s32 obj_count_objects_with_behavior_id(enum BehaviorId behaviorId);
|
||||||
|
|
||||||
// misc obj helpers
|
// misc obj helpers
|
||||||
|
|
||||||
struct SpawnParticlesInfo* obj_get_temp_spawn_particles_info(enum ModelExtendedId modelId);
|
struct SpawnParticlesInfo* obj_get_temp_spawn_particles_info(enum ModelExtendedId modelId);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue