From e1933e5f78086e55ad12292f7fb003cd05d32989 Mon Sep 17 00:00:00 2001 From: MysterD Date: Wed, 23 Sep 2020 22:00:20 -0700 Subject: [PATCH] Improvements to Bowser 2 (still not fully supported) --- data/behavior_data.c | 1 + src/game/behavior_actions.h | 1 + src/game/behaviors/bowser.inc.c | 26 ++++++++++++++++++++++++-- src/pc/network/network.h | 1 + src/pc/network/packets/packet_object.c | 13 ++++++++++++- 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/data/behavior_data.c b/data/behavior_data.c index 529c0ef4..c1050137 100644 --- a/data/behavior_data.c +++ b/data/behavior_data.c @@ -2186,6 +2186,7 @@ const BehaviorScript bhvTiltingBowserLavaPlatform[] = { SET_FLOAT(oCollisionDistance, 20000), SET_INT(oFaceAngleYaw, 0), SET_HOME(), + CALL_NATIVE(bhv_tilting_bowser_lava_platform_init), BEGIN_LOOP(), CALL_NATIVE(cur_obj_rotate_face_angle_using_vel), CALL_NATIVE(load_object_collision_model), diff --git a/src/game/behavior_actions.h b/src/game/behavior_actions.h index cca0c65e..3ca3ea84 100644 --- a/src/game/behavior_actions.h +++ b/src/game/behavior_actions.h @@ -156,6 +156,7 @@ void bhv_bowser_loop(void); void bhv_bowser_body_anchor_init(void); void bhv_bowser_body_anchor_loop(void); void bhv_bowser_flame_spawn_loop(void); +void bhv_tilting_bowser_lava_platform_init(void); void bhv_falling_bowser_platform_loop(void); void bhv_blue_bowser_flame_init(void); void bhv_blue_bowser_flame_loop(void); diff --git a/src/game/behaviors/bowser.inc.c b/src/game/behaviors/bowser.inc.c index 4a21f683..f17e7735 100644 --- a/src/game/behaviors/bowser.inc.c +++ b/src/game/behaviors/bowser.inc.c @@ -1018,7 +1018,17 @@ void bowser_act_dead(void) { } } -void bowser_tilt_platform(struct Object *platform, s16 a1) { +void bhv_tilting_bowser_lava_platform_init(void) { + struct SyncObject* so = network_init_object(o, SYNC_DISTANCE_ONLY_EVENTS); + network_init_object_field(o, &o->oAngleVelPitch); + network_init_object_field(o, &o->oAngleVelRoll); + network_init_object_field(o, &o->oFaceAnglePitch); + network_init_object_field(o, &o->oFaceAngleRoll); + network_init_object_field(o, &o->oMoveAnglePitch); + network_init_object_field(o, &o->oMoveAngleRoll); +} + +void bowser_tilt_platform(struct Object* platform, s16 a1) { s16 angle; angle = o->oBowserAngleToCentre + 0x8000; platform->oAngleVelPitch = coss(angle) * a1; @@ -1026,7 +1036,7 @@ void bowser_tilt_platform(struct Object *platform, s16 a1) { } void bowser_act_ride_tilting_platform(void) { - struct Object *platform = cur_obj_nearest_object_with_behavior(bhvTiltingBowserLavaPlatform); + struct Object* platform = cur_obj_nearest_object_with_behavior(bhvTiltingBowserLavaPlatform); UNUSED s16 sp2A = o->oBowserAngleToCentre + 0x8000; s16 sp28; UNUSED s32 unused; @@ -1058,11 +1068,15 @@ void bowser_act_ride_tilting_platform(void) { platform->oAngleVelRoll = 0; platform->oFaceAnglePitch = 0; platform->oFaceAngleRoll = 0; + if (network_owns_object(o)) { + network_send_object(platform); + } } } cur_obj_extend_animation_if_at_end(); } + s32 bowser_check_fallen_off_stage(void) // bowser off stage? { if (o->oAction != 2 && o->oAction != 19) { @@ -1278,6 +1292,13 @@ void bhv_bowser_loop(void) { } } +void bhv_bowser_override_ownership(u8* shouldOverride, u8* shouldOwn) { + if (o->oAction == 19) { // tilting platform + *shouldOverride = TRUE; + *shouldOwn = (gNetworkType == NT_SERVER); + } +} + void bhv_bowser_init(void) { s32 level; // 0 is dw, 1 is fs, 2 is sky o->oBowserUnk110 = 1; @@ -1298,6 +1319,7 @@ void bhv_bowser_init(void) { o->oBowserEyesShut = 0; struct SyncObject* so = network_init_object(o, 8000.0f); + so->override_ownership = bhv_bowser_override_ownership; so->fullObjectSync = TRUE; network_init_object_field(o, &o->header.gfx.node.flags); network_init_object_field(o, &networkBowserAnimationIndex); diff --git a/src/pc/network/network.h b/src/pc/network/network.h index 29c76854..a44b86db 100644 --- a/src/pc/network/network.h +++ b/src/pc/network/network.h @@ -54,6 +54,7 @@ struct SyncObject { u8 (*ignore_if_true)(void); void (*on_received_pre)(u8 fromLocalIndex); void (*on_received_post)(u8 fromLocalIndex); + void (*override_ownership)(u8* shouldOverride, u8* shouldOwn); void* extraFields[MAX_SYNC_OBJECT_FIELDS]; }; diff --git a/src/pc/network/packets/packet_object.c b/src/pc/network/packets/packet_object.c index 5a4ab327..7047e796 100644 --- a/src/pc/network/packets/packet_object.c +++ b/src/pc/network/packets/packet_object.c @@ -24,11 +24,22 @@ static float player_distance(struct MarioState* marioState, struct Object* o) { } static bool should_own_object(struct SyncObject* so) { + // check for override + u8 shouldOverride = FALSE; + u8 shouldOwn = FALSE; + if (so->override_ownership != NULL) { + extern struct Object* gCurrentObject; + struct Object* tmp = gCurrentObject; + gCurrentObject = so->o; + so->override_ownership(&shouldOverride, &shouldOwn); + gCurrentObject = tmp; + if (shouldOverride) { return shouldOwn; } + } + if (gMarioStates[0].heldByObj == so->o) { return true; } for (int i = 0; i < MAX_PLAYERS; i++) { if (gMarioStates[i].heldByObj == so->o) { return false; } } - if (so->o->oHeldState == HELD_HELD && so->o->heldByPlayerIndex == 0) { return true; } if (player_distance(&gMarioStates[0], so->o) > player_distance(&gMarioStates[1], so->o)) { return false; } if (so->o->oHeldState == HELD_HELD && so->o->heldByPlayerIndex != 0) { return false; }