From bc11f061365d2f67ed93d94014bfab369a440cf5 Mon Sep 17 00:00:00 2001 From: MysterD Date: Tue, 29 Mar 2022 18:17:37 -0700 Subject: [PATCH] Remove player's bubble when they leave the area --- src/game/behaviors/water_objs.inc.c | 2 +- src/game/mario_actions_automatic.c | 3 +-- src/game/obj_behaviors.c | 17 +++++++++++++++++ src/game/obj_behaviors.h | 1 + 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/game/behaviors/water_objs.inc.c b/src/game/behaviors/water_objs.inc.c index c8b48916f..b16d56e9d 100644 --- a/src/game/behaviors/water_objs.inc.c +++ b/src/game/behaviors/water_objs.inc.c @@ -91,7 +91,7 @@ void bhv_bubble_player_loop(void) { o->header.gfx.scale[2] = scale; // check if the bubble popped - if (marioState->action != ACT_BUBBLED) { + if (marioState->action != ACT_BUBBLED || !is_player_in_local_area(marioState)) { spawn_mist_particles(); create_sound_spawner(SOUND_OBJ_DIVING_IN_WATER); marioState->bubbleObj = NULL; diff --git a/src/game/mario_actions_automatic.c b/src/game/mario_actions_automatic.c index 6a2ade4ec..f9ca1f92d 100644 --- a/src/game/mario_actions_automatic.c +++ b/src/game/mario_actions_automatic.c @@ -952,8 +952,7 @@ s32 act_bubbled(struct MarioState* m) { } // create bubble - if (m->bubbleObj == NULL) { - //m->bubbleObj = spawn_object(m->marioObj, MODEL_BUBBLE, bhvBubblePlayer); + if (m->bubbleObj == NULL && is_player_in_local_area(m)) { m->bubbleObj = spawn_object(m->marioObj, MODEL_BUBBLE_PLAYER, bhvBubblePlayer); if (m->bubbleObj != NULL) { m->bubbleObj->heldByPlayerIndex = m->playerIndex; diff --git a/src/game/obj_behaviors.c b/src/game/obj_behaviors.c index f03fbdf50..2b9bfd909 100644 --- a/src/game/obj_behaviors.c +++ b/src/game/obj_behaviors.c @@ -536,6 +536,23 @@ u8 is_player_active(struct MarioState* m) { return TRUE; } +u8 is_player_in_local_area(struct MarioState* m) { + if (gNetworkType == NT_NONE && m == &gMarioStates[0]) { return TRUE; } + struct NetworkPlayer* np = &gNetworkPlayers[m->playerIndex]; + if (np == gNetworkPlayerServer && gServerSettings.headlessServer) { return FALSE; } + if (np->type != NPT_LOCAL) { + if (!np->connected) { return FALSE; } + if (gNetworkPlayerLocal == NULL) { return FALSE; } + bool levelAreaMismatch = + (np->currCourseNum != gNetworkPlayerLocal->currCourseNum + || np->currActNum != gNetworkPlayerLocal->currActNum + || np->currLevelNum != gNetworkPlayerLocal->currLevelNum + || np->currAreaIndex != gNetworkPlayerLocal->currAreaIndex); + if (levelAreaMismatch) { return FALSE; } + } + return TRUE; +} + /** * Returns closest MarioState */ diff --git a/src/game/obj_behaviors.h b/src/game/obj_behaviors.h index 5dafd81d9..6f7092d71 100644 --- a/src/game/obj_behaviors.h +++ b/src/game/obj_behaviors.h @@ -163,6 +163,7 @@ void bhv_rr_cruiser_wing_init(void); void bhv_rr_cruiser_wing_loop(void); struct Object* spawn_default_star(f32 sp20, f32 sp24, f32 sp28); u8 is_player_active(struct MarioState* m); +u8 is_player_in_local_area(struct MarioState* m); struct MarioState* nearest_mario_state_to_object(struct Object* obj); struct Object* nearest_player_to_object(struct Object* obj); u8 is_nearest_mario_state_to_object(struct MarioState* m, struct Object* obj);