From bd7d03975e0aa9215d24cddb7b352e1f59c95078 Mon Sep 17 00:00:00 2001 From: MysterD Date: Tue, 6 Oct 2020 20:28:17 -0700 Subject: [PATCH] Synchronized metal boxes --- src/game/behaviors/metal_box.inc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/game/behaviors/metal_box.inc.c b/src/game/behaviors/metal_box.inc.c index 851dfede..f41dcd19 100644 --- a/src/game/behaviors/metal_box.inc.c +++ b/src/game/behaviors/metal_box.inc.c @@ -25,14 +25,22 @@ s32 check_if_moving_over_floor(f32 a0, f32 a1) { } void bhv_pushable_loop(void) { + if (!network_sync_object_initialized(o)) { + network_init_object(o, 1000.0f); + network_init_object_field(o, &o->oMoveAngleYaw); + } + + struct MarioState* marioState = nearest_mario_state_to_object(o); + struct Object* player = marioState->marioObj; + UNUSED s16 unused; s16 sp1C; obj_set_hitbox(o, &sMetalBoxHitbox); o->oForwardVel = 0.0f; - if (obj_check_if_collided_with_object(o, gMarioObject) && gMarioStates->flags & 0x80000000) { - sp1C = obj_angle_to_object(o, gMarioObject); - if (abs_angle_diff(sp1C, gMarioObject->oMoveAngleYaw) > 0x4000) { - o->oMoveAngleYaw = (s16)((gMarioObject->oMoveAngleYaw + 0x2000) & 0xc000); + if (obj_check_if_collided_with_object(o, player) && marioState->flags & 0x80000000) { + sp1C = obj_angle_to_object(o, player); + if (abs_angle_diff(sp1C, player->oMoveAngleYaw) > 0x4000) { + o->oMoveAngleYaw = (s16)((player->oMoveAngleYaw + 0x2000) & 0xc000); if (check_if_moving_over_floor(8.0f, 150.0f)) { o->oForwardVel = 4.0f; cur_obj_play_sound_1(SOUND_ENV_METAL_BOX_PUSH);