From 4aada40a62365af73f94abbe27f0e62855b48604 Mon Sep 17 00:00:00 2001 From: Agent X <44549182+Agent-11@users.noreply.github.com> Date: Mon, 20 Feb 2023 21:47:32 -0500 Subject: [PATCH] area_create_warp_node and area_get_warp_node* (#270) * area_get_warp_node* - Added area_get_warp_node to Lua - Added area_get_warp_node_from_params to Lua * area_create_warp_node and warp constants Here you go Isaac! * Add object param * Commits work again, pushing everything else --- autogen/convert_constants.py | 4 +- autogen/convert_functions.py | 8 ++- autogen/lua_definitions/constants.lua | 6 +++ autogen/lua_definitions/functions.lua | 23 ++++++++ docs/lua/constants.md | 9 ++++ docs/lua/functions-3.md | 31 +++++++++++ docs/lua/functions.md | 57 ++++++++++++++++++++ src/engine/level_script.c | 20 +++++++ src/engine/level_script.h | 2 + src/game/area.c | 2 + src/game/area.h | 1 + src/pc/lua/smlua_constants_autogen.c | 2 + src/pc/lua/smlua_functions_autogen.c | 78 +++++++++++++++++++++++++++ 13 files changed, 240 insertions(+), 3 deletions(-) diff --git a/autogen/convert_constants.py b/autogen/convert_constants.py index 4325b0d9..72bacd2e 100644 --- a/autogen/convert_constants.py +++ b/autogen/convert_constants.py @@ -38,7 +38,8 @@ in_files = [ "include/seq_ids.h", "include/surface_terrains.h", "src/game/level_update.h", - "src/pc/network/version.h" + "src/pc/network/version.h", + "include/level_commands.h" ] exclude_constants = { @@ -47,6 +48,7 @@ exclude_constants = { } include_constants = { + 'include/level_commands.h': [ "WARP_CHECKPOINT", "WARP_NO_CHECKPOINT" ], } pretend_find = [ diff --git a/autogen/convert_functions.py b/autogen/convert_functions.py index e25d05cc..85cfc9cc 100644 --- a/autogen/convert_functions.py +++ b/autogen/convert_functions.py @@ -55,7 +55,9 @@ in_files = [ "src/game/mario_misc.h", "src/pc/mods/mod_storage.h", "src/pc/utils/misc.h", - "src/game/level_update.h" + "src/game/level_update.h", + "src/game/area.h", + "src/engine/level_script.h" ] override_allowed_functions = { @@ -66,8 +68,10 @@ override_allowed_functions = { "src/pc/lua/utils/smlua_model_utils.h": [ "smlua_model_util_get_id" ], "src/game/object_list_processor.h": [ "set_object_respawn_info_bits" ], "src/game/mario_misc.h": [ "bhv_toad.*", "bhv_unlock_door.*" ], + "src/pc/utils/misc.h": [ "update_all_mario_stars" ], "src/game/level_update.h": [ "level_trigger_warp" ], - "src/pc/utils/misc.h": [ "update_all_mario_stars"], + "src/game/area.h": [ "area_get_warp_node" ], + "src/engine/level_script.h": [ "area_create_warp_node" ] } override_disallowed_functions = { diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index 68bb10ad..9ce4e5aa 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -3627,6 +3627,12 @@ INTERACT_IGLOO_BARRIER = (1 << 30) --- @type InteractionType INTERACT_PLAYER = (1 << 31) +--- @type integer +WARP_CHECKPOINT = 0x80 + +--- @type integer +WARP_NO_CHECKPOINT = 0x00 + --- @class LevelNum --- @type LevelNum diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index 5ba825e8..8ce36cac 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -1,5 +1,17 @@ -- AUTOGENERATED FOR CODE EDITORS -- +--- @param id integer +--- @return ObjectWarpNode +function area_get_warp_node(id) + -- ... +end + +--- @param o Object +--- @return ObjectWarpNode +function area_get_warp_node_from_params(o) + -- ... +end + --- @param a0 Vec3f --- @param a1 Vec3f --- @param yVel number @@ -4002,6 +4014,17 @@ function get_star_name_sm64(courseNum, starNum, charCase) -- ... end +--- @param id integer +--- @param destLevel integer +--- @param destArea integer +--- @param destNode integer +--- @param checkpoint integer +--- @param o Object +--- @return ObjectWarpNode +function area_create_warp_node(id, destLevel, destArea, destNode, checkpoint, o) + -- ... +end + --- @param m MarioState --- @param warpOp integer --- @return integer diff --git a/docs/lua/constants.md b/docs/lua/constants.md index 8d1e0121..d4cd3a84 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -19,6 +19,7 @@ - [enum InteractionFlag](#enum-InteractionFlag) - [interaction.h](#interactionh) - [enum InteractionType](#enum-InteractionType) +- [level_commands.h](#level_commandsh) - [level_defines.h](#level_definesh) - [enum LevelNum](#enum-LevelNum) - [level_update.h](#level_updateh) @@ -1244,6 +1245,14 @@
+## [level_commands.h](#level_commands.h) +- WARP_CHECKPOINT +- WARP_NO_CHECKPOINT + +[:arrow_up_small:](#) + +
+ ## [level_defines.h](#level_defines.h) ### [enum LevelNum](#LevelNum) diff --git a/docs/lua/functions-3.md b/docs/lua/functions-3.md index 0724862e..f482ff28 100644 --- a/docs/lua/functions-3.md +++ b/docs/lua/functions-3.md @@ -3358,6 +3358,37 @@
+--- +# functions from level_script.h + +
+ + +## [area_create_warp_node](#area_create_warp_node) + +### Lua Example +`local ObjectWarpNodeValue = area_create_warp_node(id, destLevel, destArea, destNode, checkpoint, o)` + +### Parameters +| Field | Type | +| ----- | ---- | +| id | `integer` | +| destLevel | `integer` | +| destArea | `integer` | +| destNode | `integer` | +| checkpoint | `integer` | +| o | [Object](structs.md#Object) | + +### Returns +[ObjectWarpNode](structs.md#ObjectWarpNode) + +### C Prototype +`struct ObjectWarpNode *area_create_warp_node(u8 id, u8 destLevel, u8 destArea, u8 destNode, u8 checkpoint, struct Object *o);` + +[:arrow_up_small:](#) + +
+ --- # functions from level_update.h diff --git a/docs/lua/functions.md b/docs/lua/functions.md index 8762e901..05600f76 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -20,6 +20,12 @@
+- area.h + - [area_get_warp_node](functions.md#area_get_warp_node) + - [area_get_warp_node_from_params](functions.md#area_get_warp_node_from_params) + +
+ - behavior_actions.h - [arc_to_goal_pos](functions-2.md#arc_to_goal_pos) - [bhv_1up_common_init](functions-2.md#bhv_1up_common_init) @@ -788,6 +794,11 @@
+- level_script.h + - [area_create_warp_node](functions-3.md#area_create_warp_node) + +
+ - level_update.h - [level_trigger_warp](functions-3.md#level_trigger_warp) @@ -1843,6 +1854,52 @@ Retrieves a texture by name.
+ +--- +# functions from area.h + +
+ + +## [area_get_warp_node](#area_get_warp_node) + +### Lua Example +`local ObjectWarpNodeValue = area_get_warp_node(id)` + +### Parameters +| Field | Type | +| ----- | ---- | +| id | `integer` | + +### Returns +[ObjectWarpNode](structs.md#ObjectWarpNode) + +### C Prototype +`struct ObjectWarpNode *area_get_warp_node(u8 id);` + +[:arrow_up_small:](#) + +
+ +## [area_get_warp_node_from_params](#area_get_warp_node_from_params) + +### Lua Example +`local ObjectWarpNodeValue = area_get_warp_node_from_params(o)` + +### Parameters +| Field | Type | +| ----- | ---- | +| o | [Object](structs.md#Object) | + +### Returns +[ObjectWarpNode](structs.md#ObjectWarpNode) + +### C Prototype +`struct ObjectWarpNode *area_get_warp_node_from_params(struct Object *o);` + +[:arrow_up_small:](#) + +
--- 1 | [2](functions-2.md) | [3](functions-3.md) | [4](functions-4.md) | [5](functions-5.md) | [next >](functions-2.md)] diff --git a/src/engine/level_script.c b/src/engine/level_script.c index 7f0b764b..a8c5c28d 100644 --- a/src/engine/level_script.c +++ b/src/engine/level_script.c @@ -102,6 +102,26 @@ static s32 eval_script_op(s8 op, s32 arg) { return result; } +struct ObjectWarpNode *area_create_warp_node(u8 id, u8 destLevel, u8 destArea, u8 destNode, u8 checkpoint, struct Object *o) { + if (sCurrAreaIndex != -1) { + struct ObjectWarpNode *warpNode = + alloc_only_pool_alloc(sLevelPool, sizeof(struct ObjectWarpNode)); + + warpNode->node.id = id; + warpNode->node.destLevel = destLevel + checkpoint; + warpNode->node.destArea = destArea; + warpNode->node.destNode = destNode; + + warpNode->object = o; + + warpNode->next = gAreas[sCurrAreaIndex].warpNodes; + gAreas[sCurrAreaIndex].warpNodes = warpNode; + + return warpNode; + } + return NULL; +} + static void area_check_red_coin_or_secret(void *arg, bool isMacroObject) { const BehaviorScript *bhv = NULL; if (isMacroObject) { diff --git a/src/engine/level_script.h b/src/engine/level_script.h index 280394f5..ba4557da 100644 --- a/src/engine/level_script.h +++ b/src/engine/level_script.h @@ -10,6 +10,8 @@ extern LevelScript* gLevelScriptActive; extern u8 level_script_entry[]; +struct ObjectWarpNode *area_create_warp_node(u8 id, u8 destLevel, u8 destArea, u8 destNode, u8 checkpoint, struct Object *o); + struct LevelCommand *level_script_execute(struct LevelCommand *cmd); #endif // LEVEL_SCRIPT_H diff --git a/src/game/area.c b/src/game/area.c index aaf527d4..cff1a61a 100644 --- a/src/game/area.c +++ b/src/game/area.c @@ -170,6 +170,8 @@ struct ObjectWarpNode *area_get_warp_node(u8 id) { } struct ObjectWarpNode *area_get_warp_node_from_params(struct Object *o) { + if (o == NULL) { return NULL; } + u8 sp1F = (o->oBehParams & 0x00FF0000) >> 16; return area_get_warp_node(sp1F); diff --git a/src/game/area.h b/src/game/area.h index 21492ac2..22ec1118 100644 --- a/src/game/area.h +++ b/src/game/area.h @@ -160,6 +160,7 @@ void override_viewport_and_clip(Vp *a, Vp *b, u8 c, u8 d, u8 e); void print_intro_text(void); u32 get_mario_spawn_type(struct Object *o); struct ObjectWarpNode *area_get_warp_node(u8 id); +struct ObjectWarpNode *area_get_warp_node_from_params(struct Object *o); void clear_areas(void); void clear_area_graph_nodes(void); void load_area(s32 index); diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index 494fd690..07ce0f3a 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -1398,6 +1398,8 @@ char gSmluaConstants[] = "" "INT_STATUS_HIT_MINE = (1 << 21)\n" "INT_STATUS_STOP_RIDING = (1 << 22)\n" "INT_STATUS_TOUCHED_BOB_OMB = (1 << 23)\n" +"WARP_CHECKPOINT = 0x80\n" +"WARP_NO_CHECKPOINT = 0x00\n" "LEVEL_NONE = 0\n" "LEVEL_UNKNOWN_1 = 1\n" "LEVEL_UNKNOWN_2 = 2\n" diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index ba681439..508c0813 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -35,8 +35,48 @@ #include "src/pc/mods/mod_storage.h" #include "src/pc/utils/misc.h" #include "src/game/level_update.h" +#include "src/game/area.h" +#include "src/engine/level_script.h" + //////////// + // area.h // +//////////// + +int smlua_func_area_get_warp_node(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", "area_get_warp_node", 1, top); + return 0; + } + + u8 id = smlua_to_integer(L, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "area_get_warp_node"); return 0; } + + smlua_push_object(L, LOT_OBJECTWARPNODE, area_get_warp_node(id)); + + return 1; +} + +int smlua_func_area_get_warp_node_from_params(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", "area_get_warp_node_from_params", 1, top); + return 0; + } + + struct Object* o = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "area_get_warp_node_from_params"); return 0; } + + smlua_push_object(L, LOT_OBJECTWARPNODE, area_get_warp_node_from_params(o)); + + return 1; +} + //////////////////////// // behavior_actions.h // //////////////////////// @@ -12605,6 +12645,37 @@ int smlua_func_get_star_name_sm64(lua_State* L) { return 1; } + //////////////////// + // level_script.h // +//////////////////// + +int smlua_func_area_create_warp_node(lua_State* L) { + if (L == NULL) { return 0; } + + int top = lua_gettop(L); + if (top != 6) { + LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "area_create_warp_node", 6, top); + return 0; + } + + u8 id = smlua_to_integer(L, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "area_create_warp_node"); return 0; } + u8 destLevel = smlua_to_integer(L, 2); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "area_create_warp_node"); return 0; } + u8 destArea = smlua_to_integer(L, 3); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "area_create_warp_node"); return 0; } + u8 destNode = smlua_to_integer(L, 4); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 4, "area_create_warp_node"); return 0; } + u8 checkpoint = smlua_to_integer(L, 5); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 5, "area_create_warp_node"); return 0; } + struct Object* o = (struct Object*)smlua_to_cobject(L, 6, LOT_OBJECT); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 6, "area_create_warp_node"); return 0; } + + smlua_push_object(L, LOT_OBJECTWARPNODE, area_create_warp_node(id, destLevel, destArea, destNode, checkpoint, o)); + + return 1; +} + //////////////////// // level_update.h // //////////////////// @@ -28721,6 +28792,10 @@ int smlua_func_load_object_collision_model(UNUSED lua_State* L) { void smlua_bind_functions_autogen(void) { lua_State* L = gLuaState; + // area.h + smlua_bind_function(L, "area_get_warp_node", smlua_func_area_get_warp_node); + smlua_bind_function(L, "area_get_warp_node_from_params", smlua_func_area_get_warp_node_from_params); + // behavior_actions.h smlua_bind_function(L, "arc_to_goal_pos", smlua_func_arc_to_goal_pos); smlua_bind_function(L, "bhv_1up_common_init", smlua_func_bhv_1up_common_init); @@ -29481,6 +29556,9 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "get_star_name_ascii", smlua_func_get_star_name_ascii); smlua_bind_function(L, "get_star_name_sm64", smlua_func_get_star_name_sm64); + // level_script.h + smlua_bind_function(L, "area_create_warp_node", smlua_func_area_create_warp_node); + // level_update.h smlua_bind_function(L, "level_trigger_warp", smlua_func_level_trigger_warp);