Make WARP_NODE commands able to read custom Lua registered levels

This commit is contained in:
Agent X 2024-04-17 17:40:53 -04:00
parent a6b938df75
commit d15ebf29d3

View file

@ -6,11 +6,11 @@ extern "C" {
#include "include/surface_terrains.h" #include "include/surface_terrains.h"
#include "include/seq_ids.h" #include "include/seq_ids.h"
#include "level_commands.h" #include "level_commands.h"
#include "src/game/level_update.h" #include "game/level_update.h"
#include "include/dialog_ids.h" #include "include/dialog_ids.h"
#include "levels/scripts.h" #include "levels/scripts.h"
#include "levels/menu/header.h" #include "levels/menu/header.h"
#include "src/game/area.h" #include "game/area.h"
} }
// Free data pointers, but keep nodes and tokens intact // Free data pointers, but keep nodes and tokens intact
@ -687,8 +687,6 @@ static void ParseLevelScriptSymbol(GfxData* aGfxData, DataNode<LevelScript>* aNo
lvl_symbol_3(MARIO, 2, 0, 0); lvl_symbol_3(MARIO, 2, 0, 0);
// warps // warps
lvl_symbol_5(WARP_NODE, 0, 0, 0);
lvl_symbol_5(PAINTING_WARP_NODE, 0, 0, 0);
lvl_symbol_5(INSTANT_WARP, 0, 0, 0); lvl_symbol_5(INSTANT_WARP, 0, 0, 0);
// misc // misc
@ -816,16 +814,64 @@ static void ParseLevelScriptSymbol(GfxData* aGfxData, DataNode<LevelScript>* aNo
// JUMP_AREA // JUMP_AREA
if (_Symbol == "JUMP_AREA") { if (_Symbol == "JUMP_AREA") {
LevelScript _Arg0 = ParseLevelScriptSymbolArg(aGfxData, aNode, aTokenIndex); LevelScript op = ParseLevelScriptSymbolArg(aGfxData, aNode, aTokenIndex);
LevelScript _Arg1 = ParseLevelScriptSymbolArg(aGfxData, aNode, aTokenIndex); LevelScript arg = ParseLevelScriptSymbolArg(aGfxData, aNode, aTokenIndex);
LevelScript _Arg2 = ParseLevelScriptSymbolArg(aGfxData, aNode, aTokenIndex); LevelScript target = ParseLevelScriptSymbolArg(aGfxData, aNode, aTokenIndex);
aGfxData->mPointerList.Add(aHead + 2); aGfxData->mPointerList.Add(aHead + 2);
LevelScript _Ls[] = { JUMP_AREA_EXT(_Arg0, _Arg1, _Arg2) }; LevelScript _Ls[] = { JUMP_AREA_EXT(op, arg, target) };
memcpy(aHead, _Ls, sizeof(_Ls)); memcpy(aHead, _Ls, sizeof(_Ls));
aHead += (sizeof(_Ls) / sizeof(_Ls[0])); aHead += (sizeof(_Ls) / sizeof(_Ls[0]));
return; return;
} }
// WARP_NODE
if (_Symbol == "WARP_NODE") {
u64 topTokenIndex = aTokenIndex;
bool foundLevel = true;
LevelScript id = ParseLevelScriptSymbolArg(aGfxData, aNode, aTokenIndex);
LevelScript destLevel = ParseLevelScriptSymbolArgInternal(aGfxData, aNode, aTokenIndex, &foundLevel);
LevelScript destArea = ParseLevelScriptSymbolArg(aGfxData, aNode, aTokenIndex);
LevelScript destNode = ParseLevelScriptSymbolArg(aGfxData, aNode, aTokenIndex);
LevelScript flags = ParseLevelScriptSymbolArg(aGfxData, aNode, aTokenIndex);
if (foundLevel) {
LevelScript _Ls[] = { WARP_NODE(id, destLevel, destArea, destNode, flags) };
memcpy(aHead, _Ls, sizeof(_Ls));
aHead += (sizeof(_Ls) / sizeof(_Ls[0]));
} else {
s16 destLevelIndex = DynOS_Lua_RememberVariable(aGfxData, aHead + 1, aNode->mTokens[topTokenIndex + 1]);
LevelScript _Ls[] = { WARP_NODE(id, destLevelIndex, destArea, destNode, flags) };
memcpy(aHead, _Ls, sizeof(_Ls));
aHead += (sizeof(_Ls) / sizeof(_Ls[0]));
}
return;
}
// PAINTING_WARP_NODE
if (_Symbol == "PAINTING_WARP_NODE") {
u64 topTokenIndex = aTokenIndex;
bool foundLevel = true;
LevelScript id = ParseLevelScriptSymbolArg(aGfxData, aNode, aTokenIndex);
LevelScript destLevel = ParseLevelScriptSymbolArgInternal(aGfxData, aNode, aTokenIndex, &foundLevel);
LevelScript destArea = ParseLevelScriptSymbolArg(aGfxData, aNode, aTokenIndex);
LevelScript destNode = ParseLevelScriptSymbolArg(aGfxData, aNode, aTokenIndex);
LevelScript flags = ParseLevelScriptSymbolArg(aGfxData, aNode, aTokenIndex);
if (foundLevel) {
LevelScript _Ls[] = { PAINTING_WARP_NODE(id, destLevel, destArea, destNode, flags) };
memcpy(aHead, _Ls, sizeof(_Ls));
aHead += (sizeof(_Ls) / sizeof(_Ls[0]));
} else {
s16 destLevelIndex = DynOS_Lua_RememberVariable(aGfxData, aHead + 1, aNode->mTokens[topTokenIndex + 1]);
LevelScript _Ls[] = { PAINTING_WARP_NODE(id, destLevelIndex, destArea, destNode, flags) };
memcpy(aHead, _Ls, sizeof(_Ls));
aHead += (sizeof(_Ls) / sizeof(_Ls[0]));
}
return;
}
// Unknown // Unknown
PrintDataError(" ERROR: Unknown lvl symbol: %s", _Symbol.begin()); PrintDataError(" ERROR: Unknown lvl symbol: %s", _Symbol.begin());
} }