Bomb-Omb Buddy sanity improvement (#51)

This commit is contained in:
Prince Frizzy 2022-03-30 22:25:21 -04:00 committed by GitHub
parent a1af1c2ffb
commit e52173f109
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 19 deletions

View file

@ -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);
}

View file

@ -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.

View file

@ -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