diff --git a/Makefile b/Makefile index e987a9e1..af9c14b4 100644 --- a/Makefile +++ b/Makefile @@ -1469,4 +1469,4 @@ MAKEFLAGS += --no-builtin-rules -include $(DEP_FILES) -print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true +print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true \ No newline at end of file diff --git a/src/game/behaviors/bobomb.inc.c b/src/game/behaviors/bobomb.inc.c index 4b17471f..115fb7fc 100644 --- a/src/game/behaviors/bobomb.inc.c +++ b/src/game/behaviors/bobomb.inc.c @@ -301,25 +301,26 @@ void bhv_bobomb_buddy_init(void) { } void bobomb_buddy_act_idle(void) { - UNUSED u8 filler[4]; - s16 sp1a = o->header.gfx.animInfo.animFrame; - UNUSED s16 collisionFlags = 0; + s16 animFrame = o->header.gfx.animInfo.animFrame; o->oBobombBuddyPosXCopy = o->oPosX; o->oBobombBuddyPosYCopy = o->oPosY; o->oBobombBuddyPosZCopy = o->oPosZ; - collisionFlags = object_step(); + object_step(); - if ((sp1a == 5) || (sp1a == 16)) + if ((animFrame == 5) || (animFrame == 16)) { cur_obj_play_sound_2(SOUND_OBJ_BOBOMB_WALK); + } struct Object* player = nearest_player_to_object(o); - if (dist_between_objects(o, player) < 1000.0f) + if (dist_between_objects(o, player) < 1000.0f) { o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, obj_angle_to_object(o, player), 0x140); + } - if (o->oInteractStatus == INT_STATUS_INTERACTED) + if (o->oInteractStatus == INT_STATUS_INTERACTED) { o->oAction = BOBOMB_BUDDY_ACT_TURN_TO_TALK; + } } /** @@ -345,24 +346,27 @@ void bobomb_buddy_cannon_dialog(s16 dialogFirstText, s16 dialogSecondText) { forceCannonOpen = FALSE; cannonClosed = cur_obj_nearest_object_with_behavior(bhvCannonClosed); - if (cannonClosed != 0) + if (cannonClosed != 0) { o->oBobombBuddyCannonStatus = BOBOMB_BUDDY_CANNON_OPENING; - else + } else { o->oBobombBuddyCannonStatus = BOBOMB_BUDDY_CANNON_STOP_TALKING; + } } break; case BOBOMB_BUDDY_CANNON_OPENING: cannonClosed = cur_obj_nearest_object_with_behavior(bhvCannonClosed); cutscene = cutscene_object(CUTSCENE_PREPARE_CANNON, cannonClosed); - if (cutscene == -1) + if (cutscene == -1) { o->oBobombBuddyCannonStatus = BOBOMB_BUDDY_CANNON_OPENED; + } break; case BOBOMB_BUDDY_CANNON_OPENED: buddyText = cutscene_object_with_dialog(CUTSCENE_DIALOG, o, dialogSecondText); - if (buddyText != 0) + if (buddyText != 0) { o->oBobombBuddyCannonStatus = BOBOMB_BUDDY_CANNON_STOP_TALKING; + } break; case BOBOMB_BUDDY_CANNON_STOP_TALKING: @@ -400,25 +404,28 @@ void bobomb_buddy_act_talk(void) { break; case BOBOMB_BUDDY_ROLE_CANNON: - if (gCurrCourseNum == COURSE_BOB) + if (gCurrCourseNum == COURSE_BOB) { bobomb_buddy_cannon_dialog(DIALOG_004, DIALOG_105); - else + } else { bobomb_buddy_cannon_dialog(DIALOG_047, DIALOG_106); + } break; } } } void bobomb_buddy_act_turn_to_talk(void) { - s16 sp1e = o->header.gfx.animInfo.animFrame; - if ((sp1e == 5) || (sp1e == 16)) + s16 animFrame = o->header.gfx.animInfo.animFrame; + if ((animFrame == 5) || (animFrame == 16)) { cur_obj_play_sound_2(SOUND_OBJ_BOBOMB_WALK); + } - struct Object* player = nearest_player_to_object(o); + struct Object *player = nearest_interacting_player_to_object(o); s32 angleToPlayer = obj_angle_to_object(o, player); o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, angleToPlayer, 0x1000); - if ((s16) o->oMoveAngleYaw == (s16) angleToPlayer) + if ((s16) o->oMoveAngleYaw == (s16) angleToPlayer) { o->oAction = BOBOMB_BUDDY_ACT_TALK; + } cur_obj_play_sound_2(SOUND_ACTION_READ_SIGN); } diff --git a/src/game/behaviors/treasure_chest.inc.c b/src/game/behaviors/treasure_chest.inc.c index 227a2838..55d689a4 100644 --- a/src/game/behaviors/treasure_chest.inc.c +++ b/src/game/behaviors/treasure_chest.inc.c @@ -327,4 +327,4 @@ void bhv_treasure_chest_loop(void) { case 2: break; } -} +} \ No newline at end of file diff --git a/src/game/obj_behaviors.c b/src/game/obj_behaviors.c index 3a362461..8eb5bb44 100644 --- a/src/game/obj_behaviors.c +++ b/src/game/obj_behaviors.c @@ -597,6 +597,43 @@ struct Object* nearest_player_to_object(struct Object *obj) { return nearest->marioObj; } +/** + * Returns closest MarioState that's interacting with the object. + */ +struct MarioState *nearest_interacting_mario_state_to_object(struct Object *obj) { + struct MarioState *nearest = NULL; + f32 nearestDist = 0; + u8 checkActive = TRUE; + do { + for (s32 i = 0; i < MAX_PLAYERS; i++) { + if (gMarioStates[i].marioObj == obj) { continue; } + if (gMarioStates[i].interactObj != obj) { continue; } + if (checkActive && !is_player_active(&gMarioStates[i])) { continue; } + float dist = dist_between_objects(obj, gMarioStates[i].marioObj); + if (nearest == NULL || dist < nearestDist) { + nearest = &gMarioStates[i]; + nearestDist = dist; + } + } + if (!checkActive) { break; } + checkActive = FALSE; + } while (nearest == NULL); + + if (nearest == NULL) { + nearest = &gMarioStates[0]; + } + + return nearest; +} + +/** + * Returns closest marioObj that's interacting with the object. + */ +struct Object *nearest_interacting_player_to_object(struct Object *obj) { + struct MarioState *nearest = nearest_interacting_mario_state_to_object(obj); + return nearest->marioObj; +} + /** * Returns whether or not the MarioState is the closet MarioState * to the object. diff --git a/src/game/obj_behaviors.h b/src/game/obj_behaviors.h index 5dbb8a82..39b78a29 100644 --- a/src/game/obj_behaviors.h +++ b/src/game/obj_behaviors.h @@ -167,6 +167,8 @@ u8 is_other_player_active(void); 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); +struct MarioState *nearest_interacting_mario_state_to_object(struct Object *obj); +struct Object *nearest_interacting_player_to_object(struct Object *obj); u8 is_nearest_mario_state_to_object(struct MarioState* m, struct Object* obj); u8 is_nearest_player_to_object(struct Object* m, struct Object* obj); #endif // OBJ_BEHAVIORS_H