Adjusted how de-duplication of star spawns is done for red/hidden stars

This commit is contained in:
MysterD 2020-10-04 20:52:53 -07:00
parent c98edbcb4b
commit 2c7b42b331
5 changed files with 42 additions and 18 deletions

View File

@ -58,8 +58,10 @@ u32 gSpawnedStarDefault[8] = { 0 };
u8 gSpawnedStarDefaultCount = 0; u8 gSpawnedStarDefaultCount = 0;
u32 gSpawnedStarNLE[8] = { 0 }; u32 gSpawnedStarNLE[8] = { 0 };
u8 gSpawnedStarNLECount = 0; u8 gSpawnedStarNLECount = 0;
u8 gSpawnedStarRedCoin = 0; u32 gSpawnedStarRed[8] = { 0 };
u8 gSpawnedStarHidden = 0; u8 gSpawnedStarRedCount = 0;
u32 gSpawnedStarHidden[8] = { 0 };
u8 gSpawnedStarHiddenCount = 0;
/* /*
* The following two tables are used in get_mario_spawn_type() to determine spawn type * The following two tables are used in get_mario_spawn_type() to determine spawn type

View File

@ -142,8 +142,10 @@ extern u32 gSpawnedStarDefault[];
extern u8 gSpawnedStarDefaultCount; extern u8 gSpawnedStarDefaultCount;
extern u32 gSpawnedStarNLE[]; extern u32 gSpawnedStarNLE[];
extern u8 gSpawnedStarNLECount; extern u8 gSpawnedStarNLECount;
extern u8 gSpawnedStarRedCoin; extern u32 gSpawnedStarRed[];
extern u8 gSpawnedStarHidden; extern u8 gSpawnedStarRedCount;
extern u32 gSpawnedStarHidden[];
extern u8 gSpawnedStarHiddenCount;
void override_viewport_and_clip(Vp *a, Vp *b, u8 c, u8 d, u8 e); void override_viewport_and_clip(Vp *a, Vp *b, u8 c, u8 d, u8 e);
void print_intro_text(void); void print_intro_text(void);

View File

@ -125,16 +125,25 @@ struct Object *spawn_star(struct Object *sp30, f32 sp34, f32 sp38, f32 sp3C) {
return sp30; return sp30;
} }
static u8 spawn_star_deduplication(u32* array, u8* count, u32 behParams) {
for (int i = 0; i < *count; i++) {
if (array[i] == behParams) { return TRUE; }
}
if (*count < 8) {
array[*count] = behParams;
*count = *count + 1;
return FALSE;
}
return TRUE;
}
struct Object* spawn_default_star(f32 x, f32 y, f32 z) { struct Object* spawn_default_star(f32 x, f32 y, f32 z) {
if (sCurrPlayMode != PLAY_MODE_NORMAL && sCurrPlayMode != PLAY_MODE_PAUSED) { return NULL; } if (sCurrPlayMode != PLAY_MODE_NORMAL && sCurrPlayMode != PLAY_MODE_PAUSED) { return NULL; }
u32 behParams = o->oBehParams; u32 behParams = o->oBehParams;
// de-duplication checking // de-duplication checking
for (int i = 0; i < gSpawnedStarDefaultCount; i++) { if (spawn_star_deduplication(gSpawnedStarDefault, &gSpawnedStarDefaultCount, behParams)) {
if (gSpawnedStarDefault[i] == behParams) { return NULL; } return NULL;
}
if (gSpawnedStarDefaultCount < 8) {
gSpawnedStarDefault[gSpawnedStarDefaultCount++] = behParams;
} }
struct Object *star; struct Object *star;
@ -145,24 +154,32 @@ struct Object* spawn_default_star(f32 x, f32 y, f32 z) {
} }
struct Object* spawn_red_coin_cutscene_star(f32 x, f32 y, f32 z) { struct Object* spawn_red_coin_cutscene_star(f32 x, f32 y, f32 z) {
if (gSpawnedStarRedCoin) { return NULL; }
struct Object * star;
u32 behParams = o->oBehParams; u32 behParams = o->oBehParams;
// de-duplication checking
if (spawn_star_deduplication(gSpawnedStarRed, &gSpawnedStarRedCount, behParams)) {
return NULL;
}
struct Object * star;
star = spawn_star(star, x, y, z); star = spawn_star(star, x, y, z);
star->oBehParams2ndByte = 1; star->oBehParams2ndByte = 1;
gSpawnedStarRedCoin = TRUE;
network_send_spawn_star(star, 1, x, y, z, behParams); network_send_spawn_star(star, 1, x, y, z, behParams);
return star; return star;
} }
struct Object* spawn_no_exit_star(f32 x, f32 y, f32 z) { struct Object* spawn_no_exit_star(f32 x, f32 y, f32 z) {
if (gSpawnedStarHidden) { return NULL; }
struct Object * star;
u32 behParams = o->oBehParams; u32 behParams = o->oBehParams;
// de-duplication checking
if (spawn_star_deduplication(gSpawnedStarHidden, &gSpawnedStarHiddenCount, behParams)) {
return NULL;
}
struct Object * star;
star = spawn_star(star, x, y, z); star = spawn_star(star, x, y, z);
star->oBehParams2ndByte = 1; star->oBehParams2ndByte = 1;
star->oInteractionSubtype |= INT_SUBTYPE_NO_EXIT; star->oInteractionSubtype |= INT_SUBTYPE_NO_EXIT;
gSpawnedStarHidden = TRUE;
network_send_spawn_star(star, 2, x, y, z, behParams); network_send_spawn_star(star, 2, x, y, z, behParams);
return star; return star;
} }

View File

@ -1315,11 +1315,14 @@ s32 init_level(void) {
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
gSpawnedStarDefault[i] = 0; gSpawnedStarDefault[i] = 0;
gSpawnedStarNLE[i] = 0; gSpawnedStarNLE[i] = 0;
gSpawnedStarRed[i] = 0;
gSpawnedStarHidden[i] = 0;
} }
gSpawnedStarDefaultCount = 0; gSpawnedStarDefaultCount = 0;
gSpawnedStarNLECount = 0; gSpawnedStarNLECount = 0;
gSpawnedStarRedCoin = 0; gSpawnedStarRedCount = 0;
gSpawnedStarHidden = 0; gSpawnedStarHiddenCount = 0;
if (gCurrCreditsEntry == NULL) { if (gCurrCreditsEntry == NULL) {
gHudDisplay.flags = HUD_DISPLAY_DEFAULT; gHudDisplay.flags = HUD_DISPLAY_DEFAULT;

View File

@ -7,7 +7,7 @@
#ifdef DEBUG #ifdef DEBUG
static u8 warpToLevel = LEVEL_WF; static u8 warpToLevel = LEVEL_BOB;
#define SCANCODE_0 0x0B #define SCANCODE_0 0x0B
#define SCANCODE_1 0x02 #define SCANCODE_1 0x02