From fa2606fecb1d44eac70d6f90137f296f37c12812 Mon Sep 17 00:00:00 2001 From: MysterD Date: Sat, 10 Oct 2020 16:12:29 -0700 Subject: [PATCH] Misc gMarioState/gMarioObject cleanup --- src/game/behaviors/blue_coin.inc.c | 2 +- src/game/behaviors/breakable_wall.inc.c | 2 +- src/game/behaviors/castle_floor_trap.inc.c | 4 ++-- src/game/behaviors/pole_base.inc.c | 2 +- src/game/behaviors/purple_switch.inc.c | 2 +- src/game/behaviors/water_mist_particle.inc.c | 12 ++++++++++-- src/game/behaviors/water_splashes_and_waves.inc.c | 13 +++++++++---- src/game/obj_behaviors_2.c | 4 +++- 8 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/game/behaviors/blue_coin.inc.c b/src/game/behaviors/blue_coin.inc.c index d35d63ad..aa9fc401 100644 --- a/src/game/behaviors/blue_coin.inc.c +++ b/src/game/behaviors/blue_coin.inc.c @@ -77,7 +77,7 @@ void bhv_blue_coin_switch_loop(void) { // If Mario is on the switch and has ground-pounded, // recede and get ready to start ticking. if (gMarioObject->platform == o) { - if (gMarioStates->action == ACT_GROUND_POUND_LAND) { + if (gMarioStates[0].action == ACT_GROUND_POUND_LAND) { // Set to BLUE_COIN_SWITCH_ACT_RECEDING o->oAction++; diff --git a/src/game/behaviors/breakable_wall.inc.c b/src/game/behaviors/breakable_wall.inc.c index 76fddd11..4954bc9c 100644 --- a/src/game/behaviors/breakable_wall.inc.c +++ b/src/game/behaviors/breakable_wall.inc.c @@ -6,7 +6,7 @@ void bhv_wf_breakable_wall_loop(void) { network_init_object_field(o, &o->oBreakableWallForce); } - if (o->oBreakableWallForce || gMarioStates->action == ACT_SHOT_FROM_CANNON) { + if (o->oBreakableWallForce || gMarioStates[0].action == ACT_SHOT_FROM_CANNON) { cur_obj_become_tangible(); if (o->oBreakableWallForce || obj_check_if_collided_with_object(o, gMarioObject)) { if (!o->oBreakableWallForce) { diff --git a/src/game/behaviors/castle_floor_trap.inc.c b/src/game/behaviors/castle_floor_trap.inc.c index 7655b3cd..73efdb79 100644 --- a/src/game/behaviors/castle_floor_trap.inc.c +++ b/src/game/behaviors/castle_floor_trap.inc.c @@ -19,8 +19,8 @@ void bhv_castle_floor_trap_init(void) { } void bhv_castle_floor_trap_open_detect(void) { - if (gMarioStates->action == ACT_SPECIAL_EXIT_AIRBORNE - || gMarioStates->action == ACT_SPECIAL_DEATH_EXIT) + if (gMarioStates[0].action == ACT_SPECIAL_EXIT_AIRBORNE + || gMarioStates[0].action == ACT_SPECIAL_DEATH_EXIT) o->oAction = 4; // rotates trapdoor so it looks always open else { o->oAngleVelRoll = 0x400; diff --git a/src/game/behaviors/pole_base.inc.c b/src/game/behaviors/pole_base.inc.c index 3ae63fef..543fa28d 100644 --- a/src/game/behaviors/pole_base.inc.c +++ b/src/game/behaviors/pole_base.inc.c @@ -4,6 +4,6 @@ void bhv_pole_base_loop(void) { if (o->oPosY - 10.0f < gMarioObject->oPosY && gMarioObject->oPosY < o->oPosY + o->hitboxHeight + 30.0f) if (o->oTimer > 10) - if (!(gMarioStates->action & MARIO_PUNCHING)) + if (!(gMarioStates[0].action & MARIO_PUNCHING)) cur_obj_push_mario_away(70.0f); } diff --git a/src/game/behaviors/purple_switch.inc.c b/src/game/behaviors/purple_switch.inc.c index 8738d94a..d5dfd49b 100644 --- a/src/game/behaviors/purple_switch.inc.c +++ b/src/game/behaviors/purple_switch.inc.c @@ -31,7 +31,7 @@ void bhv_purple_switch_loop(void) { case PURPLE_SWITCH_IDLE: cur_obj_set_model(MODEL_PURPLE_SWITCH); cur_obj_scale(1.5f); - if (gMarioObject->platform == o && !(gMarioStates->action & MARIO_UNKNOWN_13)) { + if (gMarioObject->platform == o && !(gMarioStates[0].action & MARIO_UNKNOWN_13)) { if (lateral_dist_between_objects(o, gMarioObject) < 127.5) { o->oAction = PURPLE_SWITCH_PRESSED; network_send_object(o); diff --git a/src/game/behaviors/water_mist_particle.inc.c b/src/game/behaviors/water_mist_particle.inc.c index cb9243ae..9780ade7 100644 --- a/src/game/behaviors/water_mist_particle.inc.c +++ b/src/game/behaviors/water_mist_particle.inc.c @@ -3,13 +3,21 @@ void bhv_water_mist_spawn_loop(void) { clear_particle_flags(0x20000); - spawn_object(o, MODEL_MIST, bhvWaterMist); + if (o->parentObj == NULL || o->parentObj->behavior != bhvMario) { + obj_mark_for_deletion(o); + return; + } + spawn_object(o->parentObj, MODEL_MIST, bhvWaterMist); } void bhv_water_mist_loop(void) { + if (o->parentObj == NULL || o->parentObj->behavior != bhvMario) { + obj_mark_for_deletion(o); + return; + } f32 sp1C; if (o->oTimer == 0) { - o->oMoveAngleYaw = gMarioObject->oMoveAngleYaw; + o->oMoveAngleYaw = o->parentObj->oMoveAngleYaw; obj_translate_xz_random(o, 10.0f); } cur_obj_move_using_fvel_and_gravity(); diff --git a/src/game/behaviors/water_splashes_and_waves.inc.c b/src/game/behaviors/water_splashes_and_waves.inc.c index c70a95ae..0a952075 100644 --- a/src/game/behaviors/water_splashes_and_waves.inc.c +++ b/src/game/behaviors/water_splashes_and_waves.inc.c @@ -84,10 +84,15 @@ void bhv_water_droplet_loop(void) { } void bhv_idle_water_wave_loop(void) { - obj_copy_pos(o, gMarioObject); - o->oPosY = gMarioStates->waterLevel + 5; - if (!(gMarioObject->oMarioParticleFlags & ACTIVE_PARTICLE_IDLE_WATER_WAVE)) { - gMarioObject->oActiveParticleFlags &= (u16)~ACTIVE_PARTICLE_IDLE_WATER_WAVE; + if (o->parentObj == NULL || o->parentObj->behavior != bhvMario) { + obj_mark_for_deletion(o); + return; + } + obj_copy_pos(o, o->parentObj); + u8 index = o->parentObj->oBehParams - 1; + o->oPosY = gMarioStates[index].waterLevel + 5; + if (!(o->parentObj->oMarioParticleFlags & ACTIVE_PARTICLE_IDLE_WATER_WAVE)) { + o->parentObj->oActiveParticleFlags &= (u16)~ACTIVE_PARTICLE_IDLE_WATER_WAVE; o->activeFlags = ACTIVE_FLAG_DEACTIVATED; } } diff --git a/src/game/obj_behaviors_2.c b/src/game/obj_behaviors_2.c index 0a68f7ee..00874eab 100644 --- a/src/game/obj_behaviors_2.c +++ b/src/game/obj_behaviors_2.c @@ -665,7 +665,9 @@ static void obj_set_knockback_action(s32 attackType) { } o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; - o->oMoveAngleYaw = obj_angle_to_object(gMarioObject, o); + + struct Object* player = nearest_player_to_object(o); + o->oMoveAngleYaw = obj_angle_to_object(player, o); } static void obj_set_squished_action(void) {