Made the entry level configurable by Lua

This commit is contained in:
MysterD 2022-04-08 19:39:22 -07:00
parent 403bf30be9
commit 37367a9756
14 changed files with 54 additions and 5 deletions

View file

@ -31,6 +31,9 @@ gPlayerSyncTable = {}
--- @type StarPositions
gStarPositions = {}
--- @type LevelValues
gLevelValues = {}
-----------
-- hooks --
-----------

View file

@ -440,6 +440,9 @@
--- @field public unusedVec2 Vec3s
--- @field public yaw integer
--- @class LevelValues
--- @field public entryLevel LevelNum
--- @class LinearTransitionPoint
--- @field public dist number
--- @field public focus Vec3f

View file

@ -65,6 +65,13 @@ The `gGlobalObjectCollisionData` table contains references to object collision d
<br />
## [gLevelValues](#gLevelValues)
`gLevelValues`'s fields are listed in [LevelValue](structs.md#LevelValue).
[:arrow_up_small:](#)
<br />
## [gServerSettings](#gServerSettings)
`gServerSettings`'s fields are listed in [ServerSettings](structs.md#ServerSettings).

View file

@ -25,6 +25,7 @@
- [HandheldShakePoint](#HandheldShakePoint)
- [InstantWarp](#InstantWarp)
- [LakituState](#LakituState)
- [LevelValues](#LevelValues)
- [LinearTransitionPoint](#LinearTransitionPoint)
- [MarioAnimDmaRelatedThing](#MarioAnimDmaRelatedThing)
- [MarioAnimation](#MarioAnimation)
@ -674,6 +675,16 @@
<br />
## [LevelValues](#LevelValues)
| Field | Type | Access |
| ----- | ---- | ------ |
| entryLevel | [enum LevelNum](constants.md#enum-LevelNum) | |
[:arrow_up_small:](#)
<br />
## [LinearTransitionPoint](#LinearTransitionPoint)
| Field | Type | Access |

View file

@ -14,7 +14,6 @@
const LevelScript level_script_entry[] = {
SET_REG(/*value*/ LEVEL_CASTLE_GROUNDS),
//JUMP(/*target*/ level_main_scripts_entry),
EXECUTE(/*seg*/ 0x14, /*script*/ _introSegmentRomStart, /*scriptEnd*/ _introSegmentRomEnd, /*entry*/ level_main_scripts_entry),
JUMP(level_script_entry),

View file

@ -1,5 +1,9 @@
#include "hardcoded.h"
struct LevelValues gLevelValues = {
.entryLevel = LEVEL_CASTLE_GROUNDS,
};
struct StarPositions gStarPositions = {
.KoopaBobStarPos = { 3030.0f, 4500.0f, -4600.0f },
.KoopaThiStarPos = { 7100.0f, -1300.0f, -6000.0f },

View file

@ -1,5 +1,10 @@
#ifndef HARDCODED_H
#include "types.h"
#include "level_table.h"
struct LevelValues {
enum LevelNum entryLevel;
};
struct StarPositions {
Vec3f KoopaBobStarPos;
@ -30,6 +35,7 @@ struct StarPositions {
Vec3f JetstreamRingStarPos;
};
extern struct LevelValues gLevelValues;
extern struct StarPositions gStarPositions;
#endif

View file

@ -37,6 +37,7 @@
#include "sound_init.h"
#include "rumble_init.h"
#include "obj_behaviors.h"
#include "hardcoded.h"
#include "pc/configfile.h"
#include "pc/cheats.h"
#include "pc/network/network.h"
@ -1533,7 +1534,7 @@ void update_mario_inputs(struct MarioState *m) {
gCurrCreditsEntry = NULL;
gCurrActStarNum = 0;
gCurrActNum = 0;
gChangeLevel = 16;
gChangeLevel = gLevelValues.entryLevel;
}
if (m->playerIndex == 0) {

View file

@ -6,6 +6,7 @@
#include "src/pc/configfile.h"
#include "pc/utils/misc.h"
#include "src/game/level_update.h"
#include "src/game/hardcoded.h"
#include "audio/external.h"
#include "sounds.h"
@ -44,7 +45,7 @@ void djui_panel_host_message_do_host(UNUSED struct DjuiBase* caller) {
djui_panel_modlist_create(NULL);
fake_lvl_init_from_save_file();
extern s16 gChangeLevelTransition;
gChangeLevelTransition = 16;
gChangeLevelTransition = gLevelValues.entryLevel;
play_sound(SOUND_MENU_STAR_SOUND_OKEY_DOKEY, gGlobalSoundSource);
extern void play_transition(s16 transType, s16 time, u8 red, u8 green, u8 blue);
play_transition(0x09, 0x14, 0x00, 0x00, 0x00);

View file

@ -571,6 +571,11 @@ void smlua_cobject_init_globals(void) {
lua_setglobal(L, "gStarPositions");
}
{
smlua_push_object(L, LOT_LEVELVALUES, &gLevelValues);
lua_setglobal(L, "gLevelValues");
}
}
void smlua_cobject_init_per_file_globals(char* path) {

View file

@ -530,6 +530,11 @@ static struct LuaObjectField sLakituStateFields[LUA_LAKITU_STATE_FIELD_COUNT] =
{ "yaw", LVT_S16, offsetof(struct LakituState, yaw), false, LOT_NONE },
};
#define LUA_LEVEL_VALUES_FIELD_COUNT 1
static struct LuaObjectField sLevelValuesFields[LUA_LEVEL_VALUES_FIELD_COUNT] = {
{ "entryLevel", LVT_S32, offsetof(struct LevelValues, entryLevel), false, LOT_NONE },
};
#define LUA_LINEAR_TRANSITION_POINT_FIELD_COUNT 5
static struct LuaObjectField sLinearTransitionPointFields[LUA_LINEAR_TRANSITION_POINT_FIELD_COUNT] = {
{ "dist", LVT_F32, offsetof(struct LinearTransitionPoint, dist), false, LOT_NONE },
@ -1750,6 +1755,7 @@ struct LuaObjectTable sLuaObjectAutogenTable[LOT_AUTOGEN_MAX - LOT_AUTOGEN_MIN]
{ LOT_HANDHELDSHAKEPOINT, sHandheldShakePointFields, LUA_HANDHELD_SHAKE_POINT_FIELD_COUNT },
{ LOT_INSTANTWARP, sInstantWarpFields, LUA_INSTANT_WARP_FIELD_COUNT },
{ LOT_LAKITUSTATE, sLakituStateFields, LUA_LAKITU_STATE_FIELD_COUNT },
{ LOT_LEVELVALUES, sLevelValuesFields, LUA_LEVEL_VALUES_FIELD_COUNT },
{ LOT_LINEARTRANSITIONPOINT, sLinearTransitionPointFields, LUA_LINEAR_TRANSITION_POINT_FIELD_COUNT },
{ LOT_MARIOANIMATION, sMarioAnimationFields, LUA_MARIO_ANIMATION_FIELD_COUNT },
{ LOT_MARIOBODYSTATE, sMarioBodyStateFields, LUA_MARIO_BODY_STATE_FIELD_COUNT },

View file

@ -29,6 +29,7 @@ enum LuaObjectAutogenType {
LOT_HANDHELDSHAKEPOINT,
LOT_INSTANTWARP,
LOT_LAKITUSTATE,
LOT_LEVELVALUES,
LOT_LINEARTRANSITIONPOINT,
LOT_MARIOANIMATION,
LOT_MARIOBODYSTATE,

View file

@ -7,6 +7,7 @@
#include "pc/utils/misc.h"
#include "game/area.h"
#include "game/level_info.h"
#include "game/hardcoded.h"
#include "pc/lua/smlua_hooks.h"
struct NetworkPlayer gNetworkPlayers[MAX_PLAYERS] = { 0 };
@ -219,7 +220,7 @@ u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 mode
np->currLevelAreaSeqId = 0;
np->currLevelSyncValid = false;
np->currAreaSyncValid = false;
network_player_update_course_level(np, 0, 0, 16, 1);
network_player_update_course_level(np, 0, 0, gLevelValues.entryLevel, 1);
// update visuals
np->fadeOpacity = 0;

View file

@ -8,6 +8,7 @@
#include "src/engine/math_util.h"
#include "src/game/save_file.h"
#include "src/game/level_update.h"
#include "src/game/hardcoded.h"
#include "src/pc/fs/fs.h"
#include "PR/os_eeprom.h"
#include "pc/network/version.h"
@ -230,7 +231,7 @@ void network_receive_join(struct Packet* p) {
fake_lvl_init_from_save_file();
extern s16 gChangeLevel;
gChangeLevel = 16;
gChangeLevel = gLevelValues.entryLevel;
mods_activate(&gRemoteMods);
djui_panel_modlist_create(NULL);