Add the ability to have global star IDs

Set gLevelValues.useGlobalStarIds on init, this value not being the same for everyone will cause desyncs.
This commit is contained in:
Agent X 2024-02-20 22:06:40 -05:00
parent 39e997cd48
commit 5fffa9e9d9
9 changed files with 18 additions and 9 deletions

View File

@ -919,6 +919,7 @@
--- @field public skipCreditsAt LevelNum
--- @field public starHeal integer
--- @field public starPositions StarPositions
--- @field public useGlobalStarIds integer
--- @field public vanishCapDuration integer
--- @field public vanishCapDurationVcutm integer
--- @field public vanishCapSequence SeqId

View File

@ -1258,6 +1258,7 @@
| skipCreditsAt | [enum LevelNum](constants.md#enum-LevelNum) | |
| starHeal | `integer` | |
| starPositions | [StarPositions](structs.md#StarPositions) | read-only |
| useGlobalStarIds | `integer` | |
| vanishCapDuration | `integer` | |
| vanishCapDurationVcutm | `integer` | |
| vanishCapSequence | [enum SeqId](constants.md#enum-SeqId) | |

View File

@ -17,8 +17,9 @@ void bhv_spawned_star_init(void) {
o->oBehParams = o->parentObj->oBehParams;
}
s32 starId = (o->oBehParams >> 24) & 0xFF;
if (bit_shift_left(starId) & save_file_get_star_flags(gCurrSaveFileNum - 1, gCurrCourseNum - 1))
if (bit_shift_left(gLevelValues.useGlobalStarIds ? starId % 7 : starId) & save_file_get_star_flags(gCurrSaveFileNum - 1, (gLevelValues.useGlobalStarIds ? (starId / 7) - 1 : gCurrCourseNum - 1))) {
cur_obj_set_model(smlua_model_util_load(E_MODEL_TRANSPARENT_STAR));
}
cur_obj_play_sound_2(SOUND_GENERAL2_STAR_APPEARS);
// exclamation box stars are not sent through the normal exclamation box

View File

@ -63,8 +63,8 @@ void bhv_collect_star_init(void) {
u8 currentLevelStarFlags;
starId = o->oBehParams >> 24;
currentLevelStarFlags = save_file_get_star_flags(gCurrSaveFileNum - 1, gCurrCourseNum - 1);
if (currentLevelStarFlags & (1 << starId)) {
currentLevelStarFlags = save_file_get_star_flags(gCurrSaveFileNum - 1, (gLevelValues.useGlobalStarIds ? (starId / 7) - 1 : gCurrCourseNum - 1));
if (currentLevelStarFlags & (1 << (gLevelValues.useGlobalStarIds ? starId % 7 : starId))) {
cur_obj_set_model(MODEL_TRANSPARENT_STAR);
} else {
cur_obj_set_model(MODEL_STAR);

View File

@ -121,7 +121,8 @@ struct LevelValues gDefaultLevelValues = {
.maxLives = 100,
.maxCoins = 999,
.numCoinsToLife = 50,
.wdwWaterLevelSpeed = 10.0f
.wdwWaterLevelSpeed = 10.0f,
.useGlobalStarIds = FALSE
};
struct LevelValues gLevelValues = { 0 };

View File

@ -87,6 +87,7 @@ struct LevelValues {
u16 maxCoins;
u16 numCoinsToLife;
f32 wdwWaterLevelSpeed;
u8 useGlobalStarIds;
};
extern struct LevelValues gLevelValues;

View File

@ -980,7 +980,7 @@ u32 interact_star_or_key(struct MarioState *m, UNUSED u32 interactType, struct O
m->interactObj = o;
m->usedObj = o;
starIndex = o->oBehParams >> 24;
starIndex = (o->oBehParams >> 24) & (gLevelValues.useGlobalStarIds ? 0xFF : 0x1F);
if (m == &gMarioStates[0]) {
// sync the star collection

View File

@ -10,6 +10,7 @@
#include "level_table.h"
#include "course_table.h"
#include "rumble_init.h"
#include "hardcoded.h"
#include "macros.h"
#include "pc/network/network.h"
#include "pc/lua/utils/smlua_level_utils.h"
@ -524,7 +525,8 @@ void save_file_collect_star_or_key(s16 coinScore, s16 starIndex, u8 fromNetwork)
if (INVALID_FILE_INDEX(fileIndex)) { return; }
if (INVALID_SRC_SLOT(gSaveFileUsingBackupSlot)) { return; }
s32 starFlag = 1 << starIndex;
s32 starByte = (starIndex / 7) - 1;
s32 starFlag = 1 << (gLevelValues.useGlobalStarIds ? (starIndex % 7) : starIndex);
UNUSED s32 flags = save_file_get_flags();
if (!fromNetwork) {
@ -568,8 +570,9 @@ void save_file_collect_star_or_key(s16 coinScore, s16 starIndex, u8 fromNetwork)
break;
default:
if (!(save_file_get_star_flags(fileIndex, courseIndex) & starFlag)) {
save_file_set_star_flags(fileIndex, courseIndex, starFlag);
s32 index = gLevelValues.useGlobalStarIds ? starByte : courseIndex;
if (!(save_file_get_star_flags(fileIndex, index) & starFlag)) {
save_file_set_star_flags(fileIndex, index, starFlag);
}
break;
}

View File

@ -994,7 +994,7 @@ 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 47
#define LUA_LEVEL_VALUES_FIELD_COUNT 48
static struct LuaObjectField sLevelValuesFields[LUA_LEVEL_VALUES_FIELD_COUNT] = {
{ "bubbleOnDeathBarrierInCapStages", LVT_U8, offsetof(struct LevelValues, bubbleOnDeathBarrierInCapStages), false, LOT_NONE },
{ "cellHeightLimit", LVT_S16, offsetof(struct LevelValues, cellHeightLimit), false, LOT_NONE },
@ -1034,6 +1034,7 @@ static struct LuaObjectField sLevelValuesFields[LUA_LEVEL_VALUES_FIELD_COUNT] =
{ "skipCreditsAt", LVT_S32, offsetof(struct LevelValues, skipCreditsAt), false, LOT_NONE },
{ "starHeal", LVT_U8, offsetof(struct LevelValues, starHeal), false, LOT_NONE },
{ "starPositions", LVT_COBJECT, offsetof(struct LevelValues, starPositions), true, LOT_STARPOSITIONS },
{ "useGlobalStarIds", LVT_U8, offsetof(struct LevelValues, useGlobalStarIds), false, LOT_NONE },
{ "vanishCapDuration", LVT_U16, offsetof(struct LevelValues, vanishCapDuration), false, LOT_NONE },
{ "vanishCapDurationVcutm", LVT_U16, offsetof(struct LevelValues, vanishCapDurationVcutm), false, LOT_NONE },
{ "vanishCapSequence", LVT_S32, offsetof(struct LevelValues, vanishCapSequence), false, LOT_NONE },