Synchronized room checking better + fixed bookswitches

Determining if the player is in the room was bugged, and bookswitches
caused Luigi to crash. Now things should be a bit more stable in BBH.
Fixes #30
This commit is contained in:
MysterD 2020-09-07 19:51:39 -07:00
parent ef48ec249a
commit 95e9c1dc4c
3 changed files with 39 additions and 24 deletions

View file

@ -185,7 +185,7 @@ void bookshelf_manager_act_1(void) {
}
void bookshelf_manager_act_2(void) {
if (!(o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM)) {
//if (!(o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM)) {
if (o->oBookSwitchManagerUnkF4 < 0) {
if (o->oTimer > 30) {
if (gNetworkType == NT_SERVER) {
@ -216,13 +216,16 @@ void bookshelf_manager_act_2(void) {
o->oTimer = 0;
}
}
} else if (gNetworkType == NT_SERVER) {
/*} else if (gNetworkType == NT_SERVER) {
o->oAction = 4;
network_send_object(o);
}
}*/
}
void bookshelf_manager_act_3(void) {
if (o->parentObj == NULL || o->parentObj->behavior != bhvHauntedBookshelf) {
o->parentObj = cur_obj_nearest_object_with_behavior(bhvHauntedBookshelf);
}
if (o->oTimer > 85) {
if (gNetworkType == NT_SERVER) {
o->oAction = 4;
@ -245,7 +248,8 @@ void bookshelf_manager_act_4(void) {
void bhv_haunted_bookshelf_manager_loop(void) {
if (!network_sync_object_initialized(o)) {
network_init_object(o, SYNC_DISTANCE_ONLY_EVENTS);
struct SyncObject* so = network_init_object(o, SYNC_DISTANCE_ONLY_EVENTS);
so->syncDeathEvent = FALSE;
network_init_object_field(o, &o->oAction);
network_init_object_field(o, &o->activeFlags);
network_init_object_field(o, &o->oBookSwitchManagerUnkF8);

View file

@ -117,7 +117,13 @@ static void platform_on_track_act_init(void) {
* Wait for mario to stand on the platform for 20 frames, then begin moving.
*/
static void platform_on_track_act_wait_for_mario(void) {
if (gMarioObject->platform == o) {
u8 anyMarioOnPlatform = FALSE;
for (int i = 0; i < MAX_PLAYERS; i++) {
if (!is_player_active(&gMarioStates[i])) { continue; }
if (gMarioStates[i].marioObj->platform == o) { anyMarioOnPlatform = TRUE; }
}
if (anyMarioOnPlatform) {
if (o->oTimer > 20) {
o->oAction = PLATFORM_ON_TRACK_ACT_MOVE_ALONG_TRACK;
if (network_owns_object(o)) { network_send_object(o); }

View file

@ -2523,29 +2523,34 @@ void bhv_init_room(void) {
}
void cur_obj_enable_rendering_if_mario_in_room(void) {
register s32 marioInRoom;
if (o->oRoom == -1) { return; }
if (gMarioCurrentRoom == 0) { return; }
if (o->oRoom != -1 && gMarioCurrentRoom != 0) {
if (gMarioCurrentRoom == o->oRoom) {
marioInRoom = TRUE;
} else if (gDoorAdjacentRooms[gMarioCurrentRoom][0] == o->oRoom) {
marioInRoom = TRUE;
} else if (gDoorAdjacentRooms[gMarioCurrentRoom][1] == o->oRoom) {
marioInRoom = TRUE;
} else {
marioInRoom = FALSE;
}
u8 marioInRoom = FALSE;
if (marioInRoom) {
cur_obj_enable_rendering();
o->activeFlags &= ~ACTIVE_FLAG_IN_DIFFERENT_ROOM;
gNumRoomedObjectsInMarioRoom++;
} else {
cur_obj_disable_rendering();
o->activeFlags |= ACTIVE_FLAG_IN_DIFFERENT_ROOM;
gNumRoomedObjectsNotInMarioRoom++;
for (int i = 0; i < MAX_PLAYERS; i++) {
if (gMarioStates[i].currentRoom != 0) {
s16 currentRoom = gMarioStates[i].currentRoom;
if (currentRoom == o->oRoom) {
marioInRoom = TRUE;
} else if (gDoorAdjacentRooms[currentRoom][0] == o->oRoom) {
marioInRoom = TRUE;
} else if (gDoorAdjacentRooms[currentRoom][1] == o->oRoom) {
marioInRoom = TRUE;
}
}
}
if (marioInRoom) {
cur_obj_enable_rendering();
o->activeFlags &= ~ACTIVE_FLAG_IN_DIFFERENT_ROOM;
gNumRoomedObjectsInMarioRoom++;
}
else {
cur_obj_disable_rendering();
o->activeFlags |= ACTIVE_FLAG_IN_DIFFERENT_ROOM;
gNumRoomedObjectsNotInMarioRoom++;
}
}
s32 cur_obj_set_hitbox_and_die_if_attacked(struct ObjectHitbox *hitbox, s32 deathSound, s32 noLootCoins) {