From 5b7e1c28d812a831bd347dc42c8ba8aa0918ec82 Mon Sep 17 00:00:00 2001 From: MysterD Date: Tue, 18 Aug 2020 18:45:34 -0700 Subject: [PATCH] Synchronized clam --- src/game/behaviors/clam.inc.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/game/behaviors/clam.inc.c b/src/game/behaviors/clam.inc.c index 36969800..7d05cd7c 100644 --- a/src/game/behaviors/clam.inc.c +++ b/src/game/behaviors/clam.inc.c @@ -13,6 +13,9 @@ struct ObjectHitbox sClamShellHitbox = { }; void clam_act_0(void) { + struct Object* player = nearest_player_to_object(o); + int distanceToPlayer = dist_between_objects(o, player); + if (cur_obj_init_anim_check_frame(0, 25)) { cur_obj_play_sound_2(SOUND_GENERAL_CLAM_SHELL3); spawn_mist_from_global(); @@ -20,9 +23,11 @@ void clam_act_0(void) { o->oClamUnkF4 = 10; o->oTimer = 0; - } else if (o->oTimer > 150 && o->oDistanceToMario < 500.0f) { + if (network_owns_object(o)) { network_send_object(o); } + } else if (o->oTimer > 150 && player == gMarioStates[0].marioObj && distanceToPlayer < 500.0f) { cur_obj_play_sound_2(SOUND_GENERAL_CLAM_SHELL2); o->oAction = 1; + if (network_owns_object(o)) { network_send_object(o); } } else if (o->oClamUnkF4 != 0) { o->oClamUnkF4 -= 1; cur_obj_shake_y(3.0f); @@ -34,8 +39,10 @@ void clam_act_1(void) { s16 val04; s16 val02; - if (o->oTimer > 150) { + struct Object* player = nearest_player_to_object(o); + if (o->oTimer > 150 && player == gMarioStates[0].marioObj) { o->oAction = 0; + if (network_owns_object(o)) { network_send_object(o); } } else if (obj_is_rendering_enabled() && cur_obj_init_anim_check_frame(1, 8)) { for (val06 = -0x2000; val06 < 0x2000; val06 += 0x555) { val04 = (s16)(100.0f * sins(val06)); @@ -49,6 +56,12 @@ void clam_act_1(void) { } void bhv_clam_loop(void) { + if (o->oSyncID == 0) { + network_init_object(o, SYNC_DISTANCE_ONLY_EVENTS); + network_init_object_field(o, &o->oAction); + network_init_object_field(o, &o->oTimer); + network_init_object_field(o, &o->oClamUnkF4); + } o->header.gfx.scale[1] = 1.5f; switch (o->oAction) {