Fix deduplication check for spawning stars

Stay in level after star option revealed that the deduplication
checking I was doing previously is no longer a valid way to do it.
The old way would prevent a second star from spawning.
This commit is contained in:
MysterD 2020-09-21 19:11:27 -07:00
parent d3d13c26f8
commit 01faa86bf0
4 changed files with 18 additions and 6 deletions

View File

@ -54,7 +54,8 @@ u8 gWarpTransBlue = 0;
s16 gCurrSaveFileNum = 1;
s16 gCurrLevelNum = LEVEL_MIN;
u8 gSpawnedStarDefault = 0;
u32 gSpawnedStarDefault[8] = { 0 };
u8 gSpawnedStarDefaultCount = 0;
u8 gSpawnedStarRedCoin = 0;
u8 gSpawnedStarHidden = 0;

View File

@ -138,7 +138,8 @@ extern struct Area *gCurrentArea;
extern s16 gCurrSaveFileNum;
extern s16 gCurrLevelNum;
extern u8 gSpawnedStarDefault;
extern u32 gSpawnedStarDefault[];
extern u8 gSpawnedStarDefaultCount;
extern u8 gSpawnedStarRedCoin;
extern u8 gSpawnedStarHidden;

View File

@ -127,12 +127,19 @@ struct Object *spawn_star(struct Object *sp30, f32 sp34, f32 sp38, f32 sp3C) {
struct Object* spawn_default_star(f32 x, f32 y, f32 z) {
if (sCurrPlayMode != PLAY_MODE_NORMAL && sCurrPlayMode != PLAY_MODE_PAUSED) { return NULL; }
if (gSpawnedStarDefault) { return NULL; }
struct Object *star;
u32 behParams = o->oBehParams;
// de-duplication checking
for (int i = 0; i < gSpawnedStarDefaultCount; i++) {
if (gSpawnedStarDefault[i] == behParams) { return NULL; }
}
if (gSpawnedStarDefaultCount < 8) {
gSpawnedStarDefault[gSpawnedStarDefaultCount++] = behParams;
}
struct Object *star;
star = spawn_star(star, x, y, z);
star->oBehParams2ndByte = 0;
gSpawnedStarDefault = TRUE;
network_send_spawn_star(star, 0, x, y, z, behParams);
return star;
}

View File

@ -1246,7 +1246,10 @@ s32 init_level(void) {
sTransitionTimer = 0;
D_80339EE0 = 0;
gSpawnedStarDefault = 0;
for (int i = 0; i < 8; i++) {
gSpawnedStarDefault[i] = 0;
}
gSpawnedStarDefaultCount = 0;
gSpawnedStarRedCoin = 0;
gSpawnedStarHidden = 0;